GetMinimumDistance returning wrong value

GetMinimumDistance returning wrong value

GeorgK
Advisor Advisor
727 Views
7 Replies
Message 1 of 8

GetMinimumDistance returning wrong value

GeorgK
Advisor
Advisor

Hello together,

 

I try to get the minimaldistance with this code:

 

m_invApp = GetObject(, "Inventor.Application")

        Dim oFaceProxy As FaceProxy
        oFaceProxy = m_invApp.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select Face")

        If oFaceProxy Is Nothing Then
            Exit Sub
        End If
        On Error GoTo 0

        Dim oAssyDoc As AssemblyDocument
        oAssyDoc = m_invApp.ActiveDocument

        ' Set a reference to the mass properties object.
        Dim oMassProps As MassProperties
        oMassProps = oAssyDoc.ComponentDefinition.MassProperties

        'Check if mass property results are already available
        'at a high accuracy level or better. If so, simply
        'print out the results, else, set a flag to not cache
        'the results in the document.
        If oMassProps.AvailableAccuracy = MassPropertiesAccuracyEnum.k_High And oMassProps.AvailableAccuracy = MassPropertiesAccuracyEnum.k_VeryHigh Then
            ' Set the accuracy to high.
            oMassProps.Accuracy = MassPropertiesAccuracyEnum.k_High

            'Set CacheResultsOnCompute property to False
            'so that results are not saved with the document
            'and hence the document is not 'dirtied'.
            oMassProps.CacheResultsOnCompute = False
        End If

        Dim oMeasureTools As MeasureTools
        oMeasureTools = m_invApp.MeasureTools
        Dim oDistance As Double = oMeasureTools.GetMinimumDistance(oMassProps.CenterOfMass, oFaceProxy.PointOnFace)
        oDistance = oAssyDoc.UnitsOfMeasure.ConvertUnits(oDistance, "cm", "mm")
        MsgBox(oDistance)

But the result is wrong.

What I am doing wrong?

 

Thank you

Georg

0 Likes
728 Views
7 Replies
Replies (7)
Message 2 of 8

chandra.shekar.g
Autodesk Support
Autodesk Support

@GeorgK,

 

Code seems to fine for me. Can you please demonstrate wrong distance value? I mean, what is actual value and expected value from Inventor API.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 8

GeorgK
Advisor
Advisor

Hello @chandra.shekar.g,

 

there is a difference:

Abstand.png

 

0 Likes
Message 4 of 8

chandra.shekar.g
Autodesk Support
Autodesk Support

@GeorgK,

 

Can you please provide sample file to test this behaviour? please make sure that files are non confidential.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 5 of 8

GeorgK
Advisor
Advisor

Attached is a sample model

 

Abstand_1.png

0 Likes
Message 6 of 8

chandra.shekar.g
Autodesk Support
Autodesk Support

@GeorgK,

 

Tried below VBA code to measure distance between center of mass and selected face.

 

Sub Distance()
    Dim oFace As FaceProxy
    Set oFace = ThisApplication.CommandManager.Pick(kPartFaceFilter, "Select a face")

    Dim oDoc As AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oDef As AssemblyComponentDefinition
    Set oDef = oDoc.ComponentDefinition
    
    Dim oMassProp As MassProperties
    Set oMassProp = oDef.MassProperties
    
    Dim oWpt As WorkPoint
    Set oWpt = oDef.WorkPoints.AddFixed(oMassProp.CenterOfMass)
    
    Dim oTool As MeasureTools
    Set oTool = ThisApplication.MeasureTools
    
    Dim oDist As Double
    oDist = oTool.GetMinimumDistance(oWpt, oFace)
    
    oDist = oDoc.UnitsOfMeasure.ConvertUnits(oDist, "cm", "mm")
    MsgBox (oDist)
End Sub

On running above code, it prompts for selection of face and selected the face as shown below.

 

Face_selection.png

 

On successful completion of code, Distance is shown in message box as shown below.

 

Distance_Measured.PNG

Which is same value as measured in Measure tool.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 7 of 8

GeorgK
Advisor
Advisor

Hello @chandra.shekar.g,

 

thank you very much. That's working but without the

CacheResultsOnCompute

 Is there any solution for this? Or is the result buggy?

 

Georg

0 Likes
Message 8 of 8

chandra.shekar.g
Autodesk Support
Autodesk Support

@GeorgK,

 

Same result is shown after using "CacheResultsOnCompute" property. Try below VBA code.

 

Sub Distance()
    Dim oFace As FaceProxy
    Set oFace = ThisApplication.CommandManager.Pick(kPartFaceFilter, "Select a face")

    Dim oDoc As AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oDef As AssemblyComponentDefinition
    Set oDef = oDoc.ComponentDefinition
    
    Dim oMassProp As MassProperties
    Set oMassProp = oDef.MassProperties
    
    If oMassProp.AvailableAccuracy = k_High Or oMassProp.AvailableAccuracy = k_VeryHigh Then
        ' Set the accuracy to high.
        oMassProp.Accuracy = k_High

        'Set CacheResultsOnCompute property to False
        'so that results are not saved with the document
        'and hence the document is not 'dirtied'.
        oMassProp.CacheResultsOnCompute = False
    End If
 
    
    Dim oTool As MeasureTools
    Set oTool = ThisApplication.MeasureTools
    
    Dim oDist As Double
    oDist = oTool.GetMinimumDistance(oMassProp.CenterOfMass, oFace)
    
    oDist = oDoc.UnitsOfMeasure.ConvertUnits(oDist, "cm", "mm")
    MsgBox (oDist)
End Sub

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes