ID of occurrence in a pattern

ID of occurrence in a pattern

DanfysikClaus
Participant Participant
216 Views
3 Replies
Message 1 of 4

ID of occurrence in a pattern

DanfysikClaus
Participant
Participant

Hi Forum,

Is there a way to identify an occurence in a pattern by its ID ?

This feature is important as I like to automate the selection with iLogic e.g. ID8

DanfysikClaus_1-1741082477957.png

 

 

0 Likes
217 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor

Hi @DanfysikClaus.  Yes, sort of.  They do have an 'Index', which is a ReadOnly property with an Integer type value.  But I am not sure if this 'Index' is predictable or how the system works that initially assigns those indexes.  So, I am not sure if its index would be exactly the same as the number of 'occurrences' seen in the model browser tree, if counting down from the first one you see.  I will post some links to some online help documentation pages in the Inventor API area below, to help guide you to where you can find that information.

PartDocument.ComponentDefinition 

PartComponentDefinition.Features 

PartFeatures.RectangularPatternFeatures 

RectangularPatternFeatures 

RectangularPatternFeature.PatternElements 

FeaturePatternElements 

FeaturePatternElement.Index 

There is also the 'Attributes' angle (FeaturePatternElement.AttributeSets), if getting really serious about the overall automation strategy, but that would require some preparations ahead of time, because there is no user interface access to them, other than a couple possible add-ins that are available in the Autodesk App Store.  So, assigning attributes to them, for identification purposes later, would most likely need to be done with a custom code-based resource.  It's not necessarily that difficult to do, but would certainly add a whole extra level of complication to the overall process, if going that route.

 

Since your initial image was of a pattern in a part, that is what I am referring to with the links above, but patterns in an assembly are a completely different area, with a completely different code path for accessing them, and different systems being used for controlling them.  That code path would likely start from the AssemblyComponentDefinition.OccurrencePatterns property, and go deeper from there, with the inner-most objects being the OccurrencePatternElement type objects, which also have an Index property.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 4

DanfysikClaus
Participant
Participant

Thanks alot,

I try to proceed with the links and try to get it working

Later, I might post the request to the Idea bank !

Claus

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

Here is some example iLogic rule code to help you along.  It first makes sure that it is working with a part, not an assembly or drawing.  Then gets the rectangular pattern features collection.  Then tries to find a specific one by its name (as seen in the model browser tree).  If it can not be found, it will let you know, then exit the rule.  It then looks for a specific element directly within that patter, at a specific index (using the posted image as an example, so 8 in this case).  Again, if it can not be found, it will let you know, then exit the rule.  If found, it will 'toggle' its suppressed status.  So, if it was suppressed before, it will be unsuppressed, and if unsuppressed, it will suppress it.  Then it updates the part, if that worked, and it gets that far.

Sub Main
	Dim oPDoc As PartDocument = TryCast(ThisDoc.Document, Inventor.PartDocument)
	If oPDoc Is Nothing Then Return
	Dim oRPFs As RectangularPatternFeatures = oPDoc.ComponentDefinition.Features.RectangularPatternFeatures
	Dim oMyRPF As RectangularPatternFeature = Nothing
	For Each oRPF As RectangularPatternFeature In oRPFs
		If oRPF.Name = "Rectangular Pattern1" Then
			oMyRPF = oRPF
			Exit For 'exit iteration once found
		End If
	Next
	If oMyRPF Is Nothing Then
		MsgBox("Pattern Not Found!", vbCritical, "iLogic")
		Return
	End If
	Dim oMyFPE As FeaturePatternElement = Nothing
	For Each oFPE As FeaturePatternElement In oMyRPF.PatternElements
		If oFPE.Index = 8 Then
			oMyFPE = oFPE
			Exit For 'exit iteration once found
		End If
	Next
	If oMyFPE Is Nothing Then
		MsgBox("Pattern Element At That Index Not Found!", vbCritical, "iLogic")
		Return
	End If
	'Toggle its suppressed status
	oMyFPE.Suppressed = Not oMyFPE.Suppressed
	oPDoc.Update()
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