Hello guys,
I was searching for a way to "explode" patterns using an iLogic rule.
I did some researching and came across an old post by Brian Ekins from 2008.
He had written some code to "explode" component patterns for the API.
I tweaked it a bit and got it to work inside of iLogic. It really works!
It's also very simple. Just a brief description of what the code does.
We start at element #2, because element #1 is the patterning component.
We count the number of elements in the pattern, then make them independent.
Making them independent, suppresses them in the pattern AND copies them to the design tree.
Then we simply delete the pattern sending the patterning component (element #1) into the design tree as well.
This code is in it's basic form.
If you do not have the pattern that is named in the code, in your assembly, you will get an error.
Solved! Go to Solution.
Solved by LOONYLEN. Go to Solution.
D'oh!
Sorry about that, here it is.
Sub Main() ExplodePattern
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
Dim oPattern As OccurrencePattern
oPattern = oDoc.ComponentDefinition.OccurrencePatterns.Item("Component Pattern 1:1")
'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
oPattern.Delete
End Sub
It is a very simple code. Like I said though, You will need to add some things to it like "Check if there's a pattern, then run or don't run". You can experiment with the code and then post what you've learned back here for everyone to enjoy.
Thanks,
Len