Unsupressing Folders

a_burggraafUPR9E
Explorer

Unsupressing Folders

a_burggraafUPR9E
Explorer
Explorer

Hey Autodesk forum, here I am again. I am trying to unsupress as quickly as possible and want to change entire large assemblies in one go based on reading data from excel, unsupressing things inside a certain folder is a part of it. I managed to get this far and am able to unsupress folder names, however now I want to change it so instead of selecting the folder and unsuppressing it, I want ilogic to get all the componentoccurences from the folder that is selected and store them inside an objectcollection so I can process and unsupress them later all at once by using selectset.multiple. This is how far I got now, does anyone know how I can do this?

 

Private Sub UnsuppressFolderbyname(parentfolder As String, subfolder As String)
    Dim oDoc As Document = ThisDoc.Document
    Dim oModelPane As BrowserPane = oDoc.BrowserPanes.Item("Model")
    Dim oTopNode As BrowserNode = oModelPane.TopNode
    Dim oBFolders As BrowserFoldersEnumerator = oTopNode.BrowserFolders

    ' Check if there are any folders
    If oBFolders.Count = 0 Then 
        MessageBox.Show("No folders found.", "Debug Info") ' Show message if no folders found
        Exit Sub ' Exit the rule if no folders are found
    End If

    ' Loop through all top-level folders
    For Each oBFolder As BrowserFolder In oBFolders
      
        
        If oBFolder.Name = parentfolder Then ' Look for the parent folder
           
            
            ' Now look inside the parent folder for the subfolder
            Dim oSubFolders As BrowserFoldersEnumerator = oBFolder.BrowserNode.BrowserFolders
            
            For Each oSubFolder As BrowserFolder In oSubFolders
               
                
                If oSubFolder.Name = subfolder Then ' Look for the subfolder
                  
                    
                    ' Process the subfolder if found
                    ProcessFolder(oDoc, oSubFolder)
                    Exit Sub ' Exit after processing the subfolder
                End If
            Next
            
            ' If we get here, it means the subfolder was not found
            MessageBox.Show("Subfolder not found: " & subfolder, "Debug Info")
            Exit Sub ' Exit if the subfolder was not found
        End If
    Next
    
    ' If we get here, it means the parent folder was not found
    MessageBox.Show("Parent folder not found: " & parentfolder, "Debug Info")
End Sub


' This is a custom routine to process the folder
Private Sub ProcessFolder(oDoc As Document, oBrowserFolder As BrowserFolder)
    If oBrowserFolder IsNot Nothing Then
        ' Check if the folder has any contents
        If oBrowserFolder.BrowserNode.BrowserNodes.Count = 0 Then
            MsgBox("Nothing was found in '" & oBrowserFolder.Name & "' folder.", , "")
        Else
			 oDoc.SelectSet.Clear()
            oDoc.SelectSet.Select(oBrowserFolder)
			ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyCompSuppressionCtxCmd").Execute
			
        End If          
    End If
End Sub
0 Likes
Reply
116 Views
1 Reply
Reply (1)

ryan.rittenhouse
Enthusiast
Enthusiast

Here's code that will clear the selection set and add every component occurrence in the given folder to the selection. It is recursive, so it'll go the whole way down. If you don't want this, comment out line 19

 

Sub Main()
	
	ThisDoc.Document.SelectSet.Clear()
	Dim folderName As String = "Treads"
	SelectFolder(GetFolder(folderName))
	
End Sub 'Main

Sub SelectFolder(folder As BrowserFolder)

	If folder Is Nothing Then Exit Sub
	Dim doc As AssemblyDocument = ThisDoc.Document
	
	For Each node As BrowserNode In folder.BrowserNode.BrowserNodes
		
		Select Case True
			
			Case TypeOf node.NativeObject Is BrowserFolder
		        SelectFolder(node.NativeObject)
		        Continue For
		
		    Case TypeOf node.NativeObject Is ComponentOccurrence
		        doc.SelectSet.Select(node.NativeObject)
				
			Case Else
				Logger.Error("{0} is an unknown type: {1}", node.NativeObject.Name, TypeName(node.NativeObject))
			
		End Select
				
	Next node
	
End Sub 'SelectFolder

Function GetFolder(folderName As String) As BrowserFolder
	
	Dim doc As AssemblyDocument = ThisDoc.Document
	
	For Each folder As BrowserFolder In doc.BrowserPanes.Item("Model").TopNode.BrowserFolders
		If folder.Name = folderName Then
			Return folder
		End If
	Next folder
	
	MessageBox.Show("Folder " & folderName & " not found!")
	Return Nothing
	
End Function 'GetFolder
0 Likes