11-03-2020
07:10 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
11-03-2020
07:10 AM
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.