在AutoCAD中重建多个样条线

时间:2017-10-02 17:36:51

标签: autocad spline rebuild autocad-plugin autolisp

我正在寻找一些能让我在AutoCAD中自动“重建”一个或多个样条线的功能。我的图纸有数百个样条,每个样条有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)]

(initget 6)

;;asks for number of fit points. if nothing is entered, it gives it the default value of 20

(setq n_controlvertices(getint“\ n nn of control vertices< 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>:”))

(如果         (=度无)         (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


 )

(PRINC) )

1 个答案:

答案 0 :(得分: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)
)