Hi TONELLAL,
This example will set the part number iProperty in all of the components in the assembly, to match the component name with a prefix:
' set a reference to the assembly component definintion.
' This assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
'check for and skip virtual components
'(in case a virtual component trips things up)
If Not TypeOf oOccurrence.Definition Is VirtualComponentDefinition Then
'find colon SeparatorPosistion
Dim SeparatorPos As Long
SeparatorPos = InStrRev(oOccurrence.Name, ":",-1)
'define part number prefix
Dim sPrefix As String
sPrefix = "Test_"
'set part number for each component
iProperties.Value(oOccurrence.Name, "Project", "Part Number") = sPrefix & Left(oOccurrence.Name,SeparatorPos -1)
Else
End If
Next
To present the list of all the components to the user, so one of them can be selected, you can use something like this:
' set a reference to the assembly component definintion.
' This assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim MyArrayList As New ArrayList
'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
'check for and skip virtual components
'(in case a virtual component trips things up)
If Not TypeOf oOccurrence.Definition Is VirtualComponentDefinition Then
MyArrayList.add(oOccurrence.Name)
Else
End If
Next
oSelected = InputListBox("Select a component to use", MyArrayList, MyArrayList.Item(0), "iLogic", "Component List")
MessageBox.Show("You selected: " & vblf & oSelected, "iLogic")
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com