Tharwat Posted August 23, 2010 Share Posted August 23, 2010 Hello. How could I get the Vertices of a Polyline after selecting it. Regards, Quote Link to comment Share on other sites More sharing options...
alanjt Posted August 23, 2010 Share Posted August 23, 2010 (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. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 23, 2010 Share Posted August 23, 2010 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. Quote Link to comment Share on other sites More sharing options...
rkmcswain Posted August 23, 2010 Share Posted August 23, 2010 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 Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 23, 2010 Share Posted August 23, 2010 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! Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 23, 2010 Author Share Posted August 23, 2010 Thank you gentlemen. That's really great and marvellous. Regards, Quote Link to comment Share on other sites More sharing options...
alanjt Posted August 23, 2010 Share Posted August 23, 2010 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. Quote Link to comment Share on other sites More sharing options...
rkmcswain Posted August 24, 2010 Share Posted August 24, 2010 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. Quote Link to comment Share on other sites More sharing options...
gile Posted August 24, 2010 Share Posted August 24, 2010 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)) ) ) Quote Link to comment Share on other sites More sharing options...
fixo Posted August 24, 2010 Share Posted August 24, 2010 Thanks, Gilles Personally this likes me more Regards, Oleg Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 24, 2010 Share Posted August 24, 2010 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! Quote Link to comment Share on other sites More sharing options...
sonali Posted April 8, 2015 Share Posted April 8, 2015 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! Hello sir, the code what you have written is very helpful to me. But, I just wanted t know that, how can I get this data into a csv file in a single row. Please help me, sir in his regard. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted April 9, 2015 Share Posted April 9, 2015 Good task to learn lisp, instead of (princ coords) you would do a (write-line coords fo) look up lisp help how to "Open" a file. You will also need to add a bit more so its comma seperated. look up lisp help re "nth" to read value in a list. Also "Repeat" & "length" Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted April 10, 2015 Share Posted April 10, 2015 Hello sir, the code what you have written is very helpful to me. But, I just wanted t know that, how can I get this data into a csv file in a single row.Please help me, sir in his regard. single row? X,Y,X,Y,X,Y....etc..? not separated column X,Y? [color="green"] (defun c:TEST (/ ss coords [color="black"]fn f[/color] ) ;;... ;;... (terpri) (prompt "\n >> Coordinates List: \n\t\t\t") (princ coords)[/color] (setq fn (strcat (getvar "dwgprefix") "SONALI LWPOLY.csv") [color="green"]; <-- output file[/color] f (open fn "a")) [color="green"]; "a" to append, "w" to overite[/color] (write-line (apply 'strcat (mapcar ''((x) (strcat (rtos x 2 3) ",")) [color="green"]; or "\t" for tab[/color] coords ) ) f ) (if f (close f)) (startapp "notepad" fn) ; <--optional [color="green"] (terpri))) (princ)) ;_end defun[/color] Quote Link to comment Share on other sites More sharing options...
pBe Posted April 10, 2015 Share Posted April 10, 2015 (defun c:TEST (/ ss coords fn f ) ..... (apply 'strcat (mapcar ''((x) (strcat (rtos x 2 3) ",")) ; or "\t" for tab coords ) ) [/code] I like Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 10, 2015 Share Posted April 10, 2015 (mapcar ''((x) (strcat (rtos x 2 3) ",")) I admire the variation, but just be aware that since this construct is equivalent to defining a function using defun-q, you may lose performance: (defun mapcar-quote-lambda ( lst ) (mapcar '(lambda ( x ) (+ 2 x)) lst) ) (defun mapcar-function-lambda ( lst ) (mapcar (function (lambda ( x ) (+ 2 x))) lst) ) (defun mapcar-quote-quote ( lst ) (mapcar ''(( x ) (+ 2 x)) lst) ) (defun mapcar-defun-q ( lst ) (mapcar '2+q lst) ) (defun mapcar-defun ( lst ) (mapcar '2+ lst) ) (defun 2+ ( x ) (+ 2 x)) (defun-q 2+q ( x ) (+ 2 x)) _$ (setq lst '(1 2 3 4 5)) (1 2 3 4 5) _$ (benchmark '((mapcar-quote-lambda lst)(mapcar-function-lambda lst)(mapcar-quote-quote lst)(mapcar-defun-q lst)(mapcar-defun lst))) Benchmarking ...................Elapsed milliseconds / relative speed for 65536 iteration(s): (MAPCAR-QUOTE-LAMBDA LST)........1170 / 2.35 <fastest> (MAPCAR-FUNCTION-LAMBDA LST).....1186 / 2.32 (MAPCAR-DEFUN LST)...............1186 / 2.32 (MAPCAR-QUOTE-QUOTE LST).........2652 / 1.04 (MAPCAR-DEFUN-Q LST).............2746 / 1 <slowest> (Above results for 'uncompiled' code) Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted April 10, 2015 Share Posted April 10, 2015 I admire the variation, but just be aware that since this construct is equivalent to defining a function using defun-q, you may lose performance Thank you Lee, good advise i admit these variation is poor for speed (my signature noted: "lambda not optimized..") @pBE : It's just for lazy typist maybe slow due to extra quote? Tools -> Check Text in Editor window ; warning: bad argument: (QUOTE (( ... ) ( ... ))) (MAPCAR (QUOTE (QUOTE ((X) (+ 2 X)))) LST)[color="green"] ; <-- 4 pairs parentheses, ie: extra (quote ) ?[/color] (MAPCAR (FUNCTION (LAMBDA (X) (+ 2 X))) LST)[color="green"] ; <-- 3 pairs parentheses[/color] another two more for testing ([color="blue"]defun-q-list-set[/color] '2+a '(( x ) (+ 2 x))) ([color="blue"]set[/color] '2+b '(( x ) (+ 2 x))) (defun mapcar-defun-qa ( lst ) (mapcar '2+a lst) ) (defun mapcar-set ( lst ) (mapcar '2+b lst) ) defun-q-list-set the slowest (MAPCAR-DEFUN LST)...............1172 / 2.13 <fastest> (MAPCAR-QUOTE-LAMBDA LST)........1187 / 2.11 (MAPCAR-FUNCTION-LAMBDA LST).....1250 / 2 ([color="red"]MAPCAR-SET[/color] LST).................2375 / 1.05 (MAPCAR-QUOTE-QUOTE LST).........2422 / 1.03 (MAPCAR-DEFUN-Q LST).............2469 / 1.01 ([color="red"]MAPCAR-DEFUN-QA[/color] LST)............2500 / 1 <slowest> my surprise set is just a bit faster then double quote Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 10, 2015 Share Posted April 10, 2015 Of course, there is also the incredibly slow: (mapcar (quote (eval (defun-q foo ( x ) (+ 2 x)))) lst) (mapcar (quote (eval (defun foo ( x ) (+ 2 x)))) lst) Benchmarking ...................Elapsed milliseconds / relative speed for 65536 iteration(s): (MAPCAR-DEFUN LST)..................1170 / 3.47 <fastest> (MAPCAR-QUOTE-LAMBDA LST)...........1201 / 3.38 (MAPCAR-FUNCTION-LAMBDA LST)........1217 / 3.33 (MAPCAR-QUOTE-QUOTE LST)............2745 / 1.48 (MAPCAR-DEFUN-QA LST)...............2761 / 1.47 (MAPCAR-SET LST)....................2761 / 1.47 (MAPCAR-DEFUN-Q LST)................2808 / 1.44 (MAPCAR-QUOTE-EVAL-DEFUN LST).......3073 / 1.32 (MAPCAR-QUOTE-EVAL-DEFUN-Q LST).....4056 / 1 <slowest> Quote Link to comment Share on other sites More sharing options...
pBe Posted April 10, 2015 Share Posted April 10, 2015 @pBE : It's just for lazy typist Yes, I know. i just like the variation since i never thought of coding it that way. Nice still. Quote Link to comment Share on other sites More sharing options...
sonali Posted April 11, 2015 Share Posted April 11, 2015 (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))) ) [color="red"][color="red"](setq n -1) (setq lll (length coords)) (repeat lll (setq n (+ 1 n)) (setq cox1(nth n coords)) (setq co1(rtos cox1 2 2)) (setq f(open "D:/circle.csv" "a")) (write-line co1 f) (close f) [/color] ) [/color] ) (vla-delete ss) (terpri) (prompt "\n >> Coordinates List: \n\t\t\t") (princ coords) (terpri))) (princ)) ;_end defun Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.