I am looking for some function that will allow me to automatically "rebuild" 1 or more splines in AutoCAD. I have drawings that have hundreds of splines with 30-50 control vertices each. This makes drawings very slow to work with, especially when interacting directly with a group of these splines.
I have the basic code for what I want to do, but am not sure at this point how to use the cvrebuild command in AutoLISP. Using that command in the command line simply brings up a GUI. See the code below for what I have so far.
I simply want to invoke the cvrebuild command using the variables n_controlvertices and degree as arguments. The AutoLISP routine would go through one object at a time and rebuild them with the same parameters.
I apologize for the appearance of the code. Apparently AutoLISP does not play well with StackOverflow
;; Batch rebuild splines
;;defines command name and variables
(defun c:batchrebuild (/ ss n obj n_controlvertices degree)
;; asks for selection
(prompt "\nSelect splines to be rebuilt ." )
;;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 "\nNumber of control vertices<20>: "))
(if
(= 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))
)
(repeat (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) )