Get items selected in the browser pane

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

If you want to find out which items in the browser are selected, then you can simply iterate through all the items in the tree recursively and check each node’s Selected property.

The following VBA sample shows this in case of a drawing document: 

Function GetSelectedItems(nodes As BrowserNodesEnumerator) As String
Dim node As BrowserNode
For Each node In nodes
If node.Selected Then
GetSelectedItems = GetSelectedItems _
+ vbCrLf + node.BrowserNodeDefinition.Label
End If
GetSelectedItems = GetSelectedItems _
+ GetSelectedItems(node.BrowserNodes)
Next
End Function
Sub GetSelectedItemsInBrowser()
Dim doc As Document
Set doc = ThisApplication.ActiveDocument
If Not TypeOf doc Is DrawingDocument Then
MsgBox "Open a drawing document first"
Exit Sub
End If
Dim bp As BrowserPane
Set bp = doc.BrowserPanes("DlHierarchy")
Dim items As String
items = GetSelectedItems(bp.TopNode.BrowserNodes)
MsgBox items
End Sub

Selection


Comments

3 responses to “Get items selected in the browser pane”

  1. Hello,
    my Addin adds a custom entry to the contextmenu of the selected Browsernode. Therefore I parse the activePane recursively and filter selected nodes. It works, but… if I have a bigger assy open, there are in 135k+ Nodes is sum. Iterating through hangs the program for several seconds (or minutes).
    This is, of course, not suitable. Is there any other method to get the currently selected node? I know about the browserpanesevent, but the node won’t be activated, it’s just rightclicked. Unfortunatelly there is no (at least documented) “BrowsernodeEvent.Selected” to cache the selected node, nor a property on the Browserpane object fulfilling this requirement.
    BR,
    Daniel

  2. Hi Daniel,
    If you are right-clicking on an entity which is exposed through the API then it should be passed to the OnLinearMarkingMenu event which you need to use in order to add items to the context menu anyway – even in the browser: http://adndevblog.typepad.com/manufacturing/2015/03/entity-specific-context-menu.html
    If you need further help then please log it on the API forum instead as the comment section of the blog is not really good for discussions.
    Cheers,
    Adam

  3. Hello Adam,
    thanks for the reply. I’ll try your suggestion. I know about the forum and I use it as well, just posted it here because I felt, this question may be directly related to the blog post. :)
    Best Regards,
    Daniel

Leave a Reply to dbaCancel reply

Discover more from Autodesk Developer Blog

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

Continue reading