Suppress and Unsupress folder in the Assembly

Suppress and Unsupress folder in the Assembly

karram
Advocate Advocate
1,018 Views
9 Replies
Message 1 of 10

Suppress and Unsupress folder in the Assembly

karram
Advocate
Advocate

Hello,

 

In my Assembly model i had two folder name like "Right pads" and " Left pads".

I have a condition like below.

If Baffle_Wall = "Right" Then

"Right pad" folder suppress

"Left pad" folder Unsuppress

If Baffle_Wall = "Left" Then

"Right pad" folder Unsuppress

"Left pad" folder suppress

If Baffle_Wall = "NO" Then

"Right pad" folder Unsuppress

"Left pad" folder Unsuppress

 

Below is ilogic code, but this will not works properly as per above condition. can you please guide or any other alternate code . Thanks

Sub Main()
  Dim oDoc As AssemblyDocument
  oDoc = ThisApplication.ActiveDocument
    
  Dim oPane As BrowserPane
  oPane = oDoc.BrowserPanes("Model")
  
  Dim oTopNode As BrowserNode
  oTopNode = oPane.TopNode
    
  Dim oFolder As BrowserFolder
  If Baffle_Wall = "Right" Then
  oFolder = oTopNode.BrowserFolders.Item("Right pads")
   Call SuppressFolder(oFolder)
   oFolder = oTopNode.BrowserFolders.Item("Left pads")
   Call UnSuppressFolder(oFolder)
  ElseIf Baffle_Wall = "Left" Then
  oFolder = oTopNode.BrowserFolders.Item("Left pads")
  Call UnSuppressFolder(oFolder)
  oFolder = oTopNode.BrowserFolders.Item("Right pads")
  Call SuppressFolder(oFolder)
   ElseIf Baffle_Wall = "NO" Then
  oFolder = oTopNode.BrowserFolders.Item("Left pads")
  Call UnSuppressFolder(oFolder)
  oFolder = oTopNode.BrowserFolders.Item("Right pads")
  Call UnSuppressFolder(oFolder)
End If
  End Sub

' Recursive function as there could be subfolders too
Sub SuppressFolder(oFolder As BrowserFolder)
  Dim oItem As BrowserNode
  For Each oItem In oFolder.BrowserNode.BrowserNodes
    Dim oObj As Object
    oObj = oItem.NativeObject
    
    If TypeOf oObj Is BrowserFolder Then
      Call SuppressFolder(oObj)
    ElseIf TypeOf oObj Is ComponentOccurrence Then
      Dim oOcc As ComponentOccurrence
      oOcc = oObj
      
      If Not oOcc.Suppressed Then Call oOcc.Suppress (True)
    ElseIf TypeOf oObj Is OccurrencePattern Then
      Dim oPatt As OccurrencePattern
      oPatt = oObj
      
      Dim oElem As OccurrencePatternElement
      For Each oElem In oPatt.OccurrencePatternElements
        For Each oOcc In oElem.Occurrences
          If Not oOcc.Suppressed Then Call oOcc.Suppress (True)
        Next
      Next
    End If
  Next
End Sub

Sub UnSuppressFolder(oFolder As BrowserFolder)
   Dim oItem As BrowserNode
  For Each oItem In oFolder.BrowserNode.BrowserNodes
    Dim oObj As Object
    oObj = oItem.NativeObject
    
    If TypeOf oObj Is BrowserFolder Then
      Call SuppressFolder(oObj)
    ElseIf TypeOf oObj Is ComponentOccurrence Then
      Dim oOcc As ComponentOccurrence
      oOcc = oObj
      
      If Not oOcc.Suppressed Then Call oOcc.Suppress (False)
    ElseIf TypeOf oObj Is OccurrencePattern Then
      Dim oPatt As OccurrencePattern
      oPatt = oObj
      
      Dim oElem As OccurrencePatternElement
      For Each oElem In oPatt.OccurrencePatternElements
        For Each oOcc In oElem.Occurrences
          If Not oOcc.Suppressed Then Call oOcc.Suppress (False)
        Next
      Next
    End If
  Next
End Sub

 

0 Likes
Accepted solutions (2)
1,019 Views
9 Replies
Replies (9)
Message 2 of 10

_dscholtes_
Advocate
Advocate

@karramwrote:

Sub UnSuppressFolder(oFolder As BrowserFolder)
   Dim oItem As BrowserNode
  For Each oItem In oFolder.BrowserNode.BrowserNodes
    Dim oObj As Object
    oObj = oItem.NativeObject
    
    If TypeOf oObj Is BrowserFolder Then
      Call SuppressFolder(oObj)

Yeah, I think there's a typo in the last line of code in the quote above. Just compare it with the name of the sub 😉 (sub is called UnSuppressFolder, yet the call goes to SuppressFolder.

 

Btw, you did get this code from this Manufacturing DevBlog article did you? It's worth to mention your resource(s) in your post. 

Message 3 of 10

karram
Advocate
Advocate

Yes the suppress code from Mfg DevBloggers.

 

I correct the code as you mentioned its not works

0 Likes
Message 4 of 10

karram
Advocate
Advocate

Any solution for above case

Thanks

0 Likes
Message 5 of 10

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @karram 

 

Something like this example should work.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Sub Main

	Dim oDoc As AssemblyDocument
	oDoc = ThisApplication.ActiveDocument

	Dim oPane As BrowserPane
	oPane = oDoc.BrowserPanes("Model")

	Dim oTopNode As BrowserNode
	oTopNode = oPane.TopNode

	RightFolder = oTopNode.BrowserFolders.Item("Right pads")
	LeftFolder = oTopNode.BrowserFolders.Item("Left pads")

	If Baffle_Wall = "NO" Then
		Call SuppressFolder(RightFolder, True)
		Call SuppressFolder(LeftFolder, True)
	Else
		oSuppress = (Baffle_Wall = "Left")
		Call SuppressFolder(RightFolder, Not oSuppress)
		Call SuppressFolder(LeftFolder, oSuppress)
	End If


End Sub

Sub SuppressFolder(oFolder As BrowserFolder, oSuppress As Boolean)

	Dim oItem As BrowserNode
	For Each oItem In oFolder.BrowserNode.BrowserNodes
		Dim oObj As Object
		oObj = oItem.NativeObject

		If TypeOf oObj Is BrowserFolder Then
			Call SuppressFolder(oObj, oSuppress)

		ElseIf TypeOf oObj Is ComponentOccurrence Then
			Dim oOcc As ComponentOccurrence
			oOcc = oObj

			oOcc.Unsuppress
			If oSuppress = True Then oOcc.Suppress

		ElseIf TypeOf oObj Is OccurrencePattern Then
			Dim oPatt As OccurrencePattern
			oPatt = oObj

			Dim oElem As OccurrencePatternElement
			For Each oElem In oPatt.OccurrencePatternElements
				For Each oOcc In oElem.Occurrences
					
					oOcc.Unsuppress
					If oSuppress = True Then oOcc.Suppress
				Next
			Next
		End If
	Next

End Sub

 

EESignature

Message 6 of 10

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Hi @karram . In my case the code works fine, I added error information output in Logger.Info in case you have problems with the code.

Public Sub Main()
	Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument	
	Dim oFolders As BrowserFoldersEnumerator = oDoc.BrowserPanes("Model").TopNode.BrowserFolders
	
	If Baffle_Wall = "Right" Then
		Call SuppressControlFolder(oFolders("Right pads"), True)
		Call SuppressControlFolder(oFolders("Left pads"), False)
	Else If Baffle_Wall = "Left" Then
		Call SuppressControlFolder(oFolders("Right pads"), False)
		Call SuppressControlFolder(oFolders("Left pads"), True)
	Else If Baffle_Wall = "NO" Then
		Call SuppressControlFolder(oFolders("Right pads"), False)
		Call SuppressControlFolder(oFolders("Left pads"), False)
	End If
End Sub

Private Sub SuppressControlFolder(ByVal oFolder As BrowserFolder, ByVal bSupp As Boolean)
	For Each oItem As BrowserNode In oFolder.BrowserNode.BrowserNodes
		Dim oObj As Object = oItem.NativeObject		
		If TypeOf oObj Is BrowserFolder Then
			Call SuppressControlFolder(oObj, bSupp)
		ElseIf TypeOf oObj Is ComponentOccurrence Then
			Dim oOcc As ComponentOccurrence = oObj			
			If Not oOcc.Suppressed = bSupp Then Call SuppressOcc(oOcc, bSupp)
		Else If TypeOf oObj Is OccurrencePattern Then
			Dim oPatt As OccurrencePattern = oObj			
			Dim oElem As OccurrencePatternElement
			For Each oElem In oPatt.OccurrencePatternElements
				For Each oOcc In oElem.Occurrences
					If Not oOcc.Suppressed = bSupp Then Call SuppressOcc(oOcc, bSupp)
				Next
			Next
		End If
	Next
End Sub

Private Function SuppressOcc(ByVal oOcc As ComponentOccurrence, ByVal bSupp As Boolean)
	Try
		If bSupp Then : oOcc.Suppress(True)
		Else : oOcc.Unsuppress
		End If
	Catch
		If bSupp Then :	Logger.Info("Failed to Suppress - " & oOcc.Name)
		Else :	Logger.Info("Failed to Unsuppress - " & oOcc.Name)
		End If
	End Try
End Function

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 7 of 10

_dscholtes_
Advocate
Advocate

@Curtis_Waguespack 

 


@Curtis_Waguespack wrote:
<snip>
oOcc.Unsuppress
If oSuppress = True Then oOcc.Suppress
</snip>

Isn't this a time-consuming and unnecessary order of operations when items need to be suppressed (first unsuppress, then suppress again)? Isn't it faster / more logical to write the following instead:

Call oOcc.Suppress(oSuppress)

 

 

 

 

 

 

Message 8 of 10

Curtis_Waguespack
Consultant
Consultant

@_dscholtes_ wrote:

In't this a time-consuming and unnecessary order of operations when items need to be suppressed (first unsuppress, then suppress again)? Isn't it faster / more logical to write the following instead:

Call oOcc.Suppress(oSuppress)

 


 

Hi @_dscholtes_ 

 

I think there is a little confusion about the suppress method, introduced by the original example.

 

The Suppress method only suppresses a component, it does not unsuppress by providing a true/false argument.

 

The Boolean argument (shown as True below) is an optional argument to skip the document save when suppressing a component. It is not a toggle of the suppression state

https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=ComponentOccurrence_Suppress

 

 

Call oOcc.Suppress( True) 

 

 

 

But your point about my example being time-consuming and unnecessary is valid.

 

My example did indeed just unsuppress everything and then re-suppress per the value the sub is handed down.

 

It would be better to do as @Andrii_Humeniuk has done in his example, where the component's current suppression state is evaluated using the Suppressed property, and then only unsuppressing it if needed. See example below, for an update to my example with the change denoted in bold.

 

Sub Main

	Dim oDoc As AssemblyDocument
	oDoc = ThisApplication.ActiveDocument

	Dim oPane As BrowserPane
	oPane = oDoc.BrowserPanes("Model")

	Dim oTopNode As BrowserNode
	oTopNode = oPane.TopNode

	RightFolder = oTopNode.BrowserFolders.Item("Right pads")
	LeftFolder = oTopNode.BrowserFolders.Item("Left pads")

	If Baffle_Wall = "NO" Then
		Call SuppressFolder(RightFolder, True)
		Call SuppressFolder(LeftFolder, True)
	Else
		oSuppress = (Baffle_Wall = "Left")
		Call SuppressFolder(RightFolder, Not oSuppress)
		Call SuppressFolder(LeftFolder, oSuppress)
	End If


End Sub

Sub SuppressFolder(oFolder As BrowserFolder, oSuppress As Boolean)

	Dim oItem As BrowserNode
	For Each oItem In oFolder.BrowserNode.BrowserNodes
		Dim oObj As Object
		oObj = oItem.NativeObject

		If TypeOf oObj Is BrowserFolder Then
			Call SuppressFolder(oObj, oSuppress)

		ElseIf TypeOf oObj Is ComponentOccurrence Then
			Dim oOcc As ComponentOccurrence
			oOcc = oObj

			If not oOcc.Suppressed = oSuppress Then oOcc.Unsuppress		
			If oSuppress = True Then oOcc.Suppress

		ElseIf TypeOf oObj Is OccurrencePattern Then
			Dim oPatt As OccurrencePattern
			oPatt = oObj

			Dim oElem As OccurrencePatternElement
			For Each oElem In oPatt.OccurrencePatternElements
				For Each oOcc In oElem.Occurrences
					
					If Not oOcc.Suppressed = oSuppress Then oOcc.Unsuppress					
					If oSuppress = True Then oOcc.Suppress
				Next
			Next
		End If
	Next

End Sub

 

EESignature

Message 9 of 10

HogueOne
Advocate
Advocate

I'm trying to make a subroutine to simply create a folder with chatgpt, but the syntax doesn't seem to work in iLogic. Would you be willing to help me fix this?

Sub Main

    ' Get the active assembly document
    Dim oDoc As AssemblyDocument
    oDoc = ThisApplication.ActiveDocument
    
    ' Access the model browser pane
    Dim oPane As BrowserPane
    oPane = oDoc.BrowserPanes("Model")
    
    ' Get the top node of the model browser
    Dim oTopNode As BrowserNode
    oTopNode = oPane.TopNode
    
    ' Create a new folder under the top node
    Call CreateNewFolder(oTopNode, "New Folder Name")

End Sub

Sub CreateNewFolder(oParentNode As BrowserNode, folderName As String)
    ' Create a new folder under the specified parent node
    Dim newFolder As BrowserFolder
    newFolder = oParentNode.BrowserFolders.Add(folderName)
    
    ' Optionally, you can add items or perform additional actions within the new folder
    
    ' Example: Add a part file to the new folder
    ' Dim partDoc As PartDocument
    ' partDoc = ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, , True)
    ' newFolder.Add(partDoc.ComponentDefinition)

    ' You can perform additional actions here as needed
End Sub
0 Likes
Message 10 of 10

Curtis_Waguespack
Consultant
Consultant

@HogueOne 

 

Here is an example I had on hand. It will comb through an assembly and find all purchased part ( as shown in the BOM)  and add them to a browser folder.

 

Curtis_Waguespack_0-1721331400843.png

 

 

Sub main
	
	sFolder = "Purchased"
	
	Dim oDoc As Document
	oDoc = ThisApplication.ActiveDocument

	If ThisApplication.ActiveDocument.DocumentType <> _
	DocumentTypeEnum.kAssemblyDocumentObject Then Return


	Dim oDef As ComponentDefinition
	oDef = oDoc.ComponentDefinition

	Dim oPane As BrowserPane
	oPane = oDoc.BrowserPanes.Item("Model")

	Dim oTopNode As BrowserNode
	oTopNode = oPane.TopNode

	Logger.Info("oPane.TopNode: " & oPane.TopNode.FullPath)

	Dim oTargetNode As BrowserNode
	Dim oFolder As BrowserFolder

	oTargetNode = oTopNode

	'get folder if it already exists
	For Each xFolder In oTargetNode.BrowserFolders
		'Logger.Info(xFolder.name)
		If xFolder.name = sFolder
			oFolder = xFolder
		End If
	Next

	'create folder if it doesn't exist
	If oFolder Is Nothing Then oFolder = oPane.AddBrowserFolder(sFolder)

	oFolder.AllowReorder = True
	oFolder.AllowDelete = True

	Dim oNode As BrowserNode
	oNode = oPane.GetBrowserNodeFromObject(oDef.Occurrences.Item(1))
	Try
		'move folder to just below the First occurrence
		oPane.Reorder(oNode, False, oFolder.BrowserNode)
	Catch
	End Try

	Call AddtoFolder(oFolder,oDef, oPane)

	Call Reorder(oFolder, oTopNode)
End Sub


Sub AddtoFolder(oFolder As BrowserFolder,oDef As ComponentDefinition, oPane As BrowserPane)
	
	Dim oNode As BrowserNode

	'stuff purchased parts into folder
	Dim oOcc As ComponentOccurrence
	For Each oOcc In oDef.Occurrences
		If oOcc.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure Then
			'add node to the folder
			'Logger.Info(oOcc.Name & " is purchased")
			oNode = oPane.GetBrowserNodeFromObject(oOcc)
			oFolder.Add(oNode)
		End If
	Next

End Sub

Sub Reorder(oFolder As BrowserFolder, oTopNode As BrowserNode)
	'[ move the folder to the top of the browser

	' Find next of EndOfFeatures
	Dim oFirstOccurrenceNode As BrowserNode
	oFirstOccurrenceNode = Nothing
	Dim lowerOfEndOfFeatures As Boolean
	lowerOfEndOfFeatures = False


	Dim oNode As BrowserNode
	For Each oNode In oTopNode.BrowserNodes
		' Sometimes NativeObject is Nothing.
		' So you must check it is Nothing or not before accessing it.
		If Not oNode.NativeObject Is Nothing Then
			If Not lowerOfEndOfFeatures Then
				If TypeOf oNode.NativeObject Is EndOfFeatures Then
					lowerOfEndOfFeatures = True
				End If
			Else
				If Not TypeOf oNode.NativeObject Is BrowserFolder Then
					oFirstOccurrenceNode = oNode
					Exit For
				End If
			End If
		End If
	Next oNode

	' This means all of top nodes consist of the BrowserFolders.
	If oFirstOccurrenceNode Is Nothing Then
		Exit Sub
	End If

	Dim oModelPane As BrowserPane
	oModelPane = ThisApplication.ActiveDocument.BrowserPanes("AmBrowserArrangement")

	' Move the folder to before the oFirstOccurrenceNode
	Try
		oModelPane.Reorder(oFirstOccurrenceNode, True, oFolder.BrowserNode)
	Catch
	End Try
End Sub






 

EESignature

0 Likes