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

Finding blocks attached to other blocks

4 REPLIES 4
Reply
Message 1 of 5
dy_lan
310 Views, 4 Replies

Finding blocks attached to other blocks

I'm trying to write a LISP which will determine which blocks are next to or attached to the current block on each side seperately, in order to automate the 'joining' part of plotting our network plans.

 

I have a selection set containing the middle block. On each side of the block there is another block.

 

Is there any way to determine which block is directly attached to the right/left/top/bottom side of my selection? The blocks are rectangular and slot together to form a grid, each one is plotted to a seperate sheet and we want to write 'joins plan X' on each side of the sheet where there is a joining plan.

 

I had a thought of creating a bounding box, expanding it one pixel to the right, one in from the top/left/bottom and then grabbing objects inside that box - is there a more elegant way to achieve this?

 

Thanks in advance!

4 REPLIES 4
Message 2 of 5
pbejse
in reply to: dy_lan


@dy_lan wrote:

I'm trying to write a LISP which will determine which blocks are next to or attached to the current block on each side seperately, in order to automate the 'joining' part of plotting our network plans.

 


Attached = nested inside a block?

Next= Adjacent to?

 

or are they pertainng to the same thing? as "right beside" <top/left/bottom/right> ?

Message 3 of 5
Kent1Cooper
in reply to: dy_lan


@dy_lan wrote:

.... 

Is there any way to determine which block is directly attached to the right/left/top/bottom side of my selection? The blocks are rectangular ....


If they are actually touching, you should be able to get the corners of the bounding box of the selected one, and use that in an (ssget) function as a Crossing window to select adjacent ones.  Do you know how to set that up?

 

By the way, welcome to these Forums!

Kent Cooper, AIA
Message 4 of 5
dy_lan
in reply to: Kent1Cooper

The boxes are rectangles, inserted so the top-left point snaps to the top-right point - so if the top-right point of a box matches the top-left point, that box is 'to the right' - if the bottom-left matches the top-left, that box is 'on top' etc. However, I couldn't figure out how to get the exactly top-left and bottom-right of all the boxes in order to find out which one matches.

Here's the function I put together which does do something like that, but I'm really new to LISP and CAD in general so I think I'm having trouble understanding the management of points. Any tips on how to familiarize myself working with points would be greatly appreciated!

(defun getboxbelow (plan / result)
; Get the width of the current plan
(setq plan (getPlanEnt plan))
(setq box (LM:ssboundingbox (ssadd plan)))
(command "draworder" (ssadd plan) "" "back" "")
(setq width (- (caadr box) (caar box)))
; Grab half the width, add it to bottom-left point
(setq newpt (list (+ (caar box) (/ width 2)) (cadar box) 0.0))
(setq bottomline (list (car points) (list (caadr points) (cadar points) 0.0)))
(setq topline (list (list (caar points) (cadadr points) 0.0) (cadr points)))
(princ newpt)

(setq result (_getAtt (ssname (ssget newpt) 0) "NP"))
)

getPlanEnt returns the entity of the box in question; ssboundingbox returns the bounding box.

Imagine a grid, 3x3 of boxes stacked on each other. The middle box's top-right point is in the same location as the three 'top-right boxes' so when I grab that point and get three boxes back, I guess I need to check which one of those boxes has a bottom-right point matching my selection point?

As you can probably see in the script above, my solution was to move the point to the middle of the bottom line of the box so that it'd only return the two boxes, then put the 'selected box' into back and return the first (front) result of the match. It kinda works, but I get the sense there's a much, much better way to be doing this!
Message 5 of 5
pbejse
in reply to: dy_lan


@dy_lan wrote:
The boxes are rectangles, inserted so the top-left point snaps to the top-right point - so if the top-right point of a box matches the top-left point, that box is 'to the right' - if the bottom-left matches the top-left, that box is 'on top' etc. However, I couldn't figure out how to get the exactly top-left and bottom-right of all the boxes in order to find out which one matches... 

....As you can probably see in the script above, my solution was to move the point to the middle of the bottom line of the box so that it'd only return the two boxes, then put the 'selected box' into back and return the first (front) result of the match. It kinda works, but I get the sense there's a much, much better way to be doing this!

I'd rather see a sample drawing than try to understand what you meant by the statement above dy_lan.

 

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

Post to forums  

Autodesk Design & Make Report

”Boost