By Xiaodong Liang
A weldment has a single special local occurrence of the welds component. We can get the MassProperties from ComponentOccurrence.MassProperties for this welds component instance. Just walk the occurrences of the weldment assembly looking for the local occurrence whose Definition is the WeldsComponentDefinition.
But no API to get the mass/volume of each weld. This can be worked around by deleting each weld, calculating by the current mass/ volume with mass/ volume of the total weld.
Sub getWeldMassAndVolume()
' get active Inventor process
Dim InvApp As Inventor.Application = _
Runtime.InteropServices.Marshal. _
GetActiveObject("Inventor.Application")
Dim oAssDoc As AssemblyDocument
oAssDoc = InvApp.ActiveDocument
Dim cd As ComponentDefinition
cd = oAssDoc.ComponentDefinition
If cd.Type = _
ObjectTypeEnum.kWeldmentComponentDefinitionObject Then
Dim wcd As WeldmentComponentDefinition
wcd = cd
Debug.Print("Total mass of assembly" _
& wcd.MassProperties.Mass)
Debug.Print(" Total volume of assembly" _
& wcd.MassProperties.Volume)
'Suppose the weld occurrence is the
' first one in this assembly.
Dim oO As ComponentOccurrence
oO = wcd.Occurrences(1)
Dim oTotalWeldsMass As Double
oTotalWeldsMass = oO.MassProperties.Mass
Dim oTotalWeldsVolume As Double
oTotalWeldsVolume = oO.MassProperties.Volume
Debug.Print(" mass of welds" & oTotalWeldsMass)
Debug.Print(" volume of welds" & oTotalWeldsVolume)
Dim oEachWeldB As WeldBead
For Each oEachWeldB In wcd.Welds.WeldBeads
'oEachWeldB.FaceSetOne
'oEachWeldB.FaceSetTwo
'oEachWeldB.BeadLength
'oEachWeldB.WeldInfo
'oEachWeldB.SideFaces
Next
' a workaround to get mass & volum of each weldbead
For Each oEachWeldB In wcd.Welds.WeldBeads
Dim oStr As String
oStr = oEachWeldB.Name
oEachWeldB.Delete()
Debug.Print(" mass of weld [" & oStr & "]: " _
& oTotalWeldsMass - oO.MassProperties.Mass)
Debug.Print(" volume of weld [" & oStr & "]: " _
& oTotalWeldsVolume - oO.MassProperties.Volume)
'undo delete
InvApp.CommandManager. _
ControlDefinitions("AppUndoCmd").Execute()
Next
End If
End Sub

Leave a Reply