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 2005-2013 unless otherwise noted and may not be reproduced.
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.



Comments
Getcoord defun
on Thu, 04/08/2010 - 01:01 Permalink
Do you have a version of this defun that will work on blocks that inserted in to a drawings? If so can you email.
Thanks
inserting blocks at vertices
on Wed, 08/04/2010 - 07:06 Permalink
Hello,
I was wondering if you be able to help me. I would like a lisp which allows me to select multiple polylines, and then to insert a block I have made at each vertex of those polylines?
What I'm trying to do is to pick the polylines, then click and have it insert the block in place at the vertex of the polyline.
Many thanks,
Brian
Brian, take a look at the
on Fri, 08/06/2010 - 08:20 Permalink
Brian, take a look at the routine here:
http://www.cadforum.cz/cadforum_en/qaID.asp?tip=5384
Incorrect output in some cases
on Mon, 10/18/2010 - 10:38 Permalink
Here is a sample output for a polyline with >270 vertices:
Notice that there is a ")" character in the output. Also, with other lines, I find coordinates to be incorrect.
I have been using getcoords regularly to extract co-ordinates from polylines. I'd be very grateful if you could help me with this. An alternative will be useful too. Thanks for the good work.
If you will wblock out this
on Mon, 10/18/2010 - 15:56 Permalink
If you will wblock out this polyline and email me the drawing (of the polyline *only*), I will take a look as time permits.
Is there any update to this?
on Thu, 01/06/2011 - 06:35 Permalink
I have also noticed a slight error between the drawing database (10. codes) of polylines and the actual co-ordinate although ID always gives the correct result, just wondered if there was any reason for it.
Thanks
Dave.
I never received anything to
on Thu, 01/06/2011 - 08:16 Permalink
I never received anything to check. As far as discrepancies between DXF10 codes and what LIST returns, are you sure you are checking out to the maximum number of decimal places?
See also:
http://blog.jtbworld.com/2008/04/understanding-floating-point-precision....