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