Hi @mike.krudt. I would need to know your total intentions for this rule, so that when I assemble everything together, it will work the way you want, without potential problems.
Do you intend to only check one thing about each component, then depending on that one thing, turn Visibility of that component on or off?
Or do you intend to check several things about each component, then if all checks turn out a certain way, then decide to turn visibility on or off? If you want to check multiple things about each component, then those checks may need to be formatted a certain way to make it work better.
Do you want/need to do any thing else to these components, as a result of these checks, besides turning their visibility on or off?
If you let us know your overall goals in detail, then our proposed solutions might be more complete and useful to you.
I assembled the codes from above into one as you asked for here, just looping through every part type component in all levels of the assembly, checking the value of it's custom iProperty "type", then if it is "CNC machined", it will ensure Visibility is on. Then I also included the code to check the component's material, then also deal with it's visibility, but I left that part of the code commented out for now. Since I don't really know the full extent of your intentions or plan, I'm not sure what all may need to be checked or what you need done when specific values are found.
Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
For Each oLeafOcc As ComponentOccurrence In oADef.Occurrences.AllLeafOccurrences
If iProperties.Value(oLeafOcc.Name, "Custom", "type") = "CNC machined" Then
oLeafOcc.Visible = True
ElseIf iProperties.Value(oLeafOcc.Name, "Custom", "type") = "laser" Then
oLeafOcc.Visible = False
End If
'If iProperties.MaterialOfComponent(oLeafOcc.Name) = "Steel" Then
' oLeafOcc.Visible = False
'End If
Next
Also, keep in mind that if any of those parts don't already have that custom property set-up within them, this rule might throw an error, because it will be trying to check the value of a property that doesn't exist. This can be avoided with the use of error handling code, if needed.
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.
If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS
Wesley Crihfield

(Not an Autodesk Employee)