Getting a list of polyline vertices using LISP
Here is one way to generate a list of polyline vertices using lisp. This function requires one argument, a polyline entity. The polyline can be the old style POLYLINE entity (2D or 3D), or it can be an LWPOLYLINE entity.
(defun getcoords (ent)
(vlax-safearray->list
(vlax-variant-value
(vlax-get-property
(vlax-ename->vla-object ent)
"Coordinates"
)
)
)
)
Example:
(getcoords (car (entsel)))
This function will return a list of coordinates. If the polyline is a LWPOLYLINE entity, the list will be in the form of (x y x y x y x y), and the number of vertices can be determined by dividing the length of the list by 2.
If the polyline is a POLYLINE entity (2D or 3D), then the list will be in the form of (x y z x y z x y z), and the number of vertices can be determined by dividing the length of the list by 3.
A sample of the output is shown below:
(-3.65553 2.56916 -0.83241 5.477 3.9698 3.23796 6.50188 4.54649 10.0235 2.71455 14.8257 6.78553)
All content is copyright © CAD Panacea 2008-2010 unless otherwise noted.
All content of CAD Panacea is solely my own personal thoughts and opinions and do not represent my employer or any others.
All comments posted to this blog are the sole responsibility of the person making the comment.
Google, as a third party vendor, uses cookies to serve ads on this site. Google's use of their cookies enables it to serve ads to users based on their visit to your sites and other sites on the Internet. You may opt out of the use of these cookies by visiting the Google ad and content network privacy policy.



