Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Suppress Part Pattern Element from iLogic Rule within Assembly

2 REPLIES 2
Reply
Message 1 of 3
KarlH_
205 Views, 2 Replies

Suppress Part Pattern Element from iLogic Rule within Assembly

KarlH_
Participant
Participant

Hey all,

 

I have written a couple of iLogic rules that execute within a Part, that can suppress various elements within a parts Pattern Feature.

Unsuppress all Pattern Elements;

 

Dim oPattern As RectangularPatternFeature 
oPattern = ThisDoc.Document.ComponentDefinition.Features.RectangularPatternFeatures.Item("Rectangular Pattern1")

Dim oElement As FeaturePatternElement
For Each oElement In oPattern.PatternElements
    If oElement.Index > 1 Then
        oElement.Suppressed = False
    End If
Next 
ThisDoc.Document.Update

 

KarlH__4-1674190415176.png

 

Suppress the last element;

 

Dim oPattern As RectangularPatternFeature 
oPattern = ThisDoc.Document.ComponentDefinition.Features.RectangularPatternFeatures.Item("Rectangular Pattern1")
 
Dim oElement As FeaturePatternElement
 
oElement = oPattern.PatternElements.Item(oPattern.PatternElements.Count)
oElement.Suppressed = True

ThisDoc.Document.update

 

 

KarlH__1-1674190305900.png

 

 

Suppress the desired element;

 

Dim oPattern As RectangularPatternFeature 
oPattern = ThisDoc.Document.ComponentDefinition.Features.RectangularPatternFeatures.Item("Rectangular Pattern1")

Dim oElement As FeaturePatternElement
Dim number As Integer = 5

For Each oElement In oPattern.PatternElements
    If oElement.Index = number Then
        oElement.Suppressed = True
    End If
Next 
ThisDoc.Document.Update

 

 

KarlH__2-1674190352630.png

 


And suppress the middle element(s) - pending odd or even qty.

 

Dim oPattern As RectangularPatternFeature 
oPattern = ThisDoc.Document.ComponentDefinition.Features.RectangularPatternFeatures.Item("Rectangular Pattern1")

Dim oElement As FeaturePatternElement

If oPattern.PatternElements.Count Mod 2 = 0 Then 'if the count is even
    For Each oElement In oPattern.PatternElements
        If oElement.Index = (oPattern.PatternElements.Count / 2) Or oElement.Index = (oPattern.PatternElements.Count / 2) + 1 Then
            oElement.Suppressed = True
        End If
    Next 
Else 'if the count is odd
    For Each oElement In oPattern.PatternElements
        If oElement.Index = (oPattern.PatternElements.Count + 1) / 2 Then
            oElement.Suppressed = True
        End If
    Next 
End If
ThisDoc.Document.Update

 

 

KarlH__3-1674190371590.png

 


These all work well from a testing point of view, but perhaps they could be refactored or simplified (and by all means, please feel free to comment/update).

But I'm now needing a hand in having these rules executing from a parent assembly of that part, that contains the parts Pattern Feature - I just can't seem to get the syntax right.

If worst comes to worst, I guess I can leave these rules nested within the Part, and call the parts iLogic rules via the assemblies main iLogic sub, but would prefer if I could alter these rules so that they're run from the parent assembly, keeping the part free from iLogic rules.

 

Appreciate any help, thanks!

0 Likes

Suppress Part Pattern Element from iLogic Rule within Assembly

Hey all,

 

I have written a couple of iLogic rules that execute within a Part, that can suppress various elements within a parts Pattern Feature.

Unsuppress all Pattern Elements;

 

Dim oPattern As RectangularPatternFeature 
oPattern = ThisDoc.Document.ComponentDefinition.Features.RectangularPatternFeatures.Item("Rectangular Pattern1")

Dim oElement As FeaturePatternElement
For Each oElement In oPattern.PatternElements
    If oElement.Index > 1 Then
        oElement.Suppressed = False
    End If
Next 
ThisDoc.Document.Update

 

KarlH__4-1674190415176.png

 

Suppress the last element;

 

Dim oPattern As RectangularPatternFeature 
oPattern = ThisDoc.Document.ComponentDefinition.Features.RectangularPatternFeatures.Item("Rectangular Pattern1")
 
Dim oElement As FeaturePatternElement
 
oElement = oPattern.PatternElements.Item(oPattern.PatternElements.Count)
oElement.Suppressed = True

ThisDoc.Document.update

 

 

KarlH__1-1674190305900.png

 

 

Suppress the desired element;

 

Dim oPattern As RectangularPatternFeature 
oPattern = ThisDoc.Document.ComponentDefinition.Features.RectangularPatternFeatures.Item("Rectangular Pattern1")

Dim oElement As FeaturePatternElement
Dim number As Integer = 5

For Each oElement In oPattern.PatternElements
    If oElement.Index = number Then
        oElement.Suppressed = True
    End If
Next 
ThisDoc.Document.Update

 

 

KarlH__2-1674190352630.png

 


And suppress the middle element(s) - pending odd or even qty.

 

Dim oPattern As RectangularPatternFeature 
oPattern = ThisDoc.Document.ComponentDefinition.Features.RectangularPatternFeatures.Item("Rectangular Pattern1")

Dim oElement As FeaturePatternElement

If oPattern.PatternElements.Count Mod 2 = 0 Then 'if the count is even
    For Each oElement In oPattern.PatternElements
        If oElement.Index = (oPattern.PatternElements.Count / 2) Or oElement.Index = (oPattern.PatternElements.Count / 2) + 1 Then
            oElement.Suppressed = True
        End If
    Next 
Else 'if the count is odd
    For Each oElement In oPattern.PatternElements
        If oElement.Index = (oPattern.PatternElements.Count + 1) / 2 Then
            oElement.Suppressed = True
        End If
    Next 
End If
ThisDoc.Document.Update

 

 

KarlH__3-1674190371590.png

 


These all work well from a testing point of view, but perhaps they could be refactored or simplified (and by all means, please feel free to comment/update).

But I'm now needing a hand in having these rules executing from a parent assembly of that part, that contains the parts Pattern Feature - I just can't seem to get the syntax right.

If worst comes to worst, I guess I can leave these rules nested within the Part, and call the parts iLogic rules via the assemblies main iLogic sub, but would prefer if I could alter these rules so that they're run from the parent assembly, keeping the part free from iLogic rules.

 

Appreciate any help, thanks!

Labels (2)
2 REPLIES 2
Message 2 of 3
Cadkunde.nl
in reply to: KarlH_

Cadkunde.nl
Collaborator
Collaborator

Nothing to mention on your code, seems fine.

 

To go through parts in an assembly, please look here:

https://modthemachine.typepad.com/my_weblog/2009/03/accessing-assembly-components.html

 

Maybe you need to activate the document before you change pattern.

You can do that with:

 

Dim occdoc As PartDocument = oOcc.Definition.document

occdoc.activate

 

When you do that, you need to change thisdoc.document to occdoc in your code

 

If you know the exact name of the component:

Dim oDoc As AssemblyDocument = ThisDoc.Document
Dim oOccs As Inventor.ComponentOccurrences = oDoc.ComponentDefinition.Occurrences
Dim oPrtDoc As PartDocument = oOccs.ItemByName("bla").Definition.Document

 

0 Likes

Nothing to mention on your code, seems fine.

 

To go through parts in an assembly, please look here:

https://modthemachine.typepad.com/my_weblog/2009/03/accessing-assembly-components.html

 

Maybe you need to activate the document before you change pattern.

You can do that with:

 

Dim occdoc As PartDocument = oOcc.Definition.document

occdoc.activate

 

When you do that, you need to change thisdoc.document to occdoc in your code

 

If you know the exact name of the component:

Dim oDoc As AssemblyDocument = ThisDoc.Document
Dim oOccs As Inventor.ComponentOccurrences = oDoc.ComponentDefinition.Occurrences
Dim oPrtDoc As PartDocument = oOccs.ItemByName("bla").Definition.Document

 

Message 3 of 3
wfajber
in reply to: Cadkunde.nl

wfajber
Contributor
Contributor

And just a reminder that this type of thing breaks if you are ‘Load Express’ on your assembly. It works fine but if the your assembly file is express loaded, the definition is not yet fully loaded, and thus not editable.

 

someone else had a similar issue their code in a large assembly, which should have otherwise worked.

 

0 Likes

And just a reminder that this type of thing breaks if you are ‘Load Express’ on your assembly. It works fine but if the your assembly file is express loaded, the definition is not yet fully loaded, and thus not editable.

 

someone else had a similar issue their code in a large assembly, which should have otherwise worked.

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report