Deleting suppressed parts and patterns down multiple levels with ilogic

Deleting suppressed parts and patterns down multiple levels with ilogic

Anonymous
Not applicable
845 Views
1 Reply
Message 1 of 2

Deleting suppressed parts and patterns down multiple levels with ilogic

Anonymous
Not applicable

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

 

0 Likes
846 Views
1 Reply
Reply (1)
Message 2 of 2

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Try below consolidated iLogic code to delete suppressed parts and patterns in assembly.

 

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
			If occ.IsPatternElement Then
	        	Dim oPattern As RectangularOccurrencePattern 
	            oPattern = occ.PatternElement.Parent
	        	oPattern.Delete
			Else
				occ.Delete 'delete suppressed components	
			End If 
        Else 
			If occ.SubOccurrences.Count > 0 Then                           
            	'recursive loop into current component to check for deeper suppressed components
            	DeleteSuppressedComponent(occ.SubOccurrences)
			End If 
        End If
    Next

End Sub

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network