1

我正在寻找一些可以让我在 AutoCAD 中自动“重建”1 个或多个样条线的功能。我的图纸有数百条样条线,每个样条线有 30-50 个控制顶点。这使得绘图的处理速度非常慢,尤其是在直接与这些样条线组交互时。

我有我想做的基本代码,但目前不确定如何在 AutoLISP 中使用 cvrebuild 命令。在命令行中使用该命令只会打开一个 GUI。到目前为止,请参阅下面的代码。

我只是想使用变量 n_controlvertices 和 degree 作为参数来调用 cvrebuild 命令。AutoLISP 例程将一次通过一个对象并使用相同的参数重建它们。

我为代码的出现道歉。显然 AutoLISP 不能很好地与 StackOverflow 配合使用

;; Batch rebuild splines
;;defines command name and variables

(defun c:batchrebuild (/ss n obj n_controlvertices degree)

;; 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 nil) (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 "\nDegree of fit points<3>: "))

(if (= degree nil) (setq degree 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


 )

(原则))

4

1 回答 1

1

这是一个方法。它调用 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)
)
于 2017-10-03T07:50:15.337 回答