Jump to content

A naive doubt about rectangles


fabriciorby

Recommended Posts

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:

Link to comment
Share on other sites

(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)
)

Link to comment
Share on other sites

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 :D

Link to comment
Share on other sites

or this one ...

 

(vl-remove-if-not '(lambda (x) (eq (car x) 10)) retangulo)

 

Great minds think alike, Tharwat :thumbsup:... 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

Link to comment
Share on other sites

Great minds think alike, Tharwat :thumbsup:... 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))

Link to comment
Share on other sites

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. :thumbsup: :rofl:

Link to comment
Share on other sites

(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! :D

I'm sorry, I just saw all posts now D:

Link to comment
Share on other sites

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)
)

Link to comment
Share on other sites

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. :D

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...