Hi @Damian_LeeF852L. There are a few ways this could be done. When using a 'recursive' process, you always need a separate Sub routine just to manage the 'recursion' steps, where it is designed in a way so that we can manually run it once, then it will keep calling itself to run again as many times as may be required to reach its goal which may be at an unknown number of steps either up or down. That is just the nature of a recursive routine, like the one named 'RecursivelyFindBrowserFolder' in my example above. There is nothing wrong with breaking a code up a larger task into multiple separate routines to handle smaller, specific tasks. I will post a single iLogic rule below which has 5 separate code routines in it. You do not necessarily need to use all 5 of them if you don't want to. The last two routines show different ways to achieve a similar goal. One of those last two, with 'Toggle' in its name, uses the folder browser node selection, followed by a command execution (manual user interface actions simulation), similar to in the previous examples, which is often not the best way to do things by code, for various reasons. Then there is a routine that uses true API methods to suppress those components, instead of user actions simulation tactics. The one which uses true API methods gives us more control, but requires a bit more code to apply that added control in an error proof way. The one named GetModelBrowserPane is obviously not always going to be necessary, and can be bypassed in most common situations. Its advantage is being language independent, because it gets that browser pane by its internal name, which is different in different types of documents, instead of its 'English' display name. These small, separate, specific code routines that may be commonly used many times, and potentially used by many different iLogic rules, can be stored in an external iLogic rule designed for keeping such common code routines, so simplify things. But that is a whole other large can of worms, so to speak.
Sub Main
Dim oInvApp As Inventor.Application = ThisApplication
Dim oADoc As AssemblyDocument = TryCast(oInvApp.ActiveDocument, Inventor.AssemblyDocument)
If oADoc Is Nothing Then Return
Dim sFolderName As String = "6 Test Terms + 2 Lockouts"
'just toggles suppression status, without checking or knowing current status
ToggleSuppressionOfBrowserFolder(oADoc, sFolderName)
'specify True to suppress, or False to unsuppress
SetSuppressionOfComponentsInBrowserFolder(oADoc, sFolderName, True)
If oADoc.RequiresUpdate Then oADoc.Update2(True)
End Sub
Function GetModelBrowserPane(doc As Inventor.Document) As Inventor.BrowserPane
For Each oPane As Inventor.BrowserPane In doc.BrowserPanes
'gets it by InternalName, per Document Type
If oPane.BuiltIn And oPane.TreeBrowser And _
(oPane.InternalName = "AmBrowserArrangement" Or _
oPane.InternalName = "DlHierarchy" Or _
oPane.InternalName = "PmDefault") Then Return oPane
Next 'oPane
Return Nothing
End Function
Function RecursivelyFindBrowserFolder(folders As Inventor.BrowserFoldersEnumerator, _
folderName As String) As Inventor.BrowserFolder
For Each oFolder As Inventor.BrowserFolder In folders
If oFolder.Name = folderName Then Return oFolder
If oFolder.BrowserNode.BrowserFolders.Count > 0 Then
RecursivelyFindBrowserFolder(oFolder.BrowserNode.BrowserFolders, folderName)
End If
Next 'oFolder
Return Nothing
End Function
Sub ToggleSuppressionOfBrowserFolder(doc As Inventor.Document, folderName As String)
'get BrowserPane by its InternalName per Document Type
Dim oModelPane As Inventor.BrowserPane = GetModelBrowserPane(doc)
Dim oFolder As Inventor.BrowserFolder = RecursivelyFindBrowserFolder(oModelPane.TopNode.BrowserFolders, folderName)
If oFolder IsNot Nothing Then
oFolder.BrowserNode.EnsureVisible()
oFolder.BrowserNode.DoSelect()
ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyCompSuppressionCtxCmd").Execute()
End If
End Sub
Sub SetSuppressionOfComponentsInBrowserFolder(doc As Inventor.Document, folderName As String, suppress As Boolean)
Dim oModelPane As Inventor.BrowserPane = GetModelBrowserPane(doc)
Dim oFolder As Inventor.BrowserFolder = RecursivelyFindBrowserFolder(oModelPane.TopNode.BrowserFolders, folderName)
If (oFolder Is Nothing) OrElse (oFolder.BrowserNode.BrowserNodes.Count = 0) Then Return
For Each oChildNode As Inventor.BrowserNode In oFolder.BrowserNode.BrowserNodes
Dim oNO As Object = Nothing
Try : oNO = oChildNode.NativeObject : Catch : End Try
If oNO Is Nothing Then Continue For
Dim oOcc As Inventor.ComponentOccurrence = TryCast(oNO, Inventor.ComponentOccurrence)
If oOcc Is Nothing Then Continue For
If (suppress = True) And (oOcc.Suppressed = False) Then
Try
oOcc.Suppress(True) 'True = skip save
Catch
End Try
ElseIf (suppress = False) And (oOcc.Suppressed = True) Then
Try
oOcc.Unsuppress()
Catch
End Try
End If
Next 'oChildNode
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield

(Not an Autodesk Employee)