Ilogic: Add element to existing pattern

Ilogic: Add element to existing pattern

duke
Enthusiast Enthusiast
702 Views
5 Replies
Message 1 of 6

Ilogic: Add element to existing pattern

duke
Enthusiast
Enthusiast

I have an existing pattern, and would like to use iLogic to add another element to the pattern. I know how to create a pattern and how to manipulate the the elements already in the pattern, but I can't seem to find a method that will allow me to add an element to the pattern. Where are the elements stored that make up a pattern? Can I add elements without having to delete the existing pattern?

0 Likes
Accepted solutions (1)
703 Views
5 Replies
Replies (5)
Message 2 of 6

A.Acheson
Mentor
Mentor

Is this a circular or rectangular pattern, occurrence or feature, part or assembly? Can you attach the code your using? 

 

Try working with the definition and affected occurrence collection, help page here

Syntax

CircularPatternFeatureDefinition.AffectedOccurrences() As ObjectCollection

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 6

duke
Enthusiast
Enthusiast

It is a rectangular pattern of an occurrence in an assembly.

 

Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

Dim compDef As AssemblyComponentDefinition
compDef = oDoc.ComponentDefinition

oComp = compDef.Occurrences.ItemByName("Curb Internal Channel:1")

Dim oPattern As OccurrencePattern
oPattern = compDef.OccurrencePatterns.Item("Component Pattern 5:1"

 This is my current code. The goal is to add oComp to the existing pattern. I am not finding any method that would allow me to do that though. 

0 Likes
Message 4 of 6

duke
Enthusiast
Enthusiast

I've improved my code to what I am posting below, and I cannot find any reason that it does not work as expected. Everything I have found from Autodesk says that this should effectively add a component to the existing pattern. The code does nothing though, and when I perform a count on the parentComponents collection it has the same number as before, without the additional component registering. Am I doing something wrong?

 

Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

Dim compDef As AssemblyComponentDefinition
compDef = oDoc.ComponentDefinition

Dim oComp As ComponentOccurrence
oComp = compDef.Occurrences.ItemByName("Curb Internal Channel:1")

Dim oPattern As OccurrencePattern
oPattern = compDef.OccurrencePatterns.Item("Component Pattern 5:1")

oPattern.ParentComponents.Add(oComp)
0 Likes
Message 5 of 6

WCrihfield
Mentor
Mentor
Accepted solution

Hi @duke.  Instead of trying to directly add a component to the current ObjectCollection, try getting the ObjectCollection from the 'oPattern.ParentComponents' to a variable, then adding the component to that ObjectCollection, then setting that ObjectCollection as the value of the oPattern.ParentComponents property.  When the ParentComponents property is Read/Write, that does not always mean that you can change something within its value, but it does usually mean that you can set a new value to it.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 6

duke
Enthusiast
Enthusiast
That worked! Thank you!
0 Likes