How to get list of blocks intersecting with a line?

How to get list of blocks intersecting with a line?

ShricharanaB
Advocate Advocate
1,405 Views
12 Replies
Message 1 of 13

How to get list of blocks intersecting with a line?

ShricharanaB
Advocate
Advocate

Hi,

I'm trying to make a code so that I can select two points (always on the horizontal plane) and add a dynamic block between those two points and change the length to the distance between two points. This I can already do. Now I want to get a list of all blocks that are intersecting with the newly added block. Is it possible to get this list WITHOUT using ssget ( 0 . "insert")  and checking each block if it is intersecting or not? Because with this method (ssget method) I would have to check thousands of blocks if it intersects with the newly added block, and this command will be run multiple times in a short duration. 

 

(lee mac's LM:intersections function can return nill if given two blocks donot intersect).

 

Thanks in advance for any help.

0 Likes
Accepted solutions (1)
1,406 Views
12 Replies
Replies (12)
Message 2 of 13

Kent1Cooper
Consultant
Consultant
Accepted solution

@ShricharanaB wrote:

... so that I can select two points ... and ... get a list of all blocks that are intersecting with the newly added block ... WITHOUT using ssget ( 0 . "insert")  ... Because with ... (ssget method) I would have to check thousands of blocks if it intersects with the newly added block....


You would need to check lots of Blocks only if you use (ssget "_X" ...) to find all Blocks first.  But you can use (ssget) to find only those intersected by the virtual line between your points.  Try this [which includes converting the selection set to a list]:

(setq blklist (mapcar 'cadr (ssnamex (ssget "_F" (list YourPoint1 YourPoint2) '((0 . "INSERT"))))))

Kent Cooper, AIA
Message 3 of 13

john.uhden
Mentor
Mentor

@Kent1Cooper :

Great idea, but if the insertion point of A is to the right of A's boundingbox, and the insertion point of B is to the left of B's bounding box, then there is a strong chance of finding neither on the fence line between the two.

That's why I keep wishing for Autodesk to build a boundingpoly function.

John F. Uhden

Message 4 of 13

ShricharanaB
Advocate
Advocate

Hi @Kent1Cooper,

 

It works very well for what I need.  Thank you!

 

 

0 Likes
Message 5 of 13

Kent1Cooper
Consultant
Consultant

@john.uhden wrote:

.... if the insertion point of A is to the right of A's boundingbox, and the insertion point of B is to the left of B's bounding box, then there is a strong chance of finding neither on the fence line between the two.

....


The method doesn't really care about the insertion points, only the drawn elements that a Fence selection would cross.  If they're looking for only Blocks whose insertion points lie on that virtual line, that's another question.

Kent Cooper, AIA
0 Likes
Message 6 of 13

ShricharanaB
Advocate
Advocate

In my case I'm not looking for insertion points that lies on the line between two selected points but all the fences that cross this line.

I don't understand one thing here, the blocks insertion is on the XY plane (Z= 0) plane as well, but, the block does not contain any entities on the z = 0 plane, but some 100 mm above it. There is a single vertical line connecting this body and the insertion point (think of a balloon and the thread tied to the balloon). The two points I'm selecting are always on z= 0, and the line between these two points doesn't always cross the insertion point but may be little offset from it. How is it that it is still getting the blocks correctly even though the line doesn't touch any elements of the block? 

ShricharanaB_1-1674632545173.png

 

 

0 Likes
Message 7 of 13

Kent1Cooper
Consultant
Consultant

@ShricharanaB wrote:

.... the block does not contain any entities on the z = 0 plane.... The two points I'm selecting are always on z= 0.... How is it that it is still getting the blocks correctly even though the line doesn't touch any elements of the block?


Are you applying Fence selection when in a 3D view such as your image, or when in plan view?  If the Fence visually crosses something in the current view, it will be selected.

Kent Cooper, AIA
Message 8 of 13

john.uhden
Mentor
Mentor

@ShricharanaB 

I believe that AutoCAD decides on intersections with complex objects using its "boundingbox" method, which is a rectangle whose dimensions are the horizontal and vertical extents of the object.  It does not use a multilateral figure that hugs the outline of each and every component.

To see what I mean, try this little routine to select one object (like a circle or mtext or a block insertion) and draw its boundingbox:

(defun c:BBOX ( / object LL UR)
  (and
    (setq object (vlax-ename->vla-object (car (entsel))))
    (or (vla-getboundingbox object 'LL 'UR) 1)
    (setq LL (vlax-safearray->list LL)
          UR (vlax-safearray->list UR)
    )
    (vl-cmdf "_.rectangle" "_non" LL "_non" UR)
  )
  (princ)
)

 

John F. Uhden

Message 9 of 13

Kent1Cooper
Consultant
Consultant

@john.uhden wrote:

I believe that AutoCAD decides on intersections with complex objects using its "boundingbox" method....


If you mean it decides whether a Fence selection "catches" something based on whether the Fence intersects the something's bounding box, that's not the case.  That would suggest that in this image:

Kent1Cooper_0-1674669257599.png

[a sphere as in Message 6, its bounding box being the green dots], a Fence selection along the red Line would select the sphere.  But it does not.

 

But maybe I misunderstood what you were suggesting.

Kent Cooper, AIA
0 Likes
Message 10 of 13

john.uhden
Mentor
Mentor

@Kent1Cooper 

Let's say it was my mistake via misunderstanding.

I was thinking of selecting by fence that crossed through the object, and that it used a built-in intersectwith method, and in the example of a line vl-intersectingwith  with mtext, the intersection points are on the mtext's boundingbox, not on the mtext itself.  But clearly the fence method works just like CrossingPolygon.  So I was way off base.

John F. Uhden

0 Likes
Message 11 of 13

Sea-Haven
Mentor
Mentor

Hey chuck in the mix dashed lines, they get missed sometimes but lucky there is a variable can be set to fix that problem. Now what was it. Will find it.

0 Likes
Message 12 of 13

Kent1Cooper
Consultant
Consultant

LTGAPSELECTION.  Set it to 1 to have things in other-than-continuous linetypes be selected by a Fence even if it passes through a gap.

Kent Cooper, AIA
0 Likes
Message 13 of 13

Sea-Haven
Mentor
Mentor

Thanks

0 Likes