iLogic Rule - View Representations - Toggling Component Visibility Within Assembly, Based on Custom iProperty Value

iLogic Rule - View Representations - Toggling Component Visibility Within Assembly, Based on Custom iProperty Value

Cadderman
Enthusiast Enthusiast
285 Views
1 Reply
Message 1 of 2

iLogic Rule - View Representations - Toggling Component Visibility Within Assembly, Based on Custom iProperty Value

Cadderman
Enthusiast
Enthusiast

Hi All,

 

I have a fabrication template which contains patterns that update to suit overall fabrication width, length and height.  As quantities of components vary and this template will be copied and given new names, I need a good iLogic code that can keep the view reps right.

 

A typical fabrication will contain four view representations, such as:

 

Category 1 - Primary

Category 2 - Secondary

Category 3 - Tertiary 

Category 4 - Cosmetic

 

I have given all parts within the assembly a custom iproperty, so they can be identified.

 

I would like a code that can be operated from assembly level.  This code would ensure the following:

  • When view representation "Category 1" is activated, only items with Custom iproperty "Category" value = 1
  • When view representation "Category 2" is activated, only items with Custom iproperty "Category" value = 1 and 2
  • When view representation "Category 3" is activated, only items with Custom iproperty "Category" value = 1 and 2 and 3
  • When view representation "Category 4" is activated, only items with Custom iproperty "Category" value = 1 and 2 and 3 and 4

Is this possible?

 

0 Likes
286 Views
1 Reply
Reply (1)
Message 2 of 2

WCrihfield
Mentor
Mentor

I am assuming we are just talking about top level components here, because we are dealing with main assembly view rep and simple component visibility.  I also assume that I do not need to filter by document type, so every top level component, whether it be a part or sub assembly, will have that custom iProperty.  I also assume that the value of that custom property will always have a value, and it will be in Integer form, not String (quoted number).  Also, I don't know if we are dealing with ModelStates (set to something other than 'Master')...if so, the iProperty snippet might not work.

I think that this may work for you. 

Sub Main
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
		MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "iLogic")
		Exit Sub
	End If
	Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
	oADef = oADoc.ComponentDefinition
	oVRep = oADef.RepresentationsManager.ActiveDesignViewRepresentation
	oOccs = oADef.Occurrences
	Dim oValues As New List(Of Integer)
	Select Case oVRep.Name
	Case "Category 1"
		oValues.Add(1)
		ToggleOccVis(oOccs, oValues)
	Case "Category 2"
		oValues.AddRange({1,2})
		ToggleOccVis(oOccs, oValues)
	Case "Category 3"
		oValues.AddRange({1,2,3})
		ToggleOccVis(oOccs, oValues)
	Case "Category 4"
		oValues.AddRange({1,2,3,4})
		ToggleOccVis(oOccs, oValues)
	End Select
End Sub

Sub ToggleOccVis(oComps As ComponentOccurrences, oVals As List(Of Integer))
	For Each oComp As ComponentOccurrence In oComps
		oCat = iProperties.Value(oComp.Name, "Custom", "Category")
		Dim oMatch As Boolean = False
		For Each oVal In oVals
			If oCat = oVal Then
				oMatch = True
				If Not oComp.Visible Then oComp.Visible = True
			End If
		Next
		If Not oMatch Then
			If oComp.Visible Then oComp.Visible = False
		End If
	Next
End Sub

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