Accessing the top level pattern name of an element that sits in a pattern within a pattern.

Accessing the top level pattern name of an element that sits in a pattern within a pattern.

duans5FLJC
Observer Observer
358 Views
2 Replies
Message 1 of 3

Accessing the top level pattern name of an element that sits in a pattern within a pattern.

duans5FLJC
Observer
Observer

Good day

 

I have iLogic code that loops through occurrences in my assembly and suppresses or un-suppresses them based on criteria. When I have an element within a pattern, I can access its parent pattern name and suppress it by using the following: 

Component.IsActive(oOcc.PatternElement.Parent.Name) = False

But when I have a pattern of a pattern, and that element sits within the 'lower level' pattern, I can't use the same code. This code tries to suppress the lower-level pattern that sits within the top-level pattern and fails. So I need to access that top-level pattern name while looping to suppress it. But only if it is a multi-level pattern.

 

I found this post: https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/pattern-of-a-pattern-using-ilogic/m-.... But then I have to hardcode the parent pattern name, which I can't do.

 

Does anyone know how to do that?

0 Likes
359 Views
2 Replies
Replies (2)
Message 2 of 3

dalton98
Collaborator
Collaborator

Hello. You would need to loop through each occurrence in  the pattern. Heres an example

Dim oADoc As AssemblyDocument = ThisDoc.Document

Dim oOccPat As OccurrencePattern

For Each oOccPat In oADoc.ComponentDefinition.OccurrencePatterns
	'top level patterns
Dim oOccPatEle As OccurrencePatternElement For Each oOccPatEle In oOccPat.OccurrencePatternElements 'pattern elements
Dim oOcc As ComponentOccurrence For Each oOcc In oOccPatEle.Occurrences 'element components 'If criteria met 'if parent pattern is not top level pattern If Not oOcc.PatternElement.Parent Is oOccPat oOcc.PatternElement.Parent.Suppress Else oOcc.Suppress End If 'End If Next Next Next
0 Likes
Message 3 of 3

WCrihfield
Mentor
Mentor

Hi @duans5FLJC.  Here is one way to suppress the top level component pattern of a picked component that belongs to a lower level component pattern.  It may not be 100% error free and effective in every scenario, but it works in most simple scenarios, and is fairly easy to look at and understand.

Sub Main
	oObj = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select a Component.")
	If IsNothing(oObj) OrElse (TypeOf oObj Is ComponentOccurrence = False) Then Exit Sub
	Dim oOcc As ComponentOccurrence = oObj
	If oOcc.IsPatternElement Then
		SuppressTopOccPattern(oOcc.PatternElement)
	End If
End Sub

Sub SuppressTopOccPattern(oInputPE As OccurrencePatternElement)
	Dim oOP As OccurrencePattern = oInputPE.Parent
	If oOP.IsPatternElement Then
		SuppressTopOccPattern(oOP.PatternElement)
	Else
		oOP.Suppress
	End If
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes