Ilogic suppressing every n-th element in pattern

Ilogic suppressing every n-th element in pattern

plesTTGPA
Explorer Explorer
360 Views
1 Reply
Message 1 of 2

Ilogic suppressing every n-th element in pattern

plesTTGPA
Explorer
Explorer

I'm trying to divide a pattern into sections by suppressing every n-th element , but when changing parameter "a" I get this error message.

plesTTGPA_0-1657099991767.png

 

The rule I use:

'Suppresing n-th element
'a - number of elements in pattern
'b - number of sections

Dim n As Integer = a/b

Dim oDef As AssemblyComponentDefinition = ThisApplication.ActiveDocument.ComponentDefinition

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

For Each oElement As OccurrencePatternElement In oPattern.OccurrencePatternElements 
		oElement.Suppressed = False
	If oElement.Index Mod n = 0 Then
		oElement.Suppressed = True
	End If
Next

 

0 Likes
Accepted solutions (1)
361 Views
1 Reply
Reply (1)
Message 2 of 2

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @plesTTGPA

 

I think the issue is that if you reduce the number of elements in the pattern ( example: from 41 to 40) the For each loop is still trying to suppress element 41, which doesn't exist.

 

Adding a document update before the loop should resolve this.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

'Suppresing n-th element
'a - number of elements in pattern
'b - number of sections

Dim n As Integer = a/b

Dim oDef As AssemblyComponentDefinition = ThisApplication.ActiveDocument.ComponentDefinition

Dim oPattern As OccurrencePattern = oDef.OccurrencePatterns.Item("Component Pattern 1:1")
InventorVb.DocumentUpdate()

For Each oElement As OccurrencePatternElement In oPattern.OccurrencePatternElements 
		oElement.Suppressed = False
	If oElement.Index Mod n = 0 Then
		oElement.Suppressed = True
	End If
Next

 

 

 

EESignature