.GetMinimumDistance of Curve Segments in two different drawing views. Problem with isometric views

.GetMinimumDistance of Curve Segments in two different drawing views. Problem with isometric views

SevInventor
Advocate Advocate
1,007 Views
12 Replies
Message 1 of 13

.GetMinimumDistance of Curve Segments in two different drawing views. Problem with isometric views

SevInventor
Advocate
Advocate

Hey Experts, what can I do?

 

I've adapted  a code from here:

 

Gelöst: Re: Auto-detect View Overlap on IDW - Autodesk Community - Inventor

Only for isometric views the code fails at the following line:

 

oMinDist = oMT.GetMinimumDistance(CurveSegment, bCurveSegment)

 

getMinimumdistance measures  0 even if the drawing curves don't overlap.

 

Is there an alternativ way to detect if drawing curves overlap?

Is there an alternativ way to measure the minimum distance of drawing curves?

 

 

Sub Main()
Dim oDoc As Document = ThisApplication.ActiveDocument
If oDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
	On Error resume next
Dim oSheet As Sheet = oDoc.ActiveSheet
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
For Each AView As DrawingView In oSheet.DrawingViews
    Dim SP1 As Point2d = AView.Position
    SP1 = oTG.CreatePoint2d(SP1.X - (AView.Width * 0.5), SP1.Y - (AView.Height * 0.5))
    Dim EP1 As Point2d = oTG.CreatePoint2d(SP1.X + AView.Width, SP1.Y + AView.Height)
    For Each BView As DrawingView In oSheet.DrawingViews
        If AView Is BView Then Continue For
        If CheckCH(AView.Name, BView.Name) Then Continue For
        AddCH(AView.Name, BView.Name)
        Dim SP2 As Point2d = BView.Position
        SP2 = oTG.CreatePoint2d(SP2.X - (BView.Width * 0.5), SP2.Y - (BView.Height * 0.5))
        Dim EP2 As Point2d = oTG.CreatePoint2d(SP2.X + BView.Width, SP2.Y + BView.Height)
        Dim DoOverlap As Boolean = CalcOverlap(SP1, EP1, SP2, EP2)
        If DoOverlap Then
			Dim oMT As MeasureTools = ThisApplication.MeasureTools
            For Each aDrawingCurve As DrawingCurve In AView.DrawingCurves
					For Each aCurveSegment As DrawingCurveSegment In aDrawingCurve.CurveSegments
						For Each bDrawingCurve As DrawingCurve In BView.DrawingCurves
							For Each bCurveSegment As DrawingCurveSegment In bDrawingCurve.CurveSegments
								oMinDist = oMT.GetMinimumDistance(CurveSegment, bCurveSegment)
								If oMinDist = 0 Then
									DoOverlap2 = True
									GoTo overlapping
								End If
							Next
						Next	
					Next
			Next

        End If
    Next
	
Next

Exit Sub

overlapping: 
MsgBox("precise calculation shows an overlap")
End Sub

Private CH(0,1) As String 'Calculation History, so we don't match two views twice

Private Function CalcOverlap(SP1 As Point2d, EP1 As Point2d, SP2 As Point2d, EP2 As Point2d) As Boolean
    If SP1.X < SP2.X Then 'A is on left
        If EP1.X < SP2.X Then Return False
        If EP1.Y > EP2.Y Then 'A is on top
            If SP1.Y < EP2.Y Then Return True
        Else
            If EP1.Y > SP2.Y Then Return True
        End If
    Else
        If EP2.X < SP1.X Then Return False
        If EP1.Y > EP2.Y Then 'A is on top
            If SP1.Y < EP2.Y Then Return True
        Else
            If EP1.Y > SP2.Y Then Return True
        End If
    End If
    Return False
End Function

Private Function CheckCH(AName As String, BName As String) As Boolean
    For i = 0 To CInt((CH.Length / 2)) - 1
        If CH(i,0) = AName And CH(i, 1) = BName Then Return True
        If CH(i,0) = BName And CH(i, 1) = AName Then Return True
    Next
    Return False
End Function

Private Sub AddCH(AName As String, BName As String)
    Dim i As Integer = CInt((CH.Length / 2))
    If CH(i - 1, 0) = vbNullString And CH(i - 1, 0) = vbNullString Then
        i = i - 1
    Else 
        ReDim Preserve CH(i, 1)
'		Catch 
'		End try
    End If
    CH(i, 0) = AName
    CH(i, 1) = BName
End Sub

 

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

J-Camper
Advisor
Advisor

@SevInventor,

 

I found that if you check the Geometry Property of the DrawingCurveSegment, I can get the ISO view to identify correctly unless there is an arc that is overlapping...

Partial solution would be to change this line:

								oMinDist = oMT.GetMinimumDistance(CurveSegment, bCurveSegment)

To be this:

								oMinDist = oMT.GetMinimumDistance(aCurveSegment.Geometry, bCurveSegment.Geometry)

But it still won't work if the overlapping DrawingCurveSegment is arc...

 

I also changed corrected an object variable name from "CurveSegment" to "aCurveSegment", because I could not see where "CurveSegment" was defined.  I re-wrote the rule during my testing, which I have attached, but the fix above should work in original posted code.

 

Message 3 of 13

SevInventor
Advocate
Advocate

Hello JCamper,

 

thanks.

Adding .Geometry i still have the same results. If one view is a iso view the overlap is detected even if the drawing curves don't touch. See picture:

SevInventor_0-1685537441334.png

 

Ive tested your code and it didn't detect an overlap even if the views are on top of each other:

SevInventor_1-1685537492472.png

 

 

0 Likes
Message 4 of 13

J-Camper
Advisor
Advisor
Accepted solution

@SevInventor,

 

My code was only writing to the ilogic logger, I didn't display a message. Here is my test scenario:

overlappingoverlappingnot overlappingnot overlapping

 

The logger result from the overlapping run looks like this:

INFO| 1: >>---------------------------
TRACE|There is at least 1 visible overlapping drawingcurve between Views: 
    VIEW1  &  VIEW2

 

I edited my rule to show a message box and highliht the DrawingCurveSegments that it detected were overlapping.  Attached as text file.

 

 

0 Likes
Message 5 of 13

J-Camper
Advisor
Advisor

The issue that still persists is an arc drawing curve:

linesegment overlapslinesegment overlapsonly arc overlapsonly arc overlaps

 

I still haven't figured out a way to detect an overlapping arc.

Message 6 of 13

SevInventor
Advocate
Advocate

O yes, it works better than my code.

Sorry I didn't check the logger.

Now it works fine except the arc curves. Do you think it is possible to use GetMinimumDistance for such?

0 Likes
Message 7 of 13

J-Camper
Advisor
Advisor

@SevInventor,

 

I can't understand why GetMinimumDistance isn't working for the arc.  I can play around with it some more, but I don't have an answer as of now.

0 Likes
Message 8 of 13

SevInventor
Advocate
Advocate
Accepted solution

Hello Jcamper,

 

I've changed;

If oMT.GetMinimumDistance(Asegment.Geometry, Bsegment.Geometry) > 0 Then Continue For 

to:

If oMT.GetMinimumDistance(Asegment.Geometry, Bsegment.Geometry,kNoInterference,kNoInterference) > 0 Then Continue For 

 now it works fine and the arcs are detected.

Thank you very much!

0 Likes
Message 9 of 13

J-Camper
Advisor
Advisor

@SevInventor,

 

I'm glad that appears to work for you, but I can't reproduce the success. I don't see a kNoInterference Option under the InferredTypeEnum.  It doesn't seem to throw and error, but my test scenario is still not recognizing the arc intersection.

 

What version of Inventor are you using?

Message 10 of 13

SevInventor
Advocate
Advocate

@J-Camper 

I'm using Build: 372, Release 2019.6

During my tests the code was quite slow and not 100% reliable.

So im still searching for a better solution. 

I've tried:

If Asegment.Geometry.Intersectwith(Bsegment.Geometry) Then

results-->detects an overlap if the curves are not touching

0 Likes
Message 11 of 13

J-Camper
Advisor
Advisor

@SevInventor,

 

I see.  I've been testing in 2023 Inventor, but it looks like the Objects we are using have not changed much.

 

I'm surprised that doesn't cause an error as the full name of the method is "IntersectsWithCurve" and, on top of that, if Asegment.Geometry is an Arc2d, it does not have the IntersectsWithCurve Method at all.  Are you not getting an error because you are modifying your original code?  I saw your original code has "On Error Resume Next" at the very beginning, which may be giving weird results and will hide errors from you while you build the script.

 

I don't have the Error handling in the script I posted, so it should be giving errors if it doesn't understand/can't perform the line of code.

0 Likes
Message 12 of 13

SevInventor
Advocate
Advocate

Yes, You're right.

do you think

oSheet.CreateGeometryIntent(aDrawingCurve,...)

could help? 

another approach could be using the points of the Curve segments? 

I Imagine that GetMinimumDistance would work better using points instead of segments

 

0 Likes
Message 13 of 13

J-Camper
Advisor
Advisor

@SevInventor,

 

I've made a new discovery.  It is only arc's created from the fillet command that are not being recognized:

arc from filletarc from filletarc from extrusionarc from extrusion

 

It still doesn't make sense why the filleted arc is not recognized, but this means the rule handles everything except for filleted arcs...  This is without adding the "InferredTypeEnum", so the same text file I have posted in message 4, will produce these results.

0 Likes