Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Switch off part visibility in sub-assembly

sheetal.b
Participant

Switch off part visibility in sub-assembly

sheetal.b
Participant
Participant

I have an assembly 'A' with a lot of sub-assemblies.

One of these is 'Subassembly B'. The quantity of 'Subassembly B' in 'Assembly A' is variable.

 

In 'Subassembly B', I need to switch on/off the visibility of 'Part 1' according to user input.

 

I have already made a form for the user input.

Part 1 required?: Yes/no

 

How can I switch off visibility of all occurrences of 'Part 1'? 

0 Likes
Reply
Accepted solutions (1)
415 Views
2 Replies
Replies (2)

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @sheetal.b 

The trick to find all these occurrences is to use Occurrences.AllReferencedOccurrences in your main assembly.

All you need is a document-object for your 'Part 1'. Here's an example, assuming the subassembly occurrences are named 'Subassembly B:1', 'Subassembly B:2', 'Subassembly B:3' and so on. And the 'Part1'-occurrence in the subassembly is named 'Part1:1'.

 

Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oDef As AssemblyComponentDefinition = oAsm.ComponentDefinition
Dim subAsm As AssemblyDocument = oDef.Occurrences.ItemByName("Subassembly B:1").Definition.Document
Dim part1 As PartDocument = subAsm.ComponentDefinition.Occurrences.ItemByName("Part1:1").Definition.Document

For Each oOcc As ComponentOccurrence In oDef.Occurrences.AllReferencedOccurrences(part1)
	oOcc.Visible = False
Next

TomaszDąbrowski
Enthusiast
Enthusiast

Try this code

Dim oDoc As AssemblyDocument =  ThisDoc.Document
Dim subAssembly As AssemblyDocument

'here declare your names - subassembly and part to hide
Dim subAssemblyName As String = "Subassembly B"
Dim subPartName As String = "Part 1"
Dim hide As Boolean = True 'this must be connected with your form 
'maybe create a boolean parameter and put it in your form, 
'then you can replace this "true" with your parameter value

For Each subOcc As ComponentOccurrence In oDoc.ComponentDefinition.Occurrences
	If subOcc.Name.Contains(subAssemblyName) Then
		subAssembly = subOcc.Definition.Document
	Exit for
	End If
Next
If subAssembly Is Nothing Then Return

For Each oOcu As ComponentOccurrence In subAssembly.ComponentDefinition.Occurrences
		If oOcu.Name.Contains(subPartName) Then
			If hide=True Then
			oOcu.Visible = False
				Else
			oOcu.Visible = True
			End If
			Else
			oOcu.Visible = True
		End If
			
	Next

 

0 Likes