Run command on browser item

<?xml encoding=”UTF-8″>By Adam Nagy

Some functionality of an object or sometimes the whole object may not be exposed directly through the API. In this case one workaround could be selecting the object and then running commands on it. This is the combination of running a commmand (this blog post also shows how to get all the command names) and finding an item in the browser

E.g. the WeldBead object does not have a Suppress function, and the WeldmentComponentDefinition.SuppressFeatures function does not seem to work on it either. It’s also not hooked up to the selection system, i.e. when a bead is selected in the UI then ThisApplication.ActiveDocument.SelectSet(1) will return Nothing.

So the workaround is to select the object through the BrowserPane object and then run the AssemblySuppressFeatureCtxCmd command. In order to avoid this message, we’ll use SilentOperation = True.

Warning

Enum SuppressOption
kSuppress
kUnsuppress
kToggle
End Enum
Sub SuppressBead( _
wcd As WeldmentComponentDefinition, _
wbn As BrowserNode, _
so As SuppressOption)
Dim name As String
name = wbn.BrowserNodeDefinition.Label
' We only need to check the current state of the bead if
' we are not just toggling its state but want a specific one
If so <> kToggle Then
' If the bead is already suppressed then its
' BeadFaces.Count will be 0
Dim bfs As Faces
Set bfs = wcd.Welds.WeldBeads(name).BeadFaces
If bfs.Count = 0 Xor so = kUnsuppress Then Exit Sub
End If
' Get the CommandManager object
Dim cm As CommandManager
Set cm = ThisApplication.CommandManager
' Get the collection of control definitions
Dim cds As ControlDefinitions
Set cds = cm.ControlDefinitions
' Run the "Suppress" command
ThisApplication.SilentOperation = True
Call wbn.DoSelect
Call cds("AssemblySuppressFeatureCtxCmd").Execute2(True)
ThisApplication.SilentOperation = False
End Sub
Sub SuppressWeldBead()
Dim weldName As String
weldName = "Fillet Weld 1"
' Get document
Dim doc As AssemblyDocument
Set doc = ThisApplication.ActiveDocument
Dim wcd As WeldmentComponentDefinition
Set wcd = doc.ComponentDefinition
' Get "Model" browser
Dim bp As BrowserPane
Set bp = doc.BrowserPanes("AmBrowserArrangement")
' Get "Welds" node
Dim wbn As BrowserNode
For Each wbn In bp.TopNode.BrowserNodes
If wbn.BrowserNodeDefinition.Label = "Welds" Then
Exit For
End If
Next
' Get "Beads" node
Dim bbn As BrowserNode
For Each bbn In wbn.BrowserNodes
If bbn.BrowserNodeDefinition.Label = "Beads" Then
Exit For
End If
Next
' Get the Beads we want to suppress
For Each wbn In bbn.BrowserNodes
If wbn.BrowserNodeDefinition.Label = weldName Then
Call SuppressBead(wcd, wbn, kSuppress)
End If
Next
End Sub

Here is the result of the program:

SuppressWeld

 


Comments

3 responses to “Run command on browser item”

  1. Hey, this code was just what I needed! Thank you! One problem I am having, however, is getting the weld bead to Unsuppress. Do you have any advice on this?

  2. Hi,
    I updated the code so that now you can choose if you want to suppress, unsuppress or just toggle the state of the bead.

  3. Any chance to have it Ilogic translated?…
    Can’t get it to work

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading