- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Remove part visibility in asm by custom property
Hi,
I'm trying to create an Ilogic code that removes visibility on all parts in my assembly that have a custom property
example:
I have a custom property called "type" that allows me to select the method of manufacture on all parts. (CNC, welding, laser, etc.)
Now I want to hide all parts with "laser" in this property. But how will the Ilogic code look like?
Another one:
Can I do the same as above just by hiding all the parts with a meterial, for example steel?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi there,
For your "type" = "laser" below rule would work fine, you may replace the strings as per your need for further requirements.
Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition Dim oOccurrence As ComponentOccurrence For Each oOccurrence In oAsmCompDef.Occurrences If iProperties.Value(oOccurrence.Name, "Custom", "type") = "laser" oOccurrence.Visible = False Else End If Next
Bhavik Suthar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thanks that worked! ![]()
And what if i want to hide all with the material "Steel"? ![]()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
you can try this one for Material,
Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition Dim oOccurrence As ComponentOccurrence For Each oOccurrence In oAsmCompDef.Occurrences If iProperties.MaterialOfComponent(oOccurrence.Name) = "Steel" oOccurrence.Visible = False Else End If Next
To looping thru all occurance, it's bit gerneric but you can modify it for your need,
Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument Dim oAsmDef As AssemblyComponentDefinition oAsmDef = oAsmDoc.ComponentDefinition Dim oLeafOccs As ComponentOccurrencesEnumerator oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences Dim oOcc As ComponentOccurrence For Each oOcc In oLeafOccs 'add previous rules Next
Bhavik Suthar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm not strong at Ilogic, so maybe you can help put these together.
I have this now:Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition Dim oOccurrence As ComponentOccurrence For Each oOccurrence In oAsmCompDef.Occurrences If iProperties.Value(oOccurrence.Name, "Custom", "Type") = "CNC machined" oOccurrence.Visible = True Else End If
Now it needs to look through all the Sub assemblies
with this code:
Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument Dim oAsmDef As AssemblyComponentDefinition oAsmDef = oAsmDoc.ComponentDefinition Dim oLeafOccs As ComponentOccurrencesEnumerator oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences Dim oOcc As ComponentOccurrence For Each oOcc In oLeafOccs 'add previous rules Next
What will the whole code look like?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The code did exacly what i want ![]()
The intension is to create view rep. on my assembly.
I have a very big assembly with a lot of different parts. In this assembly i want to create different view rep, that i can use in my idw.
Therefor i needed to turn off visibility of some parts.
Side quistion:
Is it possible to do this on parts that contains somthing in their part number?
For example do I have a lot of washers, bolts, nuts etc. that I also want to hide.
They do not have any custom prop that I can sort by, but they all contain "DIN 933" in their part number. Can i turn of visibility of all parts containing "DIN 933" ![]()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
OK. I understand better now.
Dealing with representations within an assembly, can get tricky. Especially if trying to handle it all by code and trying to maintain the 'Associative' setting of component view representations at deeper levels. Keep in mind that if any sub-assemblies are associatively set to a certain view representation, it might not like it when this code attempts to turn off visibility of a component within that sub-assembly. You may need to set sub-assemblies to certain view representations too, in order to achieve your goals. Just something to think about.
Yes, you can check the component's Part Number for that text. Here is an updated rule that retrieves the Part Number from each component. Then checks to make sure it isn't blank/empty, then checks to see if it contains the specified data. If it passes both checks it will turn visibility of that component off.
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
Dim oPN As String = iProperties.Value(oLeafOcc.Name, "Project", "Part Number")
If String.IsNullOrEmpty(oPN) = False AndAlso oPN.Contains("DIN 933") Then
oLeafOcc.Visible = False
End If
Next
Wesley Crihfield
(Not an Autodesk Employee)