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.
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
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
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))))
@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
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?
> 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.