Message 1 of 4
Update mass vb.NET
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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