- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Assembly pattern and color ilogic
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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 = TrueOccurrencePattern Object has a Property "OccurrencePatternElements", which you can iterate through as OccurrencePatternElement Objects to find the Occurrences that make up each Element.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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 SubThe selection process can be modified, I just threw a list selection in there for now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.