- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, I need help modifying this LISP
I have a DWG file (example attached) with multiple 3D polylines, and some of the vertices have a Z value of 0. I need a LISP script that will automatically copy the Z value from the nearest vertex that isn't 0.
Specifically, if the first vertex has a Z value of 0, it should get the Z value from the next vertex. If there are consecutive vertices with a Z value of 0, each one should get the Z value from the nearest next vertex that isn't 0.
Thank you very much in advance
(defun c:fix3dpolys ()
(vl-load-com)
(setq ss (ssget '((0 . "POLYLINE3D"))))
(if ss
(progn
(setq count 0)
(repeat (sslength ss)
(setq ent (ssname ss count))
(setq obj (vlax-ename->vla-object ent))
(if (= (vla-get-Type obj) acPolyline3D)
(progn
(setq vertices (vlax-get obj 'Coordinates))
(setq new-vertices '())
(setq prev-z nil)
(while vertices
(setq x (car vertices))
(setq y (cadr vertices))
(setq z (caddr vertices))
(if (and (= z 0.0) prev-z)
(setq z prev-z))
(setq new-vertices (append new-vertices (list x y z)))
(setq prev-z z)
(setq vertices (cdddr vertices)))
(vla-put-Coordinates obj (vlax-make-variant new-vertices vlax-vbDouble))
(setq count (1+ count))
)
)
)
(princ (strcat "\n" (itoa count) " 3D polyline(s) updated."))
)
(princ "\nNo 3D polylines selected.")
)
(princ)
)
Solved! Go to Solution.