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 all occurrences (ipts, iams) from all levels in top assembly

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
ReneRepina
362 Views, 4 Replies

Get all occurrences (ipts, iams) from all levels in top assembly

Hello.

 

Is there any available code to get all occurrences (ipts, iams) from all levels in top assembly?

 

Property "AllLeafOccurrences" exist, but it gets only all parts (ipts), without assemblies (iams).

 

Any ideas?

 

 

Best regards,

Rene Repina

Labels (8)
4 REPLIES 4
Message 2 of 5
A.Acheson
in reply to: ReneRepina

See the first rule in this article traverse assembly.

It is written in VBA so it's needs to be converted. Remove the word "Set", add sub Main to drive the sub routine and change debug.print to logger.info. 

If you have any issues converting then post the problem area with the error messages. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 5
Frederick_Law
in reply to: ReneRepina

Yes, a recursive loop.

VBA, this is used to set all parts in assembly to same Material.

Private Sub SetAllMat(ByVal oSubDoc As Inventor.Document, oMatName As String)
    
    Dim oCompDoc As Inventor.PartDocument
    Dim oRefDoc As Inventor.Document
    For Each oRefDoc In oSubDoc.ReferencedDocuments
      If oRefDoc.ReferencedDocuments.Count > 0 Then
        Call SetAllMat(oRefDoc, oMatName)
      End If
      If oRefDoc.IsModifiable Then
        If oRefDoc.DocumentType = kPartDocumentObject Then
          Set oCompDoc = ThisApplication.Documents.Open(oRefDoc.FullFileName)
          SetPartMaterial oCompDoc, oMatName
          oCompDoc.Close
        End If
      End If
    Next
End Sub

  

Message 4 of 5
WCrihfield
in reply to: ReneRepina

Hi @ReneRepina.  Just one small additional tip...  I am not sure what you are planning on doing with all of those components once you have access to them, but there is one other detail about 'how' you get them that might be important to the process.  Once you have access to a true top level component (ComponentOccurrence), how you access its child components can sometimes be important, depending on your plans.  If you use something like the following:

ComponentOccurrence.Definition.Occurrences

...then you are getting them from within its ComponentDefinition, which is like opening the assembly document that it references, then accessing its top level components, so they are all in the 'context' of that component's referenced AssemblyComponentDefinition.  However, when you use the ComponentOccurrence.SubOccurrences to access them, they are all still essentially in the same 'context' as the component itself (top level of the assembly).  By context I mean the 3D coordinate system space of a specific ComponentDefinition.  If you are working with measurements, constraints, or any other inter component geometry relationships, then context is very important because both objects need to be in the same context for these types of actions to work.  Also, iterating components (instead of iterating referenced documents) is the only way to control inter component context needed for those types of tasks.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 5
ReneRepina
in reply to: ReneRepina

Hello all.

 

Sorry for the late reply.

 

Firstly, thank you all for your suggestions.

 

@A.Acheson 

I used a little bit simpler approach. I will explain it below.

 

@Frederick_Law 

The thing is, I also need assemblies in the collection, not just parts.

 

@WCrihfield 

I am coloring them with specific colors, depended on which type of the custom property it has. It can be either IPT or IAM, so that why I need the whole collection.

This was the biggest challenge, on how to get whole collection from the top assembly. The struggles I encountered was that I was not able to get occurrences from sub-assemblies or I did get the occurrences, but not the assemblies.

Thank you for the explanation. I did not exacly try this as you suggested. I used a different approach explained below.

Used approach:

I did it in 2 steps. 1st step was to get all referenced documents from the top assembly, so that all IPTs and IAMs are included. When I had this collection, I iterated through all of them and filtered the needed ones out and used them later in code.


Best regards,

Rene Repina

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

Post to forums  

Autodesk Design & Make Report