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
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
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
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
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!
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
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
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
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
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!
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
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
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.
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.