Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get index of selected part or sub assembly

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Darrell.johnson
652 Views, 2 Replies

Get index of selected part or sub assembly

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?

2 REPLIES 2
Message 2 of 3

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

Tobias Orlow
Designated Support Specialist
Customer Success Organization
Linkedin: www.linkedin.com/in/tobiasorlow/
Message 3 of 3

It works perfectly, thank you very much!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report