How to check the block reference is intersect with the nearest line or not?

How to check the block reference is intersect with the nearest line or not?

Anonymous
Not applicable
769 Views
3 Replies
Message 1 of 4

How to check the block reference is intersect with the nearest line or not?

Anonymous
Not applicable
Hi
I am trying to writing a module for checking the block reference is intersect with the nearest polyline or not?. I have code for getting the list of AcadBlockReference, with this list i have to check this block is intersect with the the nearest polyline or not? How it is possible?. Reply me.
0 Likes
770 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Hi Ershad,

Create a selection set of all the polylines in the drawing.

You can get the upper right and lower left coordinates of a block
reference. Draw a polyline rectangle using those coordinates.

Then do an IntersectWith of that polyline with each of the polylines
from the selection set and determine which one meets your criteria of
being the nearest.

If none are detected then no polylines intersect the block reference.

Then increase the size of your polyline by the distance you just
identified and repeat as there may be a polyline which didn't intersect
the block, but is close to it.

Note this is not perfect as a polyline may be inside the bounding box
and not intersect it, or it may intersect the bounding box, but not the
block reference inside it.

Regards


Laurie Comerford

Ershad.shaikh wrote:
> Hi I am trying to writing a module for checking the block reference is
> intersect with the nearest polyline or not?. I have code for getting the
> list of AcadBlockReference, with this list i have to check this block is
> intersect with the the nearest polyline or not? How it is possible?.
> Reply me.
0 Likes
Message 3 of 4

Anonymous
Not applicable
Using following code i am getting all the list of block's. And now i want to check block's, it is intersected with any line or not? plz tell me how to check this block is intersect or not ?

Dim ssobjs As AcadEntity

For Each ssobjs In ThisDrawing.ModelSpace
If ssobjs.ObjectName = "AcDbBlockReference" Then
' Here I want to check this Adbclockreference is intersect with any line
'How to do this stuff?
End If
Next
0 Likes
Message 4 of 4

Anonymous
Not applicable
Hi Ershad,

Instead of testing every object in the drawing make a selection set of
the block references by using the GetUserSelectedObjects function below.

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Hand Select objects of a nominated type
' Status: Functional
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function GetUserSelectedObjects(ssObs As AcadSelectionSet,
spObjectType As String) As Long
On Error Resume Next
Dim FilterType(0 To 0) As Integer
Dim FilterData(0 To 0) As Variant
Dim sNumber As String
FilterType(0) = 0: FilterData(0) = spObjectType
' The line below will create an error if the SSET doesn't exist
' or delete it if it does exist.
' The ON Error will allow the program to continue and create the set
ThisDrawing.SelectionSets.Item("SSET").Delete
If Err > 0 Then Err.Clear
On Error GoTo ErrorHandler
Set ssObs = ThisDrawing.SelectionSets.Add("SSET")
ssObs.SelectOnScreen FilterType, FilterData
GetUserSelectedObjects = ssObs.Count
Exit Function

ErrorHandler:
Err.Clear
GetUserSelectedObjects = 0
End Function ' GetUserSelectedObjects()

Call in with code like:

Dim ssBlocks As AcadSelectionSet
Dim ssPolies As AcadSelectionSet
dim l as Long
Dim lPolies as Long
l = GetUserSelectedObjects (ssBlocks, "INSERT")
lPolies = GetUserSelectedObjects (ssPolies , "LWPOLYLINE")


Then use code like:

Dim oRef as AcadBlockReference
Dim oPoly as AcadLWPolyline
Dim v as Variant
If l > 0 And lPolies > 0 then
For Each oRef in ss
For Each oPoly in ssPolies
v = oRef.IntersectWith(oPoly, acExtendNone)
If UBound(v) > -1 Then
' Do your thing
End if
Next
Next
end If


From some limited testing I've done with the
"BlockReference.IntersectWith" API, it appears uses the bounding box of
the block reference as it's checking mechanism so that you will get a
result showing where the polyline intersects the bounding box of the
block reference. The polyline need not actually intersect any of the
drafting of the block reference.


Regards


Laurie Comerford

Ershad.shaikh wrote:
> Using following code i am getting all the list of block's. And now i
> want to check block's, it is intersected with any line or not? plz tell
> me how to check this block is intersect or not ? Dim ssobjs As
> AcadEntity For Each ssobjs In ThisDrawing.ModelSpace If
> ssobjs.ObjectName = "AcDbBlockReference" Then ' Here I want to check
> this Adbclockreference is intersect with any line 'How to do this stuff?
> End If Next
0 Likes