I have a virtual part inside an assembly, I can change all of the normal properties but can't manage to work out how to get the mass to change. I can see the mass and volume properties but they dont seem to update etc. my code is as below.
Option Explicit
Sub Main()
Dim oADoc As AssemblyDocument
Dim oCompOcc As ComponentOccurrence
Dim oVCompDef As VirtualComponentDefinition
Dim oMassStr As String
Dim oPropPartNo As Property
Dim oPropDesc As Property
Dim oPropMass As Property
Set oADoc = ThisApplication.ActiveDocument
oMassStr = oADoc.ComponentDefinition.MassProperties.Mass
Debug.Print (oMassStr)
If oMassStr > 4000 Then
Debug.Print ("True")
Else
Debug.Print ("False")
End If
For Each oCompOcc In oADoc.ComponentDefinition.Occurrences
If oCompOcc.Definition.Type = "100675072" Then ' Check to see if Virtual Part (Don't want to use enumerator)
Set oVCompDef = oCompOcc.Definition
Set oPropPartNo = oVCompDef.PropertySets.Item("Design Tracking Properties").Item("Part Number")
Set oPropDesc = oVCompDef.PropertySets.Item("Design Tracking Properties").Item("Description")
Set oPropMass = oVCompDef.PropertySets.Item("Design Tracking Properties").Item("Mass")
oPropPartNo.Value = "1234"
oPropDesc.Value = "4567"
oPropMass.Value = 8000
End If
Next
oADoc.Update
End Sub
Any help is much appreciated. Thanks.
Matt
Solved! Go to Solution.
Solved by nttoan8187. Go to Solution.
Hope this can help us, just need to change it a little for suitability with your need.
Public Sub GetPartMassProps()
' Set a reference to the part document.
' This assumes a part document is active.
Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.ActiveDocument
' Set a reference to the mass properties object.
Dim oMassProps As MassProperties
Set oMassProps = oPartDoc.ComponentDefinition.MassProperties
' Set the accuracy to medium.
oMassProps.Accuracy = k_Medium
' Set a reference to the mass properties object.
Dim oMass As Double
oMass = oMassProps.Mass
Msgbox(oMass)
End Sub
Thanks, you code helped. When i looked at it I realised i had gone too far into the part where I was looking for the mass properties (I was looking inside the virtual part's definition). I found the mass properties in the component occurence (from the assembly it is inside) and used your code slightly tweaked to be:
Dim oCompOcc As ComponentOccurrence
Dim oMassProps As MassProperties
Dim oMass As Double
Set oMassProps = oCompOcc.MassProperties
oMass = 458 ' New Mass Number I want to override with
oMassProps.Mass = oMass
Thanks again, Matt.