Update mass vb.NET

Update mass vb.NET

sebastian_varelaRD3LQ
Participant Participant
262 Views
3 Replies
Message 1 of 4

Update mass vb.NET

sebastian_varelaRD3LQ
Participant
Participant

Dear Inventor community,

I'm creating an addin to improve our workflow at Berkes SA. I am currently trying to update the mass automatically in our drawings, however I did not find in the API how to address the "update mass properties" button found in the BOM. it's possible? I would appreciate knowing if there is any way.

 

In my current code I found a longer way to approach the problem, although it works partially:

 

- It finds the mass value in the drawing's 1st part list

- Compares it to the one in the assembly

- Updates it if it's different.

 

However, if the user updates the mass with the button in the BOM, my code will request the update again.

 

I appreciate any help with this topic.

Best regards,

SV

 

Here my current code:

Private continueExcecution As Boolean = True
Private MasaYaUtilizada As Double = -1

Public Sub VerifyBeforExporting(drawingdoc As DrawingDocument)

    ' Obtain first partlist on drawing
    Dim partLists As PartsLists = drawingdoc.ActiveSheet.PartsLists
    Dim partList As PartsList = drawingdoc.ActiveSheet.PartsLists(1)
    Dim assemblydoc As AssemblyDocument = partList.ReferencedDocumentDescriptor.ReferencedDocument ' Obtain assembly used on first partlist
    Dim MasaOk As Boolean = True
    Dim VariesOk As Boolean = True

#Region "verificar masa"


    Dim massProperty As Inventor.Property = Nothing

    If partList IsNot Nothing Then                 ' Veryfy if the asssembly is not null
        If assemblydoc IsNot Nothing Then                     ' Obtain assembly iProperties 

            Dim propertySets As PropertySets = assemblydoc.PropertySets

            ' Obtain
            Dim DTprops As PropertySet = propertySets.Item("Design Tracking Properties")
            massProperty = DTprops.Item(39)

            'Console    -   Design Tracking Property - Número del Item: 39, Nombre: Mass, Valor:  0
            'Console    -   Design Tracking Property - Número del Item: 43, Nombre: Valid MassProps, Valor :  0

            ' Verificar si la propiedad de masa no es nula
            If massProperty IsNot Nothing Then

                Dim MassA As Double = 0

                If MasaYaUtilizada < 0 Then
                    MassA = massProperty.Value
                Else
                    MassA = MasaYaUtilizada
                End If

                Dim assemblyDef As AssemblyComponentDefinition = assemblydoc.ComponentDefinition    ' Obtain asssembly definition
                Dim massProps As MassProperties = assemblyDef.MassProperties                        ' Obtainassembly mass properties

                Dim MassB As Double = massProps.Mass * 1000


                ' COMPARE MASS VALUES
                If Not MassA = MassB Then

                    MsgBox($"Mass in drawing: {MassA} {enter}{enter} not the same as {enter}{enter}Mass in assembly: {MassB}")
                    MasaYaUtilizada = MassA
                    MasaOk = False
                Else
                    MsgBox($"Mass in drawing: {MassA} {enter}{enter} is the same as {enter}{enter}Mass in assembly: {MassB}")
                End If


            Else
                Console.WriteLine("No se pudo obtener el ensamblaje utilizado en la primera PartList.")
            End If
        End If
    Else
        Console.WriteLine("No se pudo obtener la primera PartList del dibujo.")
    End If
#End Region
End Sub

 

0 Likes
263 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor

Hi @sebastian_varelaRD3LQ.  You may already know this one, but when the button is pushed to update the mass properties, the ControlDefinition object named "AppUpdateMassPropertiesCmd" is executed.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

WCrihfield
Mentor
Mentor

Also, if you want to make sure you are getting the updated and accurate Mass value from the assembly's MassProperties, you should first make sure the assembly itself has been updated, then make sure the  MassProperties.MassOverridden Property is False, then change the MassProperties.Accuracy property value to a different setting (if currently Low, change to Medium, or the other way around), then finally get the value of its Mass property, and it will be 'recalculated' when you do so, to achieve the requested accuracy.

 

Edit:  Also, when comparing the Mass from the iProperties, and the Mass from the MassProperties, you may want to use some special comparison code other than simply '='.  I believe the Double data type can hold up to 15 decimal places, so comparing them can be tricky.  Some folks round those types of values off before comparing them, but you can also use something like the following:

Dim bEqual As Boolean = EqualWithinTolerance(a, b, 0.001)

That Double data type comparison Function (EqualWithinTolerance ) is sourced from the Autodesk.iLogic.Runtime.LmiMath Module/Class, which is included automatically for us in every iLogic rule, and allows us to specify how accurate we want the comparison to be.  Very handy.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 4

Frederick_Law
Mentor
Mentor

I round Mass to 2 decimal before compare.

0 Likes