Hi,
This VBA example moves the end of the part after the first feature. It then gets the Volume and puts that value in an iProperty. After this the end of the part is moved to the end of the features and the volume is retrieved again and saved to a different iProperty. Maybe an approach like this will meet your requirement.
'Update From the example in the API help
Public Sub UpdateVolume()
' Get the active part document.
Dim invPartDoc As PartDocument
Set invPartDoc = ThisApplication.ActiveDocument
' Get the custom property set.
Dim invCustomPropertySet As PropertySet
Set invCustomPropertySet = invPartDoc.PropertySets.Item("Inventor User Defined Properties")
Dim oFeat As ExtrudeFeature
Set oFeat = invPartDoc.ComponentDefinition.Features.ExtrudeFeatures(1)
Call oFeat.SetEndOfPart(False)
' Get the volume of the part. This will be returned in
' cubic centimeters.
Dim dVolume As Double
dVolume = invPartDoc.ComponentDefinition.MassProperties.Volume
' Get the UnitsOfMeasure object which is used to do unit conversions.
Dim oUOM As UnitsOfMeasure
Set oUOM = invPartDoc.UnitsOfMeasure
' Convert the volume to the current document units.
Dim strVolume As String
strVolume = oUOM.GetStringFromValue(dVolume, oUOM.GetStringFromType(oUOM.LengthUnits) & "^3")
Call AddiProps("OriginalVolume", strVolume, invCustomPropertySet)
Call invPartDoc.ComponentDefinition.SetEndOfPartToTopOrBottom(False)
dVolume = invPartDoc.ComponentDefinition.MassProperties.Volume
' Convert the volume to the current document units.
strVolume = oUOM.GetStringFromValue(dVolume, oUOM.GetStringFromType(oUOM.LengthUnits) & "^3")
Call AddiProps("FinalVolume", strVolume, invCustomPropertySet)
End Sub
Public Function AddiProps(iPropName As String, Vol As String, invCustomPropertySet As PropertySet)
' Attempt to get an existing custom property named "Volume".
On Error Resume Next
Dim myProperty As Property
Set myProperty = invCustomPropertySet.Item(iPropName)
If Err.Number <> 0 Then
' Failed to get the property, which means it doesn't exist
' so we'll create it.
Call invCustomPropertySet.Add(Vol, iPropName)
Else
' Got the property so update the value.
myProperty.Value = Vol
End If
End Function
Thanks,
Wayne
Wayne Brill
Developer Technical Services
Autodesk Developer Network