Remove part visibility in asm by custom property

Remove part visibility in asm by custom property

mike.krudt
Participant Participant
799 Views
8 Replies
Message 1 of 9

Remove part visibility in asm by custom property

mike.krudt
Participant
Participant
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?
0 Likes
800 Views
8 Replies
Replies (8)
Message 2 of 9

bhavik4244
Collaborator
Collaborator

@mike.krudt 

 

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
0 Likes
Message 3 of 9

mike.krudt
Participant
Participant

Thanks that worked! 🙂

 

And what if i want to hide all with the material "Steel"? 🙂

0 Likes
Message 4 of 9

mike.krudt
Participant
Participant

And what if i want to look down in sub assemblies? 

 

0 Likes
Message 5 of 9

bhavik4244
Collaborator
Collaborator

@mike.krudt 

 

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
0 Likes
Message 6 of 9

mike.krudt
Participant
Participant
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?

 

 

0 Likes
Message 7 of 9

WCrihfield
Mentor
Mentor

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

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 9

mike.krudt
Participant
Participant

@WCrihfield 

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" 🙂

 

 

0 Likes
Message 9 of 9

WCrihfield
Mentor
Mentor

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

EESignature

(Not an Autodesk Employee)