Originally Posted by
tiago.caldeira789919
Hi all,
I was wondering if someone could help out getting Vertices inserted into multiple polylines (simultaneously) at a specified interval. It must work with arcs as well.
I've searched the web and I've found the following LISP, which works fine but only selects 1 object at a time.
Code:
(defun c:demo ( / add_vtx pl int in pt flag )
(vl-load-com)
(defun add_vtx ( obj add_pt ent_name / bulg )
(vla-addVertex
obj
(1+ (fix add_pt))
(vlax-make-variant
(vlax-safearray-fill
(vlax-make-safearray vlax-vbdouble (cons 0 1))
(list
(car (trans (vlax-curve-getpointatparam obj add_pt) 0 ent_name))
(cadr (trans (vlax-curve-getpointatparam obj add_pt) 0 ent_name))
)
)
)
)
(setq bulg (vla-GetBulge obj (fix add_pt)))
(vla-SetBulge obj
(fix add_pt)
(/
(sin (/ (* 4 (atan bulg) (- add_pt (fix add_pt))) 4))
(cos (/ (* 4 (atan bulg) (- add_pt (fix add_pt))) 4))
)
)
(vla-SetBulge obj
(1+ (fix add_pt))
(/
(sin (/ (* 4 (atan bulg) (- (1+ (fix add_pt)) add_pt)) 4))
(cos (/ (* 4 (atan bulg) (- (1+ (fix add_pt)) add_pt)) 4))
)
)
(vla-update obj)
)
(setq pl (car (entsel "\nSelect pline entity")))
(if (not (wcmatch (cdr (assoc 0 (entget pl))) "*POLYLINE"))
(progn
(alert "\nPicked entity isn't polyline - quitting")
(exit)
)
(if (and (or (eq (cdr (assoc 70 (entget pl))) 0) (eq (cdr (assoc 70 (entget pl))) 1)) (eq (cdr (assoc 0 (entget pl))) "POLYLINE"))
(progn
(setq flag T)
(command "_.convertpoly" "l" pl "")
)
(if (not (eq (cdr (assoc 0 (entget pl))) "LWPOLYLINE"))
(progn
(alert "\nYou picked 3d polyline - quitting")
(exit)
)
)
)
)
(setq int (getdist "\nEnter Interval: "))
(setq in int)
(while (setq pt (vlax-curve-getPointAtDist pl int))
(add_vtx (vlax-ename->vla-object pl) (vlax-curve-getparamatpoint pl (vlax-curve-getclosestpointto pl pt)) pl)
(setq int (+ int in))
)
(if flag
(command "_.convertpoly" "h" pl "")
)
(princ)
)
If is enough for you 2D polyline, then try this:
Code:
(DEFUN C:ARRAY-VERTICES (/ *error* add_vtx in interval pl pt LSE CNT)
(defun *error* (s)
(or (wcmatch (strcase s) "*BREAK,*CANCEL*,*EXIT*") (prompt (strcat "\nError: " s)))
(setq LSE nil)
(princ)
) ;;*error*
(defun add_vtx (add_pt ent_name / obj pct)
(setq obj (vlax-ename->vla-object ent_name)
pct (trans (vlax-curve-getpointatparam obj add_pt) 0 ent_name)
)
(vla-addvertex
obj
(1+ (fix add_pt))
(vlax-make-variant
(vlax-safearray-fill
(vlax-make-safearray vlax-vbdouble (quote (0 . 1)))
(list (car pct) (cadr pct))
)
)
)
) ;;add_vtx
;;Main
(initget 15)
(setq LSE (ssget (list (quote (0 . "LWPOLYLINE"))))
interval (getdist "\nSpecify interval: ")
in interval
CNT 0
)
(while (< CNT (sslength LSE))
(setq pl (ssname LSE CNT))
(while (setq pt (vlax-curve-getpointatdist pl interval))
(command "_.POINT" pt) ;;Test!
(add_vtx (vlax-curve-getparamatpoint pl (vlax-curve-getclosestpointto pl pt)) pl)
(setq interval (+ interval in))
)
(setq interval in
CNT (1+ CNT)
)
)
(setq LSE nil)
(princ)
) ;;C:ARRAY-VERTICES
(vl-load-com)