Message 1 of 2
Deleting suppressed parts and patterns down multiple levels with ilogic

Not applicable
10-05-2018
01:05 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
So I've got two rules, the first will delete all suppressed patterns in the top level assembly. The second will delete all suppressed parts down all levels of the assembly (unless they are in a patern. I'm trying to combine the two so that all my supressed patterns in my sub assemblies are deleted too, but I am not having any success...
Can anyone help me out please. Here are my two rules below
delete pattern
Dim oAsmDoc As AssemblyDocument = ThisDoc.Document Dim oAsmDef As AssemblyComponentDefinition _ = oAsmDoc.ComponentDefinition RunAgain: oAsmDoc.Update Dim oOccs As ComponentOccurrences = oAsmDef.Occurrences For Each oOcc As ComponentOccurrence In oOccs If oOcc.Suppressed Then If oOcc.IsPatternElement Then Dim oPattern As RectangularOccurrencePattern _ = oOcc.PatternElement.Parent oPattern.Delete Goto RunAgain End If End If Next
delete supressed parts
SyntaxEditor Code Snippet
Sub Main() 'Check if suppressed parts should be removed. Stop if not yes If Delete_Suppressed_Parts = "No" Then Exit Sub 'ask user to confirm deletion Dim question As Object question = MessageBox.Show("Are you sure you want to delete suppressed parts? " & vbCrLf _ & "Once deleted, they cannot be undeleted.", "Warning",MessageBoxButtons.YesNo,MessageBoxIcon.Question) 'user doesn't want to delete If question <> vbYes Then Delete_Suppressed_Parts = "No" Exit Sub End If 'Reference active document Dim doc As AssemblyDocument doc = ThisApplication.ActiveDocument 'Put parts into array Dim acd As AssemblyComponentDefinition acd = doc.ComponentDefinition 'do removal Call DeleteSuppressedComponent(acd.Occurrences) 'feedback MessageBox.Show("Deleted!", "BOOM!") End Sub Sub DeleteSuppressedComponent(occs As ComponentOccurrences) 'define component instance Dim occ As ComponentOccurrence 'loop through all components For Each occ In occs If occ.Suppressed Then occ.Delete 'delete suppressed components Else 'recursive loop into current component to check for deeper suppressed components DeleteSuppressedComponent(occ.SubOccurrences) End If Next End Sub