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: 

Turning off visibility for all levels of components in Assembly

1 REPLY 1
Reply
Message 1 of 2
djbrown
231 Views, 1 Reply

Turning off visibility for all levels of components in Assembly

I have an iLogic rule that will turn off the visibility of parts based on user input, but will only turn off the subassemblies/parts that are 1st level parts.  I would like to have the rule turn off all instances of a specified part within an assembly.  In other words, I need a way to modify the code shown below so it will recognize the instances of the components in the subassemblies as well.

 

 ' Define User input
uPrefix = InputBox("What is Prefix?","Prefix","n/a")
PreLen = Len(uPrefix)

' Define a variable to the open Assembly Components
Dim oAsmCompDef As AssemblyComponentDefinition

oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

'Iterate through all occurrences and turn off specified parts
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
   If (Left(oOccurrence.Name,PreLen) = uPrefix) Then
      Component.Visible(oOccurrence.Name) = False
   End If
Next

 Thanks,

 

Daniel

1 REPLY 1
Message 2 of 2
adam.nagy
in reply to: djbrown

HI Daniel,

 

If you are ony interested in parts, then you could simply replace in your code 

oAsmCompDef.Occurrences

with

oAsmCompDef.Occurrences.AllLeafOccurrences

Otherwise you could iterate through all the occurrences and suboccurrences using a recursive function like the TraverseAssemblySample() in this blog post: 

http://modthemachine.typepad.com/my_weblog/2009/03/accessing-assembly-components.html

 

Cheers,



Adam Nagy
Autodesk Platform Services

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

Post to forums  

Autodesk Design & Make Report