Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

get points of multiple rectangles on a certain layer

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
bmelby
717 Views, 10 Replies

get points of multiple rectangles on a certain layer

HELP PLEASE!!

 

I need to get the lower left and upper right points of multiple rectangles on layer "assembly2"   There may be one rec in the drawing on "assembly2" layer, or may have multiple rectangles. 

10 REPLIES 10
Message 2 of 11
Kent1Cooper
in reply to: bmelby

I know how to get them, but questions arise:

 

Are they always all closed Polylines?  Or might any of them be Blocks, or some other kind of thing [3DFaces, 2D Solids, Polyfaces, etc.]?

 

In what form would you need the results?  A list of two-point lists, pairing the two corners of each rectangle together?  A list with Text such as "Rec1 LL" paired with each point separately?  A text file?  An Excel spreadsheet?  Text in the drawing?  A Table in the drawing?  Etc.  [Some of those I could help you with, but not all of them -- other people here will know about some that I don't.]

 

Might any of them ever be non-orthogonal ?  If so, would you want the opposite corner vertices [and if so, which ones], or the lower left and upper right corners of their bounding boxes, or something else?

 

Might there by any other Polylines [or other entity types] on that Layer that you don't want to get information from, such as non-closed Polylines, shapes other than rectangles, etc.?

Kent Cooper, AIA
Message 3 of 11
bmelby
in reply to: Kent1Cooper

The rectangle will alway be closed 2-D polylines on the "Assembly2" layer.

 

I need a list of the two points (lower left/upper right) associated with each rectangle.

 

I'd like it to find and analyze all rectangles found on that layer and then list the points  (lower left & upper right) for each rectangle it find (on assembly2)

Message 4 of 11
pbejse
in reply to: bmelby


@bmelby wrote:

The rectangle will alway be closed 2-D polylines on the "Assembly2" layer.

 

I need a list of the two points (lower left/upper right) associated with each rectangle.

 

I'd like it to find and analyze all rectangles found on that layer and then list the points  (lower left & upper right) for each rectangle it find (on assembly2)


Like Kent, what will be the format intended list? Anyhoo, here's a short lisp to retrieve the lower left and upper right [Bounding box]

 

(defun c:LLUR (/ rectangles rec data)
  (if (ssget "_X"
	     '((0 . "LWPOLYLINE") (8 . "assembly2") (70 . 1) (90 . 4))
      )
    (Vlax-for rec (setq	rectangles
			 (vla-get-ActiveSelectionSet
			   (vla-get-ActiveDocument
			     (vlax-get-acad-object)
			   )
			 )
		  )
      (vla-GetBoundingBox rec 'LL 'UR)
      (setq data (cons (list (vlax-safearray->list ll)
			     (vlax-safearray->list ur)
		       )
		       data
		 )
      )
    )
    )
    (vla-delete rectangles)
    (foreach itm data
      (print itm)
    )
  (princ)
)
(vl-load-com)

 

 

HTH

 

 

Message 5 of 11
bmelby
in reply to: pbejse

I have a program that these values will be entered into.  Its currently set to have the user manually sellect the points using "getpoint".  I would like it to set these automatically.

 

The setq's are as follows

 

Lower left of opening 1 = "OPPT1"

Upper right of opening 1 = "OPPT3"

 

Lower left of opening 2 = "OPPT5"

Upper right of opening 2 = "OPPT7"

 

Lower left of opening 3 = "OPPT9"

Upper right of opening3 = "OPPT11"

 

Lower left of opening 4 = "OPPT13"

Upper right of opening 4 = "OPPT15"

 

The max number of rectangle it will find in the drawing is 4...  

 

Thanks in advance!!

Message 6 of 11
Kent1Cooper
in reply to: bmelby


@bmelby wrote:

The rectangle will alway be closed 2-D polylines on the "Assembly2" layer.

 

I need a list of the two points (lower left/upper right) associated with each rectangle.

 

I'd like it to find and analyze all rectangles found on that layer and then list the points  (lower left & upper right) for each rectangle it find (on assembly2)


For an orthogonal rectangular closed 4-vertex Polyline of only straight-line segments, here's a somewhat simpler way to get its lower left and upper right corners, with 'ent' being the Polyline's entity name:

 

(setq

  v1 (vlax-curve-getPointAtParam ent 0); first vertex

  v2 (vlax-curve-getPointAtParam ent 2); third vertex

  LL (mapcar 'min v1 v2)

  UR (mapcar 'max v1 v2)

)

 

No VLA object conversion required, nor finding of bounding box and conversion of what that returns to get points out of it, and it doesn't matter in which direction it's drawn, nor at which corner it starts.

 

If you really "need a list of two points ... associated with each rectangle," you can do something like (list ent LL UR) with those results.  But it looks from a later message like you're really after separate variables with the corners stored in them independently as points.  That's not hard, but not right now -- back later if someone else doesn't beat me to it.

Kent Cooper, AIA
Message 7 of 11
Kent1Cooper
in reply to: pbejse


@pbejse wrote:
.... 
....
(if (ssget "_X" '((0 . "LWPOLYLINE") (8 . "assembly2") (70 . 1) (90 . 4)) ) ....

That's subject to possibly not working as expected....  The (70 . 1) there will find only closed Polylines with linetype generation disabled.  If it's enabled in that Polyline, that will be (70 . 129).

Kent Cooper, AIA
Message 8 of 11
Kent1Cooper
in reply to: Kent1Cooper


@Kent1Cooper wrote:

@pbejse wrote:
.... 
....
(if (ssget "_X" '((0 . "LWPOLYLINE") (8 . "assembly2") (70 . 1) (90 . 4)) ) ....

That's subject to possibly not working as expected....  The (70 . 1) there will find only closed Polylines with linetype generation disabled.  If it's enabled in that Polyline, that will be (70 . 129).


I had to look around a little to find/remind-myself how to do it, but this will find those both with and without linetype generation enabled:

 

(ssget "_X" '((0 . "LWPOLYLINE") (8 . "assembly2") (-4 . "&") (70 . 1) (90 . 4))))

Kent Cooper, AIA
Message 9 of 11
Kent1Cooper
in reply to: Kent1Cooper


@Kent1Cooper wrote:
....  But it looks from a later message like you're really after separate variables with the corners stored in them independently as points.  That's not hard, but not right now -- back later if someone else doesn't beat me to it.

Something like this [very lightly tested]:

 

(if
  (setq ss (ssget "_X" '((0 . "LWPOLYLINE") (8 . "assembly2") (-4 . "&") (70 . 1) (90 . 4))))
  (progn
    (setq n -1); counter for end number of variable names
    (repeat (setq m (sslength ss)); counter for rectangles
      (setq
        ent (ssname ss (setq m (1- m)))
        v1 (vlax-curve-getPointAtParam ent 0); first vertex
        v2 (vlax-curve-getPointAtParam ent 2); third vertex
      ); setq
      (set (read (strcat "OPPT" (itoa (setq n (+ n 2))))) (mapcar 'min v1 v2))
      (set (read (strcat "OPPT" (itoa (setq n (+ n 2))))) (mapcar 'max v1 v2))
    ); repeat
  ); progn
); if

Kent Cooper, AIA
Message 10 of 11
bmelby
in reply to: pbejse

This works just as I wanted it to!!!  Awesome work, thank you very much!!!!

Message 11 of 11
Lee_Mac
in reply to: bmelby

FWIW, here's another way to obtain the required data:

 

(defun c:rcorners ( / i l s v )
    (if (setq s (ssget "_X" '((0 . "LWPOLYLINE") (8 . "assembly2") (90 . 4) (-4 . "&=") (70 . 1))))
        (repeat (setq i (sslength s))
            (setq v (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) (entget (ssname s (setq i (1- i))))))
                  l (cons (mapcar '(lambda ( x ) (apply 'mapcar (cons x v))) '(min max)) l)
            )
        )
    )
    (foreach x l (print x))
    (princ)
)

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost