Assembly pattern and color ilogic

Assembly pattern and color ilogic

blandb
Mentor Mentor
559 Views
4 Replies
Message 1 of 5

Assembly pattern and color ilogic

blandb
Mentor
Mentor

I am blanking here, If I have a component pattern in an assembly, how do I select the pattern and change the color with Ilogic.. I can only seem to change per instance name. I cant seem to find how to select the entire pattern and set all occurrences appearances at once. Also I am blanking on how to dive down to the part and set the color at the part level if I dont have a color rule to fire at the part level.

Autodesk Certified Professional
0 Likes
560 Views
4 Replies
Replies (4)
Message 2 of 5

J-Camper
Advisor
Advisor

This is how you can get an OccurrencePattern Object From a selected ComponentOccurrence:

Dim OccPat As OccurrencePattern = Occ.PatternElement.Parent
'Where Occ is a ComponentOccurrence and Occ.IsPatternElement = True

OccurrencePattern Object  has a Property "OccurrencePatternElements", which you can iterate through as OccurrencePatternElement Objects to find the Occurrences that make up each Element.

 

0 Likes
Message 3 of 5

blandb
Mentor
Mentor

Can you share an example of how to properly use that in a select case statement?

 

Select Case PAINT

     Case "BLACK"

     Component.Color("PICKET") = "Black"

     Case "BLUE"

     Component.Color("PICKET") = "Blue"

End Select

 

Thanks for your assistance!

Autodesk Certified Professional
0 Likes
Message 4 of 5

J-Camper
Advisor
Advisor

You should be able to set up your color selection in the Subroutine I have set up [with top level assembly and a single Occurrence].  I don't change the color of Occurrences with iLogic, so I'm not sure of the best way to set that portion up.  Here is a bit of code I threw together:

Sub Main
'External Rule Lockout
If ThisApplication.ActiveDocumentType <> kAssemblyDocumentObject Then MessageBox.Show("This rule is designed to only work in assembly documents.", "Wrong Document Type") : Exit Sub
'User Selection Setup, can be done other ways
Dim ocList As New List(Of String)
For Each oc As ComponentOccurrence In ThisApplication.ActiveDocument.ComponentDefinition.Occurrences
	If oc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then ocList.Add(oc.Name)
Next
Dim Selection As String = InputListBox("", ocList, ocList.Item(0), Title := "Item to Remove", ListName := "Sub Assemblies")
If IsNothing(Selection) Then Exit Sub 'No selection made
'After Occurrence is selected. "Selection" string can be manually set or set by a list and some logic to choose.
Dim selOcc As ComponentOccurrence = ThisApplication.ActiveDocument.ComponentDefinition.Occurrences.ItemByName(Selection)
'Verify selected occurrence is part of a pattern
If selOcc.IsPatternElement
	Dim Col As ObjectCollection = FindParticipants(selOcc)
	For Each oOcc As ComponentOccurrence In Col
		Call ColorSetting(ThisApplication.ActiveDocument, oOcc)
	Next
Else
	If MessageBox.Show("The Selected Occurrence: " & selOcc.Name & "  is not part of a Pattern.  Would you like to Set Color for this Occurrence Individually?", "Single Occurrence", MessageBoxButtons.YesNo) = vbYes Then Call ColorSetting(ThisApplication.ActiveDocument, selOcc)
End If

End Sub

Function FindParticipants(Oc As ComponentOccurrence) As ObjectCollection
	Dim Result As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
	Dim level1 As OccurrencePattern = Oc.PatternElement.Parent
LoopHere :
	For Each Element In level1.OccurrencePatternElements
		For Each Occ In Element.Occurrences
			Result.Add(Occ)
		Next
	Next
	'Dig through further patterns if initial pattern is an element
	If level1.IsPatternElement
		level1 = level1.PatternElement.Parent
		GoTo LoopHere
	End If
	Return Result
End Function

Sub ColorSetting(parent As AssemblyDocument, Oc As ComponentOccurrence)
	
	MessageBox.Show(Oc.Name, "Testing")
	
	'Setup your case selection here
	
End Sub

The selection process can be modified, I just threw a list selection in there for now.

0 Likes
Message 5 of 5

blandb
Mentor
Mentor

Way more involved than I thought it would be. I usually just change the material of components and they already have appearances associated. I appreciate your help, we have went a different path. Sorry for you wasting your time on this.

Autodesk Certified Professional
0 Likes