Bug: Get the intersection of drawing curves without Inventor crashing

Bug: Get the intersection of drawing curves without Inventor crashing

aelqabbany
Advocate Advocate
429 Views
2 Replies
Message 1 of 3

Bug: Get the intersection of drawing curves without Inventor crashing

aelqabbany
Advocate
Advocate

Hi,

 

I want to get the dimension of these two intersections:

  1. Topline and the line sloping to the right
  2. Topline and the line sloping to the left

The script works unless the lines are at 90 degrees, in which case Inventor will immediately crash.

 

I have had this happen with Inventor 2020.3 and Inventor 2021.

 

P.S. I would also appreciate any tips on how to make the script more efficient.

 

In this case, the script works fine:

Inventor Crash.png

 

In this case, Inventor crashes:

Inventor Crash 2.png

 

Is the issue a bug with Inventor or a bug with my code?

Sub Main()
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

Dim oSheet As Sheet
oSheet = oDrawDoc.ActiveSheet

Dim oBaseView As DrawingView
oBaseView = oSheet.DrawingViews.Item(1)

Dim oIntent1 As GeometryIntent = oSheet.CreateGeometryIntent(get_Max_Y_Line(oSheet, oBaseView), get_Rightmost_Curve(oSheet, oBaseView))
Dim oIntent2 As GeometryIntent = oSheet.CreateGeometryIntent(get_Max_Y_Line(oSheet, oBaseView), get_Leftmost_Curve(oSheet, oBaseView))
Dim oDimensionPoint As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oBaseView.Center.X, oBaseView.Top + 2)
oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oDimensionPoint,oIntent1,oIntent2,DimensionTypeEnum.kHorizontalDimensionType).Text.FormattedText = "Cutting Length: " & "<DimensionValue/>" 
End Sub

Public Function get_Max_Y_Line(oSheet As Sheet, oWorkingView As DrawingView) As DrawingCurve
Dim Max_Y_Line As DrawingCurve
For Each oDrawingCurve As DrawingCurve In oWorkingView.DrawingCurves
	Try
	If (oDrawingCurve.CurveType = CurveTypeEnum.kLineSegmentCurve) _
		And (EqualWithinTolerance(oDrawingCurve.StartPoint.Y, oDrawingCurve.EndPoint.Y, 0.001)) _
		And (Abs(oDrawingCurve.EndPoint.X - oDrawingCurve.StartPoint.X) > 0.4 * oWorkingView.Width) _
		And (oDrawingCurve.Segments(1).HiddenLine = False) _
		And EqualWithinTolerance(oDrawingCurve.EndPoint.Y, oWorkingView.Top, 0.1) Then
			get_Max_Y_Line = oDrawingCurve
	End If
	Catch
	End Try
Next 

End Function

Public Function get_Rightmost_Curve(oSheet As Sheet, oWorkingView As DrawingView) As DrawingCurve
Dim Rightmost_Point As Double = oWorkingView.Center.X
For Each oDrawingCurve As DrawingCurve In oWorkingView.DrawingCurves
	'Bug is in this line. I want to ensure that the curve is either vertical or has a positive slope
	If oDrawingCurve.StartPoint.X - oDrawingCurve.EndPoint.X = 0 Orelse (Sign(oDrawingCurve.StartPoint.Y - oDrawingCurve.EndPoint.Y) = Sign(oDrawingCurve.StartPoint.X - oDrawingCurve.EndPoint.X)) Then 
		If oDrawingCurve.StartPoint.X > Rightmost_Point
			Rightmost_Point = oDrawingCurve.StartPoint.X
			get_Rightmost_Curve = oDrawingCurve
		End If 
		If oDrawingCurve.EndPoint.X > Rightmost_Point And
			Rightmost_Point = oDrawingCurve.EndPoint.X
			get_Rightmost_Curve = oDrawingCurve
		End If
	End If
Next
End Function

Public Function get_Leftmost_Curve(oSheet As Sheet, oWorkingView As DrawingView) As DrawingCurve
Dim Leftmost_Point As Double = oWorkingView.Center.X
For Each oDrawingCurve As DrawingCurve In oWorkingView.DrawingCurves
	'Bug is in this line. I want to ensure that the curve is either vertical or has a negative slope
	If oDrawingCurve.StartPoint.X - oDrawingCurve.EndPoint.X = 0 OrElse (Sign(oDrawingCurve.StartPoint.Y - oDrawingCurve.EndPoint.Y) <> Sign(oDrawingCurve.StartPoint.X - oDrawingCurve.EndPoint.X)) Then 
		If oDrawingCurve.StartPoint.X < Leftmost_Point
			Leftmost_Point = oDrawingCurve.StartPoint.X
			get_Leftmost_Curve = oDrawingCurve
		End If 
		If oDrawingCurve.EndPoint.X < Leftmost_Point And
			Leftmost_Point = oDrawingCurve.EndPoint.X
			get_Leftmost_Curve = oDrawingCurve
		End If
	End If
Next
End Function

 

 

0 Likes
Accepted solutions (1)
430 Views
2 Replies
Replies (2)
Message 2 of 3

Ralf_Krieg
Advisor
Advisor
Accepted solution

Hello

 

Seems to be a bug in your code. In the function get_Leftmost_Curve at line

 

If oDrawingCurve.StartPoint.X - oDrawingCurve.EndPoint.X = 0 OrElse (Sign(oDrawingCurve.StartPoint.Y - oDrawingCurve.EndPoint.Y) <> Sign(oDrawingCurve.StartPoint.X - oDrawingCurve.EndPoint.X)) Then

 

 

First part is false for the horizontal bottom line of your part.

oDrawingCurve.StartPoint.X - oDrawingCurve.EndPoint.X = 0

 

So orElse will be executed.

 

(Sign(oDrawingCurve.StartPoint.Y - oDrawingCurve.EndPoint.Y)

 

This will evaluate to 0.

 

Sign(oDrawingCurve.StartPoint.X - oDrawingCurve.EndPoint.X)

This will evaluate to 1 or -1.

 

So the orElse will evaluate to True.

If the bottom line is before the left line in drawingcurves enumerator, it will be the leftmost curve, cause the left line has no x value smaller then bottom line, if it is vertical. You have to filter out the horizontal bottom line. Maybe simply by checking if

(Sign(oDrawingCurve.StartPoint.Y - oDrawingCurve.EndPoint.Y) <> 0 

 

In the end, the creation of intent2 fails and adding dimension seems to crash inventor is intent2 is nothing.

You should not compress your code to minimum length. Take the time to check values before proceed.

 

I've added additional check above to your function. Seems to work and I think it should be added to function get_Rightmost_Curve also.

 

 

 

Public Function get_Leftmost_Curve(oSheet As Sheet, oWorkingView As DrawingView) As DrawingCurve
Dim Leftmost_Point As Double = oWorkingView.Center.X

For Each oDrawingCurve As DrawingCurve In oWorkingView.DrawingCurves
	'Bug is in this line. I want to ensure that the curve is either vertical or has a negative slope
	If oDrawingCurve.StartPoint.X - oDrawingCurve.EndPoint.X = 0 OrElse (Sign(oDrawingCurve.StartPoint.Y - oDrawingCurve.EndPoint.Y) <> 0 And Sign(oDrawingCurve.StartPoint.X - oDrawingCurve.EndPoint.X) <> Sign(oDrawingCurve.StartPoint.Y - oDrawingCurve.EndPoint.Y))Then 
		If oDrawingCurve.StartPoint.X < Leftmost_Point
			Leftmost_Point = oDrawingCurve.StartPoint.X
			get_Leftmost_Curve = oDrawingCurve
		End If 
		If oDrawingCurve.EndPoint.X < Leftmost_Point And
			Leftmost_Point = oDrawingCurve.EndPoint.X
			get_Leftmost_Curve = oDrawingCurve
		End If
	End If
Next    
End Function

 

 

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 3 of 3

aelqabbany
Advocate
Advocate

Thank you very much bro. That makes a lot of sense.

I really appreciate it.

0 Likes