代码之家  ›  专栏  ›  技术社区  ›  Jeff Miller

在AutoCAD中重建多条样条曲线

  •  1
  • Jeff Miller  · 技术社区  · 7 年前

    我只想使用变量n\u controlvertices和degree作为参数来调用cvrebuild命令。AutoLISP例程将一次遍历一个对象,并使用相同的参数重建它们。

    我为代码的出现道歉。显然,AutoLISP不能很好地处理StackOverflow

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

    ;; asks for selection
    

    (提示 “\n选择要重建的样条线。”

    ;;decides if any splines are selected, and if not selects all
    

    (if(not(setq ss(ssget’((0.“样条”)))))) )

    ;;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\u控制顶点(getint“\n控制顶点数<20>:”)

    (=n\u控制顶点为零) (setq n_控制顶点20) (setq n\u控制顶点(固定n\u控制顶点))
    )

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

    (如果 (=零度)

    (setq obj     (vlax-ename->vla-object (ssname ss (setq n (1- n))))
    
    
        ;;(command cvrebuild)
        ;;This is the part that I am not sure about
    
    
     )
    

    (普林斯) )

    1 回复  |  直到 7 年前
        1
  •  1
  •   gileCAD    7 年前

    这里有一个方法。 它调用命令行版本的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)
    )
    
    推荐文章