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
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,