PDA

View Full Version : Vertices of a Polyline



Tharwat
23rd Aug 2010, 08:53 pm
Hello.

How could I get the Vertices of a Polyline after selecting it.

Regards,

alanjt
23rd Aug 2010, 09:00 pm
(vlax-get OBJ 'Coordinates)
or
(entget eName) and use everything that has a DXF 10 code.


EDIT: I didn't realize you said Polyline. If so, forget the entget part (for LWPOlylines). You'll have to entnext through the polyline and take each 10 code.

Lee Mac
23rd Aug 2010, 09:03 pm
Quite a few ways to do that:

1) Vanilla AutoLISP: Retrieving all the DXF 10 codes:



(defun mAssoc ( key lst )
(foreach x lst
(if (= key (car x))
(setq l (cons (cdr x) l))
)
)
(reverse l)
)

(mAssoc 10 (entget <LWPolyline>))
2) Visual LISP: getting the Coordinates Property:



(defun LM:lst->2DPoint ( l ) ;; © Lee Mac 2010
(if l (cons (list (car l) (cadr l)) (LM:lst->2DPoint (cddr l))))
)

(LM:lst->2DPoint (vlax-get <LWPolyline VLA-Object> 'Coordinates))
Of course, these methods apply to an LWPolyline.

EDIT: Oops! Didn't see you posted Alan, sorry.

rkmcswain
23rd Aug 2010, 09:06 pm
One way...




(vlax-safearray->list
(vlax-variant-value
(vla-get-Coordinates
(vlax-ename->vla-object
ent
)
)
)
)




Results with vary depending on if the selected entity is a LWpolyline or a Polyline.
More details here: http://cadpanacea.com/node/188

BlackBox
23rd Aug 2010, 09:11 pm
Hello.

How could I get the Vertices of a Polyline after selecting it.

Regards,

Like so:



(defun c:TEST (/ ss coords)
(vl-load-com)
(cond
(*activeDoc*)
((setq *activeDoc* (vla-get-activedocument (vlax-get-acad-object)))))
(prompt "\n >> Select Line Object To Display Coordinates: ")
(if (setq ss (ssget ":S:E" '((0 . "*POLYLINE"))))
(progn
(vlax-for x (setq ss (vla-get-activeselectionset *activeDoc*))
(setq coords
(vlax-safearray->list
(vlax-variant-value
(vla-get-coordinates x)))))
(vla-delete ss)
(terpri)
(prompt "\n >> Coordinates List: \n\t\t\t")
(princ coords)
(terpri)))
(princ)) ;_end defun



Hope this helps!

Tharwat
23rd Aug 2010, 09:21 pm
Thank you gentlemen.

That's really great and marvellous.

Regards,

alanjt
23rd Aug 2010, 09:24 pm
One way...




(vlax-safearray->list
(vlax-variant-value
(vla-get-Coordinates
(vlax-ename->vla-object
ent
)
)
)
)




Results with vary depending on if the selected entity is a LWpolyline or a Polyline.
More details here: http://cadpanacea.com/node/188


Like so:



(defun c:TEST (/ ss coords)
(vl-load-com)
(cond
(*activeDoc*)
((setq *activeDoc* (vla-get-activedocument (vlax-get-acad-object)))))
(prompt "\n >> Select Line Object To Display Coordinates: ")
(if (setq ss (ssget ":S:E" '((0 . "*POLYLINE"))))
(progn
(vlax-for x (setq ss (vla-get-activeselectionset *activeDoc*))
(setq coords
(vlax-safearray->list
(vlax-variant-value
(vla-get-coordinates x)))))
(vla-delete ss)
(terpri)
(prompt "\n >> Coordinates List: \n\t\t\t")
(princ coords)
(terpri)))
(princ)) ;_end defun



Hope this helps!


Check out my post to see an alternative to vla-get-coordinats - saves a couple steps.

rkmcswain
24th Aug 2010, 02:06 am
Check out my post to see an alternative to vla-get-coordinats [(vlax-get OBJ 'Coordinates)]- saves a couple steps.

Good reminder - I always forget about that....
Thanks.

gile
24th Aug 2010, 08:09 am
Hi,

Another way, using vlax-curve* functions. Works with all curve polylines types (lw, 2d, 3d) returns WCS coordinates.


(defun polyCoords (pl / n l)
(vl-load-com)
(setq n (if (vlax-curve-IsClosed pl)
(fix (vlax-curve-getEndParam pl))
(1+ (fix (vlax-curve-getEndParam pl)))
)
)
(while (/= 0 n)
(setq l (cons (vlax-curve-getPointAtParam pl (setq n (1- n))) l))
)
)

fixo
24th Aug 2010, 11:19 am
Thanks, Gilles
Personally this likes me more
Regards,

Oleg

BlackBox
24th Aug 2010, 02:14 pm
Check out my post to see an alternative to vla-get-coordinats - saves a couple steps.


Good reminder - I always forget about that....
Thanks.

Agreed... thanks, Alan!