Each new virtual component by default has Base Quantity settings as shown below.
How can I assign the base quantity to some parameter? BOMQuantity.SetBaseQuantity method could do all this work for us.
Let’s say we have the virtual component “Paint:1” and the user parameter “Paint_Mass”:
The following code sample illustrates the workflow:
Sub SetQuantity()
Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument
Dim oDef As AssemblyComponentDefinition
Set oDef = oDoc.ComponentDefinition
‘reference to the user parameter where mass value is stored
Dim oPar As Inventor.UserParameter
Set oPar = oDef.Parameters.UserParameters.Item("Paint_Mass")
‘get the reference to the virtual component by its name
Dim oOcc As ComponentOccurrence
Set oOcc = oDef.Occurrences.ItemByName("Paint:1")
‘virtual component definition
Dim oVirtualDef As VirtualComponentDefinition
Set oVirtualDef = oOcc.Definition
‘Assign the base quantity to the parameter oPar
‘Limitation: this works for length, volume, and mass units only.
Dim oBOMQuantity As BOMQuantity
Set oBOMQuantity = oVirtualDef.BOMQuantity
Call oBOMQuantity.SetBaseQuantity( _
BOMQuantityTypeEnum.kParameterBOMQuantity, oPar)
End Sub
If you check base quantity after this subroutine is completed you will see this:




Leave a Reply