Uživatel L.Larsen z firmy Kingsbury, Inc. nám zaslal na posouzení jádro iLogic kódu pro rozbití pole komponent (viz Tip 8955).
Zde je námi rozšířená verze tohoto kódu - umožňuje vybrat pole ve stromu sestavy a rozložit všechny jeho součásti na nezávislé komponenty, a to v jediném kroku:
Sub Main()
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
Dim oPattern As OccurrencePattern
oPattern = GetPattern(oDoc)
If oPattern Is Nothing Then
MsgBox("Nothing for explode")
Return
End If
Dim t As Transaction = ThisApplication.TransactionManager.StartTransaction(ThisDoc.Document, "Pattern explode")
Try
'MAKE EACH ELEMENT INDEPENDENT, STARTING AT THE SECOND ELEMENT.
Dim i As Integer
'COUNT HOW MANY ELEMENTS ARE IN THE PATTERN, AFTER 2
For i = 2 To oPattern.OccurrencePatternElements.Count
'MAKE ALL ELEMENTS INDEPENDANT
oPattern.OccurrencePatternElements.Item(i).Independent = True
Next
'DELETE THE PATTERN, LEAVING ONLY THE INDEPENDENT COPIES AND THE ORIGINAL ELEMENT
oPattern.Delete()
t.End()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
t.Abort()
End Try
End Sub
Private Function GetPattern(ByVal oDoc As AssemblyDocument) As OccurrencePattern
Dim pattern As OccurrencePattern
'pattern = oDoc.ComponentDefinition.OccurrencePatterns.Item("Component Pattern 1:1")
pattern = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrencePatternFilter, "Select pattern for explode")
Return pattern
End Function