Dim oOccurrence As ComponentOccurrence Dim Prop As String Try oOccurrence = ThisDoc.Document.SelectSet.Item(1) Catch MessageBox.Show("Please select a part / subAssembly!", "Get Index of Part / SubAssembly", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1) Return End Try 'active assembly s Dim oMainAsm As AssemblyDocument = ThisDoc.Document Dim oAsmDef As AssemblyComponentDefinition = oMainAsm.ComponentDefinition index = oOccurrence."INDEX OF THE SELECTED PART / SUBASSEMBLY" ??? ' get the occurrence by its position in the occurrences collection Dim oOcc As ComponentOccurrence = oAsmDef.Occurrences.Item(index)
Is it possible to get the index from oOccurrence as shown in the Code above?
Solved! Go to Solution.
Solved by tobias.orlow. Go to Solution.
Hi @Darrell.johnson ,
you can do so by iterating through the Occurrences collection with a 'for'-loop as seen in the code below.
Note however that this will only go through your top level assemblies' occurrences. If you have more nested assemblies and e.g. a part within a sub-assembly gets selected, you'll have to add additional logic.
Dim oOccurrence As ComponentOccurrence Dim Prop As String Try oOccurrence = ThisDoc.Document.SelectSet.Item(1) Catch MessageBox.Show("Please select a part / subAssembly!", "Get Index of Part / SubAssembly", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1) Return End Try 'active assembly s Dim oMainAsm As AssemblyDocument = ThisDoc.Document Dim oAsmDef As AssemblyComponentDefinition = oMainAsm.ComponentDefinition
Dim index As Integer For i = 1 To oAsmDef.Occurrences.Count If oAsmDef.Occurrences.Item(i).Name = oOccurrence.Name Then index = i Exit For End If Next ' get the occurrence by its position in the occurrences collection Dim oOcc As ComponentOccurrence = oAsmDef.Occurrences.Item(index) MessageBox.Show("You selected: " & oOcc.Name)
Best regards,
Tobias
Can't find what you're looking for? Ask the community or share your knowledge.