Getting an occurrence without traversing

Getting an occurrence without traversing

NachoShaw
Advisor Advisor
329 Views
2 Replies
Message 1 of 3

Getting an occurrence without traversing

NachoShaw
Advisor
Advisor

Hey

 

im doing a lot of assembly work and more than 50% of the operation time is consumed by traversing the assembly for documents. Is there a good to get an occurrence or document definition without needing to to the loop if i had say, a filepath, display name or partial name?

 

I have tried the ComponentEnumerator but that seems to the take the same amount of time as a loop. I thought i could use ItemByName but that requires the Application documents not the assembly document and the file needs to be open.

 

I was hoping that the enumerator would be more of a lookup and be faster unless im using it wrong..

 

Dim Doc as string = "C;\MyFile.ipt"
Dim oAssyDoc As AssemblyDocument = Form1.G._Invapp.ActiveDocument
Dim oCompOccEnum As ComponentOccurrencesEnumerator = oAssyDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(oDoc.ComponentDefinition)
For Each oCompOcc As ComponentOccurrence In oCompOccEnum
   If oCompOcc.Definition.Document.FullFileName = Doc Then
      oC2 = oCompOcc
      Exit For
    End If
Next

 

Looking for the most efficient way to enumerate an assembly to find a component without it needing to be open. 

 

 

thanks

 

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
330 Views
2 Replies
Replies (2)
Message 2 of 3

J-Camper
Advisor
Advisor

I believe "ItemByName" Property uses DisplayName and can be accessed from AssemblyDocument:

Dim aCD As AssemblyComponentDefinition

aCD.Occurrences.ItemByName("Display Name")

 

I'm not sure what you mean by: "[...] and the file needs to be open" You have the Assembly as ActiveDocument in your code, so it is open right?

 

Testing Sample:

Dim aCD As AssemblyComponentDefinition = ThisApplication.ActiveDocument.ComponentDefinition

Dim selecting As ComponentOccurrence = aCD.Occurrences.ItemByName("select") 'Display Name

Dim selectThis As HighlightSet = ThisApplication.ActiveDocument.CreateHighlightSet
			
selectThis.AddItem(selecting)

MessageBox.Show("Look At Highlighted Component", "Selection")

 

AllReferencedOccurrences Is going to give you a group of occurrences all using the same document [multiple instances of a document]

 

Let me know if this isn't working for you.

0 Likes
Message 3 of 3

NachoShaw
Advisor
Advisor

Hi

 

Thanks for the reply. I read that ItemByName required the file you wanted to find to be already open in order to find it. I could see why when the Component collection was the application collection..

 

i must have missed this 🙂

 

 

much appreciated

 

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes