Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I want to get the dimension of these two intersections:
- Topline and the line sloping to the right
- 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:
In this case, Inventor crashes:
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
Solved! Go to Solution.