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.
Sub SuppressBead( _ wcd As WeldmentComponentDefinition, wbn As BrowserNode) Dim name As String name = wbn.BrowserNodeDefinition.Label' If the bead is already suppressed then its BeadFaces will be 0 If wcd.Welds.WeldBeads(name).BeadFaces.count = 0 Then Exit Sub' 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) End If Next End Sub
Here is the result of the program: