fabriciorby Posted March 12, 2013 Share Posted March 12, 2013 I create a rectangle with the rec command, ok. It's a LWPOLYLINE. So, I need to get the 4 cornerpoints. I try to do this: (setq retangulo (entget(car(entsel)))) But I just can get this first point, so sad :/ (setq pt1 (cdr (assoc 10 retangulo))) How can I get the other points? ((-1 . <Entity name: 7ef21ce0>) (0 . "LWPOLYLINE") (330 . <Entity name: 7ef0ac10>) (5 . "4B1BC") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "layer") (100 . "AcDbPolyline") (90 . 4) (70 . 1) (43 . 0.0) (38 . 0.0) (39 . 0.0) (10 329020.0 7.3941e+006) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 329098.0 7.3941e+006) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 329098.0 7.39408e+006) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 329020.0 7.39408e+006) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (210 0.0 0.0 1.0)) I know it's a list. Thank you (: -edit: Maybe it would be easier using Visual Lisp code, but it would be good to have both for me to compare D: Quote Link to comment Share on other sites More sharing options...
Tharwat Posted March 12, 2013 Share Posted March 12, 2013 Try this untested codes . (foreach pt retangulo (if (eq (car pt) 10) (setq lst (cons (cdr pt) lst)) ) ) Quote Link to comment Share on other sites More sharing options...
BlackBox Posted March 12, 2013 Share Posted March 12, 2013 (vl-load-com) (defun c:GetCoordinates (/ ss) (if (setq ss (ssget ":S:E" '((0 . "*POLYLINE")))) (princ (vlax-get (vlax-ename->vla-object (ssname ss 0)) 'coordinates ) ) (prompt "\n** Nothing selected ** ") ) (princ) ) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted March 12, 2013 Share Posted March 12, 2013 or this one ... (vl-remove-if-not '(lambda (x) (eq (car x) 10)) retangulo) Quote Link to comment Share on other sites More sharing options...
fabriciorby Posted March 12, 2013 Author Share Posted March 12, 2013 Try this untested codes . (foreach pt retangulo (if (eq (car pt) 10) (setq lst (cons (cdr pt) lst)) ) ) Yeah! You got it! Hm, so simple (: I need to improve my list handling. Thank you, Tharwat Quote Link to comment Share on other sites More sharing options...
Tharwat Posted March 12, 2013 Share Posted March 12, 2013 Yeah! You got it!Hm, so simple (: I need to improve my list handling. Thank you, Tharwat You're very welcome . Quote Link to comment Share on other sites More sharing options...
BlackBox Posted March 12, 2013 Share Posted March 12, 2013 or this one ... (vl-remove-if-not '(lambda (x) (eq (car x) 10)) retangulo) Great minds think alike, Tharwat ... Here's a quick speed test: (setq rec (ssname (ssget ":S:E" '((0 . "*POLYLINE"))) 0)) (setq oRec (vlax-ename->vla-object rec)) (defun _foreach (/ lst) (foreach pt (entget rec) (if (eq (car pt) 10) (setq lst (cons (cdr pt) lst)) ) ) ) (defun _lambda () (vl-remove-if-not (function (lambda (x) (= 10 (car x)))) (entget rec) ) ) (defun _vl () (vlax-get oRec 'coordinates) ) (bench '(_foreach _lambda _vl) '() 100000) ... And the results: _$ _FOREACH Elapsed: 5538 Average: 0.0554 _LAMBDA Elapsed: 4789 Average: 0.0479 _VL Elapsed: 2137 Average: 0.0214 Quote Link to comment Share on other sites More sharing options...
Tharwat Posted March 12, 2013 Share Posted March 12, 2013 Great minds think alike, Tharwat ... Here's a quick speed test: Thank You RM . The dxf 10 works only for LWpolyline and if the user selected 3dpoly , the result would be nil . (setq rec (ssname (ssget ":S:E" '((0 . "[color=red]*POLYLINE[/color]"))) 0)) Quote Link to comment Share on other sites More sharing options...
BlackBox Posted March 12, 2013 Share Posted March 12, 2013 The dxf 10 works only for LWpolyline and if the user selected 3dpoly , the result would be nil . ... All the more reason (for me) to stick with Visual LISP then. Quote Link to comment Share on other sites More sharing options...
fabriciorby Posted March 12, 2013 Author Share Posted March 12, 2013 (vl-load-com) (defun c:GetCoordinates (/ ss) (if (setq ss (ssget ":S:E" '((0 . "*POLYLINE")))) (princ (vlax-get (vlax-ename->vla-object (ssname ss 0)) 'coordinates ) ) (prompt "\n** Nothing selected ** ") ) (princ) ) Thank you too, BlackBox! I'm sorry, I just saw all posts now D: Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 12, 2013 Share Posted March 12, 2013 I recommend a 'massoc' function, for example: ;; MAssoc - Lee Mac ;; Returns all associations of a key in an association list (defun LM:MAssoc ( key lst / item ) (if (setq item (assoc key lst)) (cons (cdr item) (LM:MAssoc key (cdr (member item lst)))) ) ) Now, (defun c:test ( / s ) (if (setq s (ssget "_+.:E:S" '((0 . "LWPOLYLINE")))) (mapcar 'print (LM:MAssoc 10 (entget (ssname s 0)))) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 12, 2013 Share Posted March 12, 2013 Here's a quick speed test... However, you are comparing apples with oranges since all three tested functions return a different output. Quote Link to comment Share on other sites More sharing options...
fabriciorby Posted March 13, 2013 Author Share Posted March 13, 2013 I recommend a 'massoc' function, for example: ;; MAssoc - Lee Mac ;; Returns all associations of a key in an association list (defun LM:MAssoc ( key lst / item ) (if (setq item (assoc key lst)) (cons (cdr item) (LM:MAssoc key (cdr (member item lst)))) ) ) Now, (defun c:test ( / s ) (if (setq s (ssget "_+.:E:S" '((0 . "LWPOLYLINE")))) (mapcar 'print (LM:MAssoc 10 (entget (ssname s 0)))) ) (princ) ) Yeah! This worked too. (: Thank you, Lee Mac. 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.