Using patterns and iLogix

Using patterns and iLogix

Anonymous
Not applicable
437 Views
3 Replies
Message 1 of 4

Using patterns and iLogix

Anonymous
Not applicable

Hi,

 

Is it possible to add a part to a pattern or delete on from a pattern based on a rule?

 

Number of parts = 5

part 1

part 2

part 3

part 4

part 5

are in pattern

 

Number of parts = 4

part 1

part 2

part 3

part 4

are in pattern part 5 is no longer available in the pattern.

 

any ideas? i'm not seeing it.. could be simple but via iLogic i van only make part 5 in the first component invisible..

 

 

0 Likes
Accepted solutions (1)
438 Views
3 Replies
Replies (3)
Message 2 of 4

rjay75
Collaborator
Collaborator
Accepted solution

To add remove elements in a pattern by name do this.

 

To remove a named element from a pattern

Dim asmDef = ThisDoc.Document.ComponentDefinition
Dim compPattern As OccurrencePattern
Dim compObj As ComponentOccurrence

compObj = asmDef.Occurrences.ItemByName("ElementName")
compPattern = asmDef.OccurrencePatterns("PatternName")

If Not ((compObj Is Nothing) Or (compPattern Is Nothing)) Then
    Dim newCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection()
    For Each obj As Object In compPattern.ParentComponents
        If Not obj Is compObj Then newCol.Add(obj)
    Next
    newCol.Add(compObj)
    compPattern.ParentComponents = newCol
End If

 

To add a named element back to a pattern

Dim asmDef = ThisDoc.Document.ComponentDefinition
Dim compPattern As OccurrencePattern
Dim compObj As ComponentOccurrence

compObj = asmDef.Occurrences.ItemByName("ElementName")
compPattern = asmDef.OccurrencePatterns("PatternName")

If Not ((compObj Is Nothing) Or (compPattern Is Nothing)) Then
    Dim newCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection()
Dim inPattern As Boolean = False For Each obj As Object In compPattern.ParentComponents If obj Is compObj Then
inPattern = True
Exit For
Else
newCol.Add(obj)
End If Next
If Not inPattern Then newCol.Add(compObj) compPattern.ParentComponents = newCol
End If End If

 

0 Likes
Message 3 of 4

Anonymous
Not applicable

Thank you for the quick reply rjay75, but i have a problem with the code as you supplied..

I inserted it in a rule & tried it out but nothing happens when i run the rule. What is wrong?

I attached a screenshot with my browser & rule.

 

Dim asmDef = ThisDoc.Document.ComponentDefinition
Dim compPattern As OccurrencePattern
Dim compObj As ComponentOccurrence

compObj = asmDef.Occurrences.ItemByName("Rib onder - Centrisch") 'Part name
compPattern = asmDef.OccurrencePatterns("Pattern - Ribben") 'Pattern name

If Not ((compObj Is Nothing) Or (compPattern Is Nothing)) Then
    Dim newCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection()
    For Each obj As Object In compPattern.ParentComponents
        If Not obj Is compObj Then newCol.Add(obj)
    Next
    newCol.Add(compObj)
    compPattern.ParentComponents = newCol
End If

 

 

temp.png

0 Likes
Message 4 of 4

rjay75
Collaborator
Collaborator

There's an extra line in there while I was testing the code.

 

Remove the line

 

newCol.Add(compObj)
0 Likes