Hi @jaka73LU2 . The visibility and suppression functions work perfectly, but SelectSet throws an error when trying to select items in a subassembly.
Private Sub Main()
Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oColl As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Call GetAllPatterns(oDef.OccurrencePatterns, oColl)
Call GetAllOccs(oDef.Occurrences, oColl)
' If oColl Is Nothing Then Exit Sub
' Call oDoc.SelectSet.SelectMultiple(oColl)
' oDoc.Rebuild()
' oDoc.Update()
End Sub
Private Sub GetAllOccs(oOccs As ComponentOccurrences, ByRef oColl As ObjectCollection)
For Each oOcc As ComponentOccurrence In oOccs
If oOcc.Suppressed Then Continue For
If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
Dim oOccDef As AssemblyComponentDefinition = oOcc.Definition
Dim oOccDoc As AssemblyDocument = oOccDef.Document
If oOccDef.OccurrencePatterns.Count > 0 Then Call GetAllPatterns(oOccDef.OccurrencePatterns, oColl)
If oOcc.SubOccurrences Is Nothing Then Continue For
If oOcc.SubOccurrences.Count <> 0 Then
Call GetAllOccs(oOcc.SubOccurrences, oColl)
End If
End If
Next
End Sub
Private Function GetAllPatterns(oOccsPatt As OccurrencePatterns, ByRef oColl As ObjectCollection)
For Each oOccPatt As OccurrencePattern In oOccsPatt
' Work with visible
oOccPatt.Visible = False
MessageBox.Show(oOccPatt.Name & " - Visible", oOccPatt.Parent.Document.DisplayName)
oOccPatt.Visible = True
' Work with suppress
oOccPatt.Suppress(True)
MessageBox.Show(oOccPatt.Name & " - Suppress", oOccPatt.Parent.Document.DisplayName)
oOccPatt.Unsuppress()
'Select patterns
oColl.Add(oOccPatt)
Next
End Function
Also an example of working with the components of the opening subassembly:
Private Sub Main()
Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Call GetAllPatterns(oDef.OccurrencePatterns)
Call GetAllOccs(oDef.Occurrences)
End Sub
Private Sub GetAllOccs(oOccs As ComponentOccurrences)
For Each oOcc As ComponentOccurrence In oOccs
If oOcc.Suppressed Then Continue For
If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
Dim oOccDef As AssemblyComponentDefinition = oOcc.Definition
if oOccDef.OccurrencePatterns.Count > 0 then Call GetAllPatterns(oOccDef.OccurrencePatterns, oOcc)
If oOcc.SubOccurrences Is Nothing Then Continue For
If oOcc.SubOccurrences.Count <> 0 Then
Call GetAllOccs(oOcc.SubOccurrences)
End If
End If
Next
End Sub
Private Function GetAllPatterns(oOccsPatt As OccurrencePatterns, Optional oOcc As ComponentOccurrence = Nothing)
If oOcc IsNot Nothing Then oOcc.Edit()
For Each oOccPatt As OccurrencePattern In oOccsPatt
MessageBox.Show(oOccPatt.Name, oOccPatt.Parent.Document.DisplayName)
Next
If oOcc IsNot Nothing Then oOcc.ExitEdit(ExitTypeEnum.kExitToParent)
End Function