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: 

Setting visibility for parts in a subassembly

2 REPLIES 2
Reply
Message 1 of 3
dan_inv09
265 Views, 2 Replies

Setting visibility for parts in a subassembly

I think my problem is in one of these:

 

SyntaxEditor Code Snippet

'look at all of the components in the assembly
Dim oCompDef As Inventor.ComponentDefinition = openDoc.ComponentDefinition

'define the first level components collection
Dim oCompOcc As Inventor.ComponentOccurrence 

they're used in the bit of code that sets visibility for parts in an assembly but I need it to work on parts in a subassembly.

 

Is there a way to fix those so I can work with parts that are at least one level down?

 

 

 

 

 

2 REPLIES 2
Message 2 of 3
Owner2229
in reply to: dan_inv09

Hi, from what you've posted you'r code would continue like this, right? For the top level components:

 

' Look at all of the components in the assembly
Dim oCompDef As Inventor.ComponentDefinition = openDoc.ComponentDefinition

' Define the first level components collection
Dim oCompOcc As Inventor.ComponentOccurrence

For Each oCompOcc In oCompDef.Occurrences
    ' Toggle the top component's visibility
    oCompOcc.Visible = Not oCompOcc.Visible
    
' Skip if it isn't assembly If Not oCompOcc.DefinitionDocumentType.ToString = "kAssemblyDocumentObject" Then Continue For ' Here we can continue deeper: Dim oOcc As Inventor.ComponentOccurrence
For Each oOcc In oCompOcc.Definition.Occurrences ' Toggle the sub component's visibility oOcc.Visible = Not oOcc.Visible Next Next 

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 3 of 3
dan_inv09
in reply to: Owner2229

Sorry, I ran out of time and had to brute force it.

 

When this job is done and I have some time I will play around with a dummy assembly (or the next job) and see how it works.

 

Thanks for the effort.

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

Post to forums  

Autodesk Design & Make Report