BUG DrawingDocument CreateGeometryIntent

BUG DrawingDocument CreateGeometryIntent

karolis.s
Advocate Advocate
389 Views
3 Replies
Message 1 of 4

BUG DrawingDocument CreateGeometryIntent

karolis.s
Advocate
Advocate

Hello.

I think I have found a bug in Inventor API drawing environment. Start and End points are mixed for some reason, on the specific drawing. I have tried it on Inventor 2020 and Inventor 2024 -> same result.

CreateGeometryIntent chooses wrong point. I have specified for it to use start point, but it returns end point.

Sub Main()
    AddLengthDimension
End Sub

Sub AddLengthDimension()
    Dim oSheet As Sheet
    Set oSheet = ThisApplication.ActiveDocument.ActiveSheet
    
    Dim oView As DrawingView
    Set oView = oSheet.DrawingViews.Item(1)
    
    Dim minX As Double
    Dim maxX As Double
    minX = 999999
    maxX = -999999
    
    Dim minXCurve As DrawingCurve
    Dim maxXCurve As DrawingCurve
    Dim minXIntent As GeometryIntent
    Dim maxXIntent As GeometryIntent
    Dim segment As DrawingCurveSegment
    Dim oCurve As DrawingCurve
        
    For Each oCurve In oView.DrawingCurves
        For Each segment In oCurve.Segments            
            
                If segment.StartPoint.X < minX Then
                    minX = segment.StartPoint.X
                    'Debug.Print (segment.StartPoint.IsEqualTo(oCurve.StartPoint))
                    Debug.Print (segment.StartPoint.X)
                    Set minXIntent = oSheet.CreateGeometryIntent(oCurve, PointIntentEnum.kStartPointIntent)
                    'ATTENTION BUG IS HERE!!!
                    'Uncommented line below resolves the issue
                    'Set minXIntent = oSheet.CreateGeometryIntent(oCurve, PointIntentEnum.kEndPointIntent)
                    Set minXCurve = oCurve
                End If
                
                If segment.endPoint.X < minX Then
                    minX = segment.endPoint.X
                    'Debug.Print (segment.StartPoint.IsEqualTo(oCurve.StartPoint))
                    Debug.Print (segment.endPoint.X)
                    Set minXIntent = oSheet.CreateGeometryIntent(oCurve, PointIntentEnum.kEndPointIntent)
                    Set minXCurve = oCurve
                End If
                
                
                
                If segment.StartPoint.X > maxX Then
                    maxX = segment.StartPoint.X
                    'Debug.Print (segment.EndPoint.IsEqualTo(oCurve.EndPoint))
                    Debug.Print (segment.StartPoint.X)
                    Set maxXIntent = oSheet.CreateGeometryIntent(oCurve, PointIntentEnum.kStartPointIntent)
                    Set maxXCurve = oCurve
                End If
                
                If segment.endPoint.X > maxX Then
                    maxX = segment.endPoint.X
                    'Debug.Print (segment.EndPoint.IsEqualTo(oCurve.EndPoint))
                    Debug.Print (segment.endPoint.X)
                    Set maxXIntent = oSheet.CreateGeometryIntent(oCurve, PointIntentEnum.kEndPointIntent)
                    Set maxXCurve = oCurve
                End If
            
            End If

            
        Next segment
    Next oCurve

    Dim oTG As TransientGeometry
    Set oTG = ThisApplication.TransientGeometry
    
    Dim textPoint As Point2d
    Set textPoint = oTG.CreatePoint2d((minX + maxX) / 2, oView.Position.Y - oView.Height / 2 - 5)
    
    Debug.Print ("Minimum: " & minX)
    Debug.Print ("Maximum: " & maxX)
    
    
    If Not minXIntent Is Nothing And Not maxXIntent Is Nothing Then
        Call oSheet.DrawingDimensions.GeneralDimensions.AddLinear(textPoint, minXIntent, maxXIntent, DimensionTypeEnum.kHorizontalDimensionType)
    End If
End Sub





karoliss_0-1706715647028.png

 



Attached is a drawing file.



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

karolis.s
Advocate
Advocate

I have found another issue / bug regarding this method.

In Inventor 2020 when I am creating a GeometryIntent object, returned object property "PointOnSheet" returns Nothing (So I get an an error in the script below)
In Inventor 2024 I don't get an error in the watch window I can see that correct point is assigned to GeometryIntent object. BUT when I am creating general dimensions it chooses wrong point.


Below is an image of the result I get from my script. It's really frustrating (I have walked around the previous bug in this thread by sending a function an expected point), but I do not have any ideas how to escape this one. Any help?


karoliss_0-1706854049253.png

 

Const Tolerance As Double = 1E-19

Sub Main()
    AddThicknessDimensionWithExtremumCall
    'ShowObjectData
End Sub

Sub AddThicknessDimensionWithExtremumCall()
    Dim oSheet As Sheet
    Set oSheet = ThisApplication.ActiveDocument.ActiveSheet
    
    ' Assuming the projected view is the 3rd view on the sheet
    Dim oView As DrawingView
    Set oView = oSheet.DrawingViews.Item(3)

    Dim minPoint As Point2d, maxPoint As Point2d
    Dim minXIntent As GeometryIntent, maxXIntent As GeometryIntent

    ' Call the GetExtremumPoints function with oppositeIsMax set to True
    Dim extremumPoints As Variant
    extremumPoints = GetExtremumPoints(oView, "X", True)
    Set minPoint = extremumPoints(0)
    Set maxPoint = extremumPoints(1)
    Set minXIntent = extremumPoints(2)
    Set maxXIntent = extremumPoints(3)

    Dim oTG As TransientGeometry
    Set oTG = ThisApplication.TransientGeometry
    
    ' Set the position for the dimension text slightly above the projected view
    Dim textPoint As Point2d
    Set textPoint = oTG.CreatePoint2d((minPoint.X + maxPoint.X) / 2, oView.Position.Y + oView.Height / 2 + 5)

    ' Add the dimension
    If Not minXIntent Is Nothing And Not maxXIntent Is Nothing Then
        Call oSheet.DrawingDimensions.GeneralDimensions.AddLinear(textPoint, minXIntent, maxXIntent, DimensionTypeEnum.kHorizontalDimensionType)
    End If
End Sub

Function GetExtremumPoints(view As DrawingView, axis As String, oppositeIsMax As Boolean) As Variant
    Dim minValue As Double
    Dim maxValue As Double
    Dim oppositeMinValue As Double
    Dim oppositeMaxValue As Double
    Dim minPoint As Point2d
    Dim maxPoint As Point2d
    Dim minIntent As GeometryIntent
    Dim maxIntent As GeometryIntent
    
    minValue = 999999
    maxValue = -999999
    If oppositeIsMax Then
        oppositeMinValue = -999999
        oppositeMaxValue = -999999
    Else
        oppositeMinValue = 999999
        oppositeMaxValue = -999999
    End If

    Dim curve As DrawingCurve
    Dim segment As DrawingCurveSegment
    For Each curve In view.DrawingCurves
        For Each segment In curve.Segments
            If segment.Visible Then
                Dim start As Point2d
                Dim ending As Point2d
                Set start = segment.StartPoint
                Set ending = segment.endPoint
                
                
                If Not start Is Nothing And Not ending Is Nothing Then
                    Dim primaryStartValue As Double
                    Dim primaryEndValue As Double
                    Dim oppositeStartValue As Double
                    Dim oppositeEndValue As Double
                    
                    If axis = "X" Then
                        primaryStartValue = start.X
                        primaryEndValue = ending.X
                        oppositeStartValue = start.Y
                        oppositeEndValue = ending.Y
                    Else
                        primaryStartValue = start.Y
                        primaryEndValue = ending.Y
                        oppositeStartValue = start.X
                        oppositeEndValue = ending.X
                    End If

                    Dim updateMin As Boolean
                    Dim updateMax As Boolean
                    
                    
                    If (start.X < 43.5993 Or ending.X < 43.5993) Then
                    'And (start.Y < 26.1 Or ending.Y < 26.1)
                        Debug.Print ("TRUE")
                        Debug.Print (Abs(primaryStartValue - minValue) < Tolerance)
                        
                        ' Code to execute if condition is true
                    End If
                    
                    
                    ' Update min value point considering opposite value as tie-breaker
                    updateMin = False
                    If minValue - primaryStartValue > Tolerance Then
                        updateMin = True
                    ElseIf Abs(primaryStartValue - minValue) < Tolerance And _
                       OppositeIsValid(oppositeIsMax, oppositeMinValue, oppositeStartValue, oppositeEndValue) Then
                       Debug.Print ("Update minimum values start point!")
                       updateMin = True
                    End If
                    
                    
                    If updateMin Then
                        minValue = primaryStartValue
                        oppositeMinValue = oppositeStartValue
                        Set minPoint = start
                        Set minIntent = CreateAndVerifyGeometryIntent(curve, start)
                    End If
                    
                    updateMin = False
                    If minValue - primaryEndValue > Tolerance Then
                        updateMin = True
                    ElseIf Abs(primaryEndValue - minValue) < Tolerance And _
                       OppositeIsValid(oppositeIsMax, oppositeMinValue, oppositeStartValue, oppositeEndValue) Then
                       Debug.Print ("Update minimum values end point!")
                       updateMin = True
                    End If
                    
                    
                    If updateMin Then
                        minValue = primaryEndValue
                        oppositeMinValue = oppositeEndValue
                        Set minPoint = ending
                        Set minIntent = CreateAndVerifyGeometryIntent(curve, ending)
                    End If
                    
                    ' Similar logic for max value point
                    updateMax = False
                    If primaryStartValue > maxValue Then updateMax = True
                    If primaryStartValue = maxValue And _
                       OppositeIsValid(oppositeIsMax, oppositeMaxValue, oppositeStartValue, oppositeEndValue) Then updateMax = True
                    
                    
                    If updateMax Then
                        maxValue = primaryStartValue
                        oppositeMaxValue = oppositeStartValue
                        Set maxPoint = start
                        Set maxIntent = CreateAndVerifyGeometryIntent(curve, start)
                    End If
                    
                    updateMax = False
                    If primaryEndValue > maxValue Then updateMax = True
                    If primaryEndValue = maxValue And _
                       OppositeIsValid(oppositeIsMax, oppositeMaxValue, oppositeStartValue, oppositeEndValue) Then updateMax = True
                    
                    If updateMax Then
                        maxValue = primaryEndValue
                        oppositeMaxValue = oppositeEndValue
                        Set maxPoint = ending
                        Set maxIntent = CreateAndVerifyGeometryIntent(curve, ending)
                    End If
                Else
                    Debug.Print ("START OR END IS NULL")
                    
                End If
            Else
                Debug.Print ("SEGMENT IS NOT VISIBLE!")
                
            
            End If
        Next segment
    Next curve

    ' Return as an array
    GetExtremumPoints = Array(minPoint, maxPoint, minIntent, maxIntent)
End Function

Function OppositeIsValid(oppositeIsMax As Boolean, oppositeValue As Double, oppositeStartValue As Double, oppositeEndValue As Double) As Boolean
    If oppositeIsMax Then
        OppositeIsValid = (oppositeStartValue > oppositeValue) Or (oppositeEndValue > oppositeValue)
    Else
        OppositeIsValid = (oppositeStartValue < oppositeValue) Or (oppositeEndValue < oppositeValue)
    End If
    'Debug.Print ("Opposite is valid: " & OppositeIsValid)
End Function

Function CreateAndVerifyGeometryIntent(curve As DrawingCurve, expectedPoint As Point2d) As GeometryIntent
    Dim drawDoc As DrawingDocument
    Set drawDoc = ThisApplication.ActiveDocument
    Dim oSheet As Sheet
    Set oSheet = drawDoc.ActiveSheet
    Dim intent As GeometryIntent
    Set intent = oSheet.CreateGeometryIntent(curve, PointIntentEnum.kStartPointIntent)
    
    ' Verify if the intent point matches the expected point, if not, try the alternate intent
    If Not PointsAreEqual(intent.PointOnSheet, expectedPoint) Then
        
        Set intent = oSheet.CreateGeometryIntent(curve, PointIntentEnum.kEndPointIntent)
    End If
    
    If Not PointsAreEqual(intent.PointOnSheet, expectedPoint) Then
        Debug.Print ("Couldn't find the expected point for curve in ")
        Err.Raise vbObjectError + 1, "CreateAndVerifyGeometryIntent", "Couldn't find the expected point for curve in " & ActiveSheet.Name
    
    End If
    

    Set CreateAndVerifyGeometryIntent = intent
End Function

' Helper function to compare two points for equality
Function PointsAreEqual(point1 As Point2d, point2 As Point2d) As Boolean
    'If (point1 Is Nothing) Or (point2 Is Nothing) Then
        'PointsAreEqual = False
    'Else
        'Const Tolerance As Double = 0.001 ' Define an appropriate tolerance
        PointsAreEqual = (Abs(point1.X - point2.X) < Tolerance) And (Abs(point1.Y - point2.Y) < Tolerance)
    'End If
End Function

Public Sub ShowObjectData()
    ' Set a reference to the select set of the active document.
    Dim oSelectSet As SelectSet
    Set oSelectSet = ThisApplication.ActiveDocument.SelectSet
    
    ' Check to make sure a single item was selected.
    If oSelectSet.Count = 1 Then
        Dim oSegment As DrawingCurveSegment
        Set oSegment = oSelectSet.Item(1)
        
        ' Print the segment's geometry type
        MsgBox "Geometry Type: " & oSegment.GeometryType
        
        ' Print start and end point values
        MsgBox "Start Point: X=" & oSegment.StartPoint.X & ", Y=" & oSegment.StartPoint.Y & vbCrLf & _
               "End Point: X=" & oSegment.endPoint.X & ", Y=" & oSegment.endPoint.Y
               
        Exit Sub
    Else
        MsgBox "You must select a single object."
        Exit Sub
    End If
End Sub



P.S the unusual way of number comparing is because I get unexpected results by simply using "< ; > ; =" signs. If I get it right it's wrong because big float numbers doesn't return the same value in bits sometimes. Had to spend a chunk of time to debug that.. 

0 Likes
Message 3 of 4

abdullah_elq
Advocate
Advocate
Accepted solution

I've run into this bug as well, and it is super annoying. One workaround is to pass in the point2d object when using CreateGeometryIntent. For example:

'Instead of:
Set intent = oSheet.CreateGeometryIntent(curve, PointIntentEnum.kEndPointIntent)

'Do this:
Set intent = oSheet.CreateGeometryIntent(curve, segment.EndPoint)

 

I got this code to work as intended (iLogic):

Sub Main()
    AddLengthDimension()
End Sub

Sub AddLengthDimension()
    Dim oSheet As Sheet
     oSheet = ThisApplication.ActiveDocument.ActiveSheet
    
    Dim oView As DrawingView
     oView = oSheet.DrawingViews.Item(1)
    
    Dim minX As Double
    Dim maxX As Double
    minX = 999999
    maxX = -999999
    
    Dim minXCurve As DrawingCurve
    Dim maxXCurve As DrawingCurve
    Dim minXIntent As GeometryIntent
    Dim maxXIntent As GeometryIntent
    Dim segment As DrawingCurveSegment
    Dim oCurve As DrawingCurve
        
    For Each oCurve In oView.DrawingCurves
        For Each segment In oCurve.Segments            
            
                If segment.StartPoint.X < minX Then
                    minX = segment.StartPoint.X
                    'Debug.Print (segment.StartPoint.IsEqualTo(oCurve.StartPoint))
                    Debug.Print (segment.StartPoint.X)
                     minXIntent = oSheet.CreateGeometryIntent(oCurve, segment.StartPoint)
                    'ATTENTION BUG IS HERE!!!
                    'Uncommented line below resolves the issue
                    'Set minXIntent = oSheet.CreateGeometryIntent(oCurve, PointIntentEnum.kEndPointIntent)
                     minXCurve = oCurve
                End If
                
                If segment.EndPoint.X < minX Then
                    minX = segment.EndPoint.X
                    'Debug.Print (segment.StartPoint.IsEqualTo(oCurve.StartPoint))
                    Debug.Print (segment.EndPoint.X)
                     minXIntent = oSheet.CreateGeometryIntent(oCurve, segment.EndPoint)
                     minXCurve = oCurve
                End If
                
                
                
                If segment.StartPoint.X > maxX Then
                    maxX = segment.StartPoint.X
                    'Debug.Print (segment.EndPoint.IsEqualTo(oCurve.EndPoint))
                    Debug.Print (segment.StartPoint.X)
                     maxXIntent = oSheet.CreateGeometryIntent(oCurve, segment.StartPoint)
                     maxXCurve = oCurve
                End If
                
                If segment.EndPoint.X > maxX Then
                    maxX = segment.EndPoint.X
                    'Debug.Print (segment.EndPoint.IsEqualTo(oCurve.EndPoint))
                    Debug.Print (segment.EndPoint.X)
                     maxXIntent = oSheet.CreateGeometryIntent(oCurve, segment.EndPoint)
                     maxXCurve = oCurve
                End If
            
           

            
        Next segment
    Next oCurve

    Dim oTG As TransientGeometry
     oTG = ThisApplication.TransientGeometry
    
    Dim textPoint As Point2d
     textPoint = oTG.CreatePoint2d((minX + maxX) / 2, oView.Position.Y - oView.Height / 2 - 5)
    
    Debug.Print ("Minimum: " & minX)
    Debug.Print ("Maximum: " & maxX)
    
    
    If Not minXIntent Is Nothing And Not maxXIntent Is Nothing Then
        Call oSheet.DrawingDimensions.GeneralDimensions.AddLinear(textPoint, minXIntent, maxXIntent, DimensionTypeEnum.kHorizontalDimensionType)
    End If
End Sub
Message 4 of 4

karolis.s
Advocate
Advocate

Thanks a lot! 

Dimension has a pink color, but it will work for us.. Hopefully Autodesk will fix these issues.

karoliss_0-1706940184481.png

 

0 Likes