Hey all,
We have an interesting pattern design that requires an opposing direction with each pattern row. There's a couple of ways to solve this - but I'm looking at alternative methods, just to see the pros and cons of each and compare their usefulness, flexibility etc. Example pattern below;
What we have here is simply two components, facing different directions, constrained in position and then assembly Feature patterned via cut-outs in the sheet-metal trim. If there's no sheet-metal hole, there's no component, so that works well.
From the below picture, you can see both Component:1 and Component:2 within Element:1 of the Feature Pattern.
What I'm hoping to achieve is an iLogic snippet that returns the Element:1 count, which is "2" in this instance (or perhaps the final count depends on active/suppressed state of each component too)
It's easy enough to hardcode the count number (that's currently 2) - which is what I've done as my current workaround, but would be handy to run this component count check via code as there's a chance that the design will add more and more components that are then patterned.
Below is the iLogic code that controls the pattern Component state using a simple MOD of the Element count, note the number 2 that I'd like to swap-out with the dynamic component count of the first element (there's probably a more elegant way to do this too, but concatenation works well enough, made me smile being able to do this. 😁)
For instance = 1 To Parameter("Pattern Testing:1", "pattern_count") * 2
If instance Mod 2
Component.IsActive("Component:" + instance.ToString) = True
Else
Component.IsActive("Component:" + instance.ToString) = False
End If
Next
The result is if there's one row, then only odd parts are active to fill that one row.
If I can get some help figuring out how to count components in an element, then I believe this can be expanded in a few interesting ways using mod to figure out component suppression, and allow us to add more and more rows and quickly test out designs.
Solved! Go to Solution.
Solved by dalton98. Go to Solution.
This code works if there are the same number of components in each element. The code is a bit sloppy but it gets the job done. First it counts the total number of supressed parts in the assembly. Then it supresses "Component Pattern 1:1". Then it counts the number of supressed parts again. Then it divides the difference by the number of elements in "Component Pattern 1:1"
Dim oDoc As AssemblyDocument oDoc = ThisApplication.ActiveDocument i = 0 Dim occ As ComponentOccurrence For Each occ In oDoc.ComponentDefinition.Occurrences If occ.Suppressed = True i = i + 1 End If Next patternName = oDoc.ComponentDefinition.OccurrencePatterns.Item(1).Name Component.IsActive(patternName) = False j = 0 For Each occ In oDoc.ComponentDefinition.Occurrences If occ.Suppressed = True j = j + 1 End If Next Component.IsActive(patternName) = True componentOcc = j - i elementsCount = oDoc.ComponentDefinition.OccurrencePatterns.Item(1).OccurrencePatternElements.Count elementCount = componentOcc / elementsCount MessageBox.Show(elementCount)
Ok ignore the above post. This is the code you want.
Dim oDoc As AssemblyDocument oDoc = ThisApplication.ActiveDocument oDoc.ComponentDefinition.OccurrencePatterns(1).OccurrencePatternElements.Item("Element:1").Occurrences.Count
@dalton98- that did the trick, thank you! Although "OccurrencePatterns(1)" works (and you can increment to reference other patterns) I've also found it accepts the Pattern Name string too which is super cool! So for example, this also works;
Row_Count = oDoc.ComponentDefinition.OccurrencePatterns("Component Pattern 1:1").OccurrencePatternElements.Item("Element:1").Occurrences.Count
As I play with this technique however, things do get a little ugly if the assembly pattern is built out of a specific order, and then the patterned components lose the anticipated named number ordering that allows MOD tricks to work. But so long as the browser stacks the components within Patterns in an order, things tend to work.
If I find time, I might call the Pattern by the name, but see if I can call the component by the order (instead of the concatenated name I've formulated).
So instead of this calling the patterned component name like this;
Component.IsActive("Component:" + instance.ToString) = True
I should probably find a method to simply call;
"Pattern Name" -> Element #1 -> [Component #1, Component #2]
In that, I'm not manipulating the active component state based on the component name, but rather the components number within the element.
Can't find what you're looking for? Ask the community or share your knowledge.