Do you want the code to only effect Element1, and not Element2?
Tip 1:
In is generally reccomended that you rename your browser nodes to help uniquely identify and clarify what each item is. This will also help out on the programming side.
Tip 2:
It is also good practice, when searching through assembly ComponentOccurrences by their Names, to loop through them checking if it's {Name.Contains("pattern name")}, so you don't have to worry about the colon (:) and Integer at the end of the Name.
When I opened your files, it couldn't find certain external rules, but within the one local rule in the assembly file, I crafted the following rule that seems to be working the way you want it to.
It was definately a pain, though, because of how deep you have to dig, and how many checks you have to put in place to help eliminate possible errors.
Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oRectOccPatt As RectangularOccurrencePattern
Dim o1stLevelElement As OccurrencePatternElement
Dim o1stLevelOcc As ComponentOccurrence
Dim o2ndLevelPatt As RectangularOccurrencePattern
Dim o2ndLevelOcc As ComponentOccurrence
For Each oRectOccPatt In oADef.OccurrencePatterns
If oRectOccPatt.Name.Contains("Component Pattern 7") Then
For Each o1stLevelElement In oRectOccPatt.OccurrencePatternElements
For Each o1stLevelOcc In o1stLevelElement.Occurrences
If o1stLevelOcc.IsPatternElement Then
If o1stLevelOcc.PatternElement.Parent.Type = ObjectTypeEnum.kRectangularOccurrencePatternObject Then
o2ndLevelPatt = o1stLevelOcc.PatternElement.Parent
If o2ndLevelPatt.Name.Contains("Component Pattern 2") Then
On Error Resume Next
If Top_braces_width = True Then
For Each o2ndLevelOcc In o2ndLevelPatt.ParentComponents
If o2ndLevelOcc.Suppressed = True Then
o2ndLevelOcc.Unsuppress
End If
Next
Else
For Each o2ndLevelOcc In o2ndLevelPatt.ParentComponents
If o2ndLevelOcc.Suppressed = False Then
o2ndLevelOcc.Suppress
End If
Next
End If
ElseIf o2ndLevelPatt.Name.Contains("Component Pattern 3") Then
On Error Resume Next
If Bottom_braces_width = True Then
For Each o2ndLevelOcc In o2ndLevelPatt.ParentComponents
If o2ndLevelOcc.Suppressed = True Then
o2ndLevelOcc.Unsuppress
End If
Next
Else
For Each o2ndLevelOcc In o2ndLevelPatt.ParentComponents
If o2ndLevelOcc.Suppressed = False Then
o2ndLevelOcc.Suppress
End If
Next
End If
End If
End If
End If
Next
Next
End If
Next
I hope this helps.
If this solves your problem, or answers your questions, please click 'Accept As Solution".
Or, if this helps you reach your goal, please click 'LIKES" 👍.
Also, if you're interested, here are a few of the 'Ideas' I'd like to get implemented.
If you agree with any of them, please vote for them.
- Add more capabilities to the 'Customize' dialog box (exe. Add Tab & Add Panel) Click Here
- MessageBox, InputBox, and InputListBox Size & Format Options Click Here
- Constrain & Dimension Images In Assembly Sketches & Drawing Sketches (TitleBlocks & SketchedSymbols) Click Here
- Save Section View Status In DesignViewRepresentation (So It Can Be Used In The Drawing) Click Here
- Add SolidBodies Folder In iLogic Rule Editor Model Tab Click Here
- Convert All Views To Raster Before Autosave Stores To 'OldVersions' Folder Click Here
- SetDesignViewRepresentation - Fix limitations for DrawingView of a Part Click Here
- Create DocumentSubTypeEnum Click Here
Inventor 2020 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum
Wesley Crihfield

(Not an Autodesk Employee)