在 AutoCAD 中重建多条样条曲线
Rebuild Multiple Splines in AutoCAD
我正在寻找一些允许我在 AutoCAD 中自动 "rebuild" 1 个或多个样条曲线的功能。我的图纸有数百条样条曲线,每条样条曲线有 30-50 个控制顶点。这使得绘图的处理速度非常慢,尤其是在直接与这些样条线组交互时。
我有我想做的事情的基本代码,但我现在不确定如何在 AutoLISP 中使用 cvrebuild 命令。在命令行中使用该命令只会调出一个 GUI。到目前为止,请参阅下面的代码。
我只想使用变量 n_controlvertices 和度数作为参数来调用 cvrebuild 命令。 AutoLISP 例程将一次处理一个对象并使用相同的参数重建它们。
对于代码的出现,我深表歉意。显然 AutoLISP 不能很好地与 Whosebug
配合使用
;; Batch rebuild splines
;;defines command name and variables
(defun c:batchrebuild (/ ss n obj n_controlvertices 度数)
;; asks for selection
(提示
“\n选择要重建的样条曲线。”
)
;;decides if any splines are selected, and if not selects all
(if (not (setq ss (ssget '((0 . "SPLINE")))))
(setq ss (ssget "_X" '((0 . "SPLINE"))))
)
;;sets allowable entry to [2 (only nonzero) + 4 (only positive)]
(初始化 6)
;;asks for number of fit points. if nothing is entered, it gives it the default value of 20
(setq n_controlvertices (getint "\n控制顶点数<20>: "))
(如果
(= n_controlvertices 无)
(setq n_controlvertices 20)
(setq n_controlvertices (fix n_controlvertices))
)
;;asks for degree of fit points. if nothing is entered, it gives it the default value of 3
(setq degree (getint "\n拟合度点<3>: "))
(如果
(= 零度)
(setq 度数 3)
(setq degree (fix degree))
)
(重复(setq n (sslength ss))
(setq obj (vlax-ename->vla-object (ssname ss (setq n (1- n))))
;;(command cvrebuild)
;;This is the part that I am not sure about
)
(原则)
)
这是一个方法。
它调用命令行版本的 CVREBUILD (-CVREBUILD)。
它处理用户输入设置的系统变量。
;; Batch rebuild splines
;;defines command name and variables
(defun c:batchrebuild (/ ss n obj n_controlvertices degree rebuild2doption rebuild2ddegree rebuild2dcv cmdecho)
;; asks for selection
(prompt "\nSelect splines to be rebuilt.")
;;decides if any splines are selected, and if not selects all
(or (setq ss (ssget '((0 . "SPLINE"))))
(setq ss (ssget "_X" '((0 . "SPLINE"))))
)
;; checks if the selection is not empty
(if ss
(progn
;;sets allowable entry to [2 (only nonzero) + 4 (only positive)
(initget 6)
;;asks for number of fit points. if nothing is entered, it gives it the default value of 20
(setq n_controlvertices
(cond
((getint "\nNumber of control vertices<20>: "))
(T 20)
)
)
;;asks for degree of fit points. if nothing is entered, it gives it the default value of 3
(setq degree (cond
((getint "\nDegree of fit points<3>: "))
(T 3)
)
)
;; saves the sysvars current values
(setq rebuild2doption (getvar "REBUILD2DOPTION")
rebuild2ddegree (getvar "REBUILD2DDEGREE")
rebuild2dcv (getvar "REBUILD2DCV")
cmdecho (getvar "CMDECHO")
)
;; sets the sysvars values according to user inputs
(setvar "REBUILD2DOPTION" 1)
(setvar "REBUILD2DDEGREE" degree)
(setvar "REBUILD2DCV" n_controlvertices)
(setvar "CMDECHO" 0)
;; rebuilds the selected splines
(repeat (setq n (sslength ss))
(command "_-cvrebuild" (ssname ss (setq n (1- n))))
)
;; restores sysvars initial values
(setvar "REBUILD2DOPTION" rebuild2doption)
(setvar "REBUILD2DDEGREE" rebuild2ddegree)
(setvar "REBUILD2DCV" rebuild2dcv)
(setvar "CMDECHO" cmdecho)
)
)
(princ)
)
我正在寻找一些允许我在 AutoCAD 中自动 "rebuild" 1 个或多个样条曲线的功能。我的图纸有数百条样条曲线,每条样条曲线有 30-50 个控制顶点。这使得绘图的处理速度非常慢,尤其是在直接与这些样条线组交互时。
我有我想做的事情的基本代码,但我现在不确定如何在 AutoLISP 中使用 cvrebuild 命令。在命令行中使用该命令只会调出一个 GUI。到目前为止,请参阅下面的代码。
我只想使用变量 n_controlvertices 和度数作为参数来调用 cvrebuild 命令。 AutoLISP 例程将一次处理一个对象并使用相同的参数重建它们。
对于代码的出现,我深表歉意。显然 AutoLISP 不能很好地与 Whosebug
配合使用;; Batch rebuild splines
;;defines command name and variables
(defun c:batchrebuild (/ ss n obj n_controlvertices 度数)
;; asks for selection
(提示 “\n选择要重建的样条曲线。” )
;;decides if any splines are selected, and if not selects all
(if (not (setq ss (ssget '((0 . "SPLINE"))))) (setq ss (ssget "_X" '((0 . "SPLINE")))) )
;;sets allowable entry to [2 (only nonzero) + 4 (only positive)]
(初始化 6)
;;asks for number of fit points. if nothing is entered, it gives it the default value of 20
(setq n_controlvertices (getint "\n控制顶点数<20>: "))
(如果
(= n_controlvertices 无)
(setq n_controlvertices 20)
(setq n_controlvertices (fix n_controlvertices))
)
;;asks for degree of fit points. if nothing is entered, it gives it the default value of 3
(setq degree (getint "\n拟合度点<3>: "))
(如果
(= 零度)
(setq 度数 3)
(setq degree (fix degree))
)
(重复(setq n (sslength ss))
(setq obj (vlax-ename->vla-object (ssname ss (setq n (1- n))))
;;(command cvrebuild)
;;This is the part that I am not sure about
)
(原则) )
这是一个方法。 它调用命令行版本的 CVREBUILD (-CVREBUILD)。 它处理用户输入设置的系统变量。
;; Batch rebuild splines
;;defines command name and variables
(defun c:batchrebuild (/ ss n obj n_controlvertices degree rebuild2doption rebuild2ddegree rebuild2dcv cmdecho)
;; asks for selection
(prompt "\nSelect splines to be rebuilt.")
;;decides if any splines are selected, and if not selects all
(or (setq ss (ssget '((0 . "SPLINE"))))
(setq ss (ssget "_X" '((0 . "SPLINE"))))
)
;; checks if the selection is not empty
(if ss
(progn
;;sets allowable entry to [2 (only nonzero) + 4 (only positive)
(initget 6)
;;asks for number of fit points. if nothing is entered, it gives it the default value of 20
(setq n_controlvertices
(cond
((getint "\nNumber of control vertices<20>: "))
(T 20)
)
)
;;asks for degree of fit points. if nothing is entered, it gives it the default value of 3
(setq degree (cond
((getint "\nDegree of fit points<3>: "))
(T 3)
)
)
;; saves the sysvars current values
(setq rebuild2doption (getvar "REBUILD2DOPTION")
rebuild2ddegree (getvar "REBUILD2DDEGREE")
rebuild2dcv (getvar "REBUILD2DCV")
cmdecho (getvar "CMDECHO")
)
;; sets the sysvars values according to user inputs
(setvar "REBUILD2DOPTION" 1)
(setvar "REBUILD2DDEGREE" degree)
(setvar "REBUILD2DCV" n_controlvertices)
(setvar "CMDECHO" 0)
;; rebuilds the selected splines
(repeat (setq n (sslength ss))
(command "_-cvrebuild" (ssname ss (setq n (1- n))))
)
;; restores sysvars initial values
(setvar "REBUILD2DOPTION" rebuild2doption)
(setvar "REBUILD2DDEGREE" rebuild2ddegree)
(setvar "REBUILD2DCV" rebuild2dcv)
(setvar "CMDECHO" cmdecho)
)
)
(princ)
)