LW Polyline Vertex

LW Polyline Vertex

Anonymous
Not applicable
1,386 Views
7 Replies
Message 1 of 8

LW Polyline Vertex

Anonymous
Not applicable

Hello

I have hundreds of polylines in my file . Every polyline has 3 vertex (x,y). I would like to modify vertex no 3 to have same y coordinates as vertex no 2. Is any simple way to do it ?

Thanks for help

 

 

0 Likes
Accepted solutions (1)
1,387 Views
7 Replies
Replies (7)
Message 2 of 8

Kent1Cooper
Consultant
Consultant
Accepted solution

Reasonably simple.  Pull the Coordinates VLA property, put its 4th entry in again in place of the last one, and apply that new Coordinates list to the Polyline.  Try this [minimally tested]:

 

(defun C:3rdY (/ ss n obj co)
  (if (setq ss (ssget '((0 . "LWPOLYLINE"))))
    (repeat (setq n (sslength ss)); then
      (setq
        obj (vlax-ename->vla-object (ssname ss (setq n (1- n))))
        co (vlax-get obj 'Coordinates)
      ); setq
      (vlax-put obj 'Coordinates (reverse (cons (nth 3 co) (cdr (reverse co)))))
    ); repeat
  ); if
  (princ)
); defun
(vl-load-com)

 

 

Kent Cooper, AIA
Message 3 of 8

Anonymous
Not applicable

Great It works perfect 🙂

0 Likes
Message 4 of 8

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

Great It works perfect 🙂


Good.  Of course you understand that it's very specific to 3-vertex Polylines, and if any other kind gets selected, the result will probably not be what you intend.  It could be made to limit selection  to only those with 3 vertices, to avoid unexpected effects on Polylines you didn't want to change.

 

If you might sometimes need to do the same on longer ones, it could be adjusted so that [for example] it changes the Y coordinate of the last  vertex to be the same as that of the next-to-last  one, no matter how many there are.

Kent Cooper, AIA
0 Likes
Message 5 of 8

Anonymous
Not applicable

Yes I know this is for this particular case. These polyline  are always the same in my files. 

This is the perfect solution to my problem. Fast and effective 🙂 Thanks

0 Likes
Message 6 of 8

CodeDing
Advisor
Advisor

@Kent1Cooper / @Anonymous ,

 

This can also easily be accomplished without VisualLisp by using the get.../setpropertyvalue functions. People often forget that these functions have the ability to access collections inside the entity. Kent's answer works fine, this is just an alternative approach.

(defun c:TEST ( / ss e cnt)
  (if (setq ss (ssget '((0 . "LWPOLYLINE"))))
    (repeat (setq cnt (sslength ss))
      (setq e (ssname ss (setq cnt (1- cnt))))
      (setpropertyvalue e "Vertices" 2 "Position/Y" (getpropertyvalue e "Vertices" 1 "Position/Y"))
    );repeat
  );if
  (prompt "\nComplete.")
  (princ)
);defun

Best,

DD

Message 7 of 8

ВeekeeCZ
Consultant
Consultant

@CodeDing wrote:

 

...

 

(defun c:TEST ( / ss e cnt)
  (if (setq ss (ssget '((0 . "LWPOLYLINE") (90 . 3))))
    (repeat (setq cnt (sslength ss))
      (setq e (ssname ss (setq cnt (1- cnt))))
      (setpropertyvalue e "Vertices" 2 "Position/Y" (getpropertyvalue e "Vertices" 1 "Position/Y"))
    );repeat
  );if
  (prompt "\nComplete.")
  (princ)
);defun

Best,

DD


 

... as a minimum for error prevention. But +1 for the simplicity.

Message 8 of 8

Sea-Haven
Mentor
Mentor

Nice idea for anyone using Bricscad does not support get or set property. Kent Cooper works.

0 Likes