By Adam Nagy
Sometimes if the API is not working, one workaround could be selecting the component in the BrowserPane and executing the relevant ControlDefinition on it: http://adndevblog.typepad.com/manufacturing/2012/09/parse-browsernodes-for-a-specified-node-and-perform-userinterface-commands.html
Some components are not hooked up to the browser so you cannot get to the associated node using GetBrowserNodeFromObject, or it selects the wrong object: http://adndevblog.typepad.com/manufacturing/2013/04/get-browsernode-of-an-occurrence.html
Here is a VBA solution that shows how you might get to the object you need and then execute a command on it:
Function GetOccurrenceNode( _ name As String, nodes As BrowserNodesEnumerator) _ As BrowserNode Dim node As BrowserNode For Each node In nodes If node.BrowserNodeDefinition.Label = name Then Set GetOccurrenceNode = node Exit Function End If Set GetOccurrenceNode = _ GetOccurrenceNode(name, node.BrowserNodes) If Not GetOccurrenceNode Is Nothing Then Exit Function End If Next End Function Function GetNode( _ obj As Object, nodes As BrowserNodesEnumerator) As BrowserNode Dim node As BrowserNode For Each node In nodes If node.NativeObject Is obj Then Set GetNode = node Exit Function End If Set GetNode = GetNode(obj, node.BrowserNodes) If Not GetNode Is Nothing Then Exit Function End If Next End Function Sub HideSubComponent() Dim dwg As DrawingDocument Set dwg = ThisApplication.ActiveDocument Dim dv As DrawingView ' Get "B:MainAsm.iam" Detail View Set dv = dwg.ActiveSheet.DrawingViews(2) Dim bp As BrowserPane Set bp = dwg.BrowserPanes("DlHierarchy") Dim asm As AssemblyDocument Set asm = dv.ReferencedDocumentDescriptor.ReferencedDocument Dim occ As ComponentOccurrence Set occ = asm.ComponentDefinition.Occurrences(1) ' This throws an error in Inventor 2012, ' that's the reason for the below workaround 'Call dv.SetVisibility(occ, False) ' If it's hidden already then we're done If Not dv.GetVisibility(occ) Then Exit Sub ' We have to find the BrowserNode of the ' occurrence under the DrawingView Dim node As BrowserNode ' This does not work well for dv.ParentView, ' and does not work at all for dv: 'Set node = bp.GetBrowserNodeFromObject(dv.parent) ' So we use this instead Set node = GetNode(dv, bp.TopNode.BrowserNodes) ' Then select the occurrence under the view node Set node = GetOccurrenceNode(occ.name, node.BrowserNodes) Call node.DoSelect ' Then run the command on it Dim cm As CommandManager Set cm = ThisApplication.CommandManager Dim cd As ControlDefinition Set cd = cm.ControlDefinitions("DrawingEntityVisibilityCtxCmd") Call cd.Execute End Sub