It may be easier for me to add the rule that I have so far:
'Delete All Virtual Components
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim asmOcc As ComponentOccurrence
For Each asmOcc In oAsmCompDef.Occurrences
If TypeOf asmOcc.Definition Is VirtualComponentDefinition Then
asmOcc.Delete
End If
Next
'Look for all the Parts that have the Custom Virtual Component iProperty added to them
For Each oOccurrence In oAsmCompDef.Occurrences
Try
iProperties.Value(oOccurrence.Name, "Custom", "VC") = "True"
Try
iProperties.Value(oOccurrence.Name, "Custom", "VC1")= "VC1"
VC1_NAME = iProperties.Value(oOccurrence.Name, "Custom", "VC1_NAME")
VC1_PNUM = iProperties.Value(oOccurrence.Name, "Custom", "VC1_PNUM")
VC1_DESC = iProperties.Value(oOccurrence.Name, "Custom", "VC1_DESC")
VC1_BOMP = iProperties.Value(oOccurrence.Name, "Custom", "VC1_BOMP")
VC1_BCLASS = iProperties.Value(oOccurrence.Name, "Custom", "VC1_BCLASS")
'Create a virtual component
Dim oMatrix As Matrix
oMatrix = ThisApplication.TransientGeometry.CreateMatrix
Dim oNewOcc As ComponentOccurrence
oNewOcc = oAsmCompDef.Occurrences.AddVirtual(VC1_NAME, oMatrix)
Dim oCVirtualCompDef As VirtualComponentDefinition
oCVirtualCompDef = oNewOcc.Definition
InventorVb.DocumentUpdate()
'Pass in the Virtual Component iProperties from the part to the Virtual Component
iProperties.Value(VC1_NAME & ":1", "Project", "Part Number") = VC1_PNUM
iProperties.Value(VC1_NAME & ":1", "Project", "Description") = VC1_DESC
iProperties.Value(VC1_NAME & ":1", "Custom", "BOM Priority") = VC1_BOMP
iProperties.Value(VC1_NAME & ":1", "Custom", "BOM Class") = VC1_BCLASS
Catch EE As Exception
End Try
'Run the code again for a second VC embedded in the part, plan to add the ability to check for 5
Try
iProperties.Value(oOccurrence.Name, "Custom", "VC2")= "VC2"
VC2_NAME = iProperties.Value(oOccurrence.Name, "Custom", "VC2_NAME")
VC2_PNUM = iProperties.Value(oOccurrence.Name, "Custom", "VC2_PNUM")
VC2_DESC = iProperties.Value(oOccurrence.Name, "Custom", "VC2_DESC")
VC2_BOMP = iProperties.Value(oOccurrence.Name, "Custom", "VC2_BOMP")
VC2_BCLASS = iProperties.Value(oOccurrence.Name, "Custom", "VC2_BCLASS")
Dim oMatrix As Matrix
oMatrix = ThisApplication.TransientGeometry.CreateMatrix
Dim oNewOcc As ComponentOccurrence
oNewOcc = oAsmCompDef.Occurrences.AddVirtual(VC2_NAME, oMatrix)
Dim oCVirtualCompDef As VirtualComponentDefinition
oCVirtualCompDef = oNewOcc.Definition
InventorVb.DocumentUpdate()
iProperties.Value(VC2_NAME & ":1", "Project", "Part Number") = VC2_PNUM
iProperties.Value(VC2_NAME & ":1", "Project", "Description") = VC2_DESC
iProperties.Value(VC2_NAME & ":1", "Custom", "BOM Priority") = VC2_BOMP
iProperties.Value(VC2_NAME & ":1", "Custom", "BOM Class") = VC2_BCLASS
Catch EE As Exception
End Try
Catch EE As Exception
End Try
Next