Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Return the coordinates of a LWPOLYLINE

6 REPLIES 6
Reply
Message 1 of 7
doni49
618 Views, 6 Replies

Return the coordinates of a LWPOLYLINE

I recenly wrote a lisp routine that was supposed to get the 4 coordinates of a rectangle (LWPolyline).  It worked fine in *MY* tests.  But when someone else ran it, the routine operated as though the order of the points had been rearranged.

 

How can I get the points AND the order in which they belong?

 

Here's a sketch to show you what I mean.  As part of my troubleshooting, I had a lisp routine draw a new pline using the points gathered by my first routine.  The result of that on the left.  On the right is the result of that when someone else runs the two routines.

 

Autolisp LWPolylines.png

Here's the code I used to get the points.

 

(defun getplinepointlist(ename)
  (setq ent(entget ename))
  (setq ptlist (list))
  (while (setq pt(cdr(assoc 10 ent)))
    (setq ptlist (append ptlist (list pt)))
    (setq ent(cdr(member (cons 10 pt) ent)))
  )
  (setq pt nil ent nil)
  (setq pt ptlist)
)



Don Ireland
Engineering Design Technician




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

6 REPLIES 6
Message 2 of 7
_Tharwat
in reply to: doni49

Try this instead ,

(defun getplinepointlist ( ename / lst )
(foreach x (entget ename)
(if (eq (car x) 10)
(setq lst (cons (list (car x) (cadr x)) lst))
)
)
(reverse lst)
)
Message 3 of 7
hgasty1001
in reply to: doni49

Hi,

 

For a polyline you can trust in curve parameters, each vertex of the polyline will be at an integer value of a parameter begining from the start parameter and stop in the last parameter, this functión list the vertex in parameter order:

 

 

(defun PlvertexList(pl / sp ep n i vertexlist)
  (setq sp (vlax-curve-getStartParam pl))
  (setq ep (vlax-curve-getEndParam pl))
  (setq n (+ (fix (- ep sp)) 1))
  (setq i sp)
  (repeat n
    (setq vertexlist (cons (vlax-curve-getpointatparam pl i) vertexlist))
    (setq i (+ i 1))
  )
  (reverse vertexlist)
)

 Gaston Nunez

 

Message 4 of 7
_gile
in reply to: hgasty1001

Hi,

 

You can use this routine too (massoc stands for Multiple ASSOC)

 

(defun gc:massoc (key alst)
  (if (setq alst (member (assoc key alst) alst))
    (cons (cdar alst) (gc:massoc key (cdr alst)))
  )
)

 (defun getplinepointlist (ename) (gc:massoc 10 (entget ename))))



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 5 of 7
Kent1Cooper
in reply to: doni49


@doni49 wrote:

I recenly wrote a lisp routine that was supposed to get the 4 coordinates of a rectangle (LWPolyline).  It worked fine in *MY* tests.  But when someone else ran it, the routine operated as though the order of the points had been rearranged.

 

How can I get the points AND the order in which they belong?

....


Other suggestions [as well as my alternative below] don't seem to address the fact that a different User is getting a different result from the same routines.  It looks to me as though that routine should be getting the vertices in the correct order [however many other ways of getting them there may be], and it pretty much would have to be, if your result is coming out as expected.  [EDIT:  ...and I tried it out, and it did return them in the right order.]  I can only guess that there's something different about the other User's setup, such as that they're in some cockamamie User Coordinate System when they run the routines [though even at that, it's kind of hard to imagine what that would be to give the illustrated result].

 

Another way to get the coordinates into a list in sequential order, if 'ename' is the entity name of the Polyline:
 

(mapcar 'cdr ; strip off the association-list 10's from

  (vl-remove-if-not ; keeping only vertex entries

    '(lambda (x)

      (= (car x) 10)

    ); lambda

    (entget ename); in entity data list

  ); ...remove...

); mapcar

Kent Cooper, AIA
Message 6 of 7
bhull1985
in reply to: Kent1Cooper

Yeah that makes a good amt of sense, if the other users UCS was x/y reversed from OP's, wouldn't that create the situations illustrated in his examples?

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Message 7 of 7
_gile
in reply to: bhull1985

> if the other users UCS was x/y reversed from OP's, wouldn't that create the situations illustrated in his examples?

 

I do not think so. None of the upper routines is related to current UCS. Except Gasty's, using vlax-curve* functions, which returns WCS coordinates, all others, using DXF data, return OCS coordinates.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost