Quantcast
Channel: Manufacturing DevBlog
Viewing all articles
Browse latest Browse all 518

Suppress folder in assembly

$
0
0

By Adam Nagy

Inside an assembly you can create a folder in the browser and place multiple components in it. You can then control visibility and suppression of all those elements through the folder.

When you right-click on a folder you get a context menu with the "Suppress" menu item in it. If you click it Inventor will go through all the elements in the folder and suppress them. We can do the same thing through the API: iterate through the folder items and suppress them.
Note: the BrowserFolder object has no Suppress functionality in the API that could make the below code much simpler

In case of suppressing an occurrence pattern we have to go though each element, iterate through the occurrences they reference and suppress those, as shown in this blog post:
http://adndevblog.typepad.com/manufacturing/2012/05/how-can-i-suppress-the-circular-pattern-component-in-an-assembly-file.html 

Here is the VBA code that suppresses the contents of the "MyFolder" browser folder:

Sub SuppressFolderTest()
  Dim oDoc As AssemblyDocument
  Set oDoc = ThisApplication.ActiveDocument
  Dim oPane As BrowserPane
  Set oPane = oDoc.BrowserPanes("Model")
  Dim oTopNode As BrowserNode
  Set oTopNode = oPane.TopNode
  Dim oFolder As BrowserFolder
  Set oFolder = oTopNode.BrowserFolders.Item("MyFolder")
  Call SuppressFolder(oFolder)
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
    Set oObj = oItem.NativeObject
    If TypeOf oObj Is BrowserFolder Then
      Call SuppressFolder(oObj)
    ElseIf TypeOf oObj Is ComponentOccurrence Then
      Dim oOcc As ComponentOccurrence
      Set oOcc = oObj
      If Not oOcc.Suppressed Then Call oOcc.Suppress
    ElseIf TypeOf oObj Is OccurrencePattern Then
      Dim oPatt As OccurrencePattern
      Set 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
        Next
      Next
    End If
  Next
End Sub

Here is the same in iLogic:

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
  oFolder = oTopNode.BrowserFolders.Item("MyFolder")
  Call SuppressFolder(oFolder)
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
    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
        Next
      Next
    End If
  Next
End Sub

And here is the code in action. As you can see we get exactly the same result as if you clicked the "Suppress" context menu item of the folder in the UI, and the "Suppress" item will be ticked: 

Suppressfolder

 


Viewing all articles
Browse latest Browse all 518

Trending Articles