How to select multiple browser nodes

How to select multiple browser nodes

Anonymous
Not applicable
2,380 Views
15 Replies
Message 1 of 16

How to select multiple browser nodes

Anonymous
Not applicable

I have object collection with browser nodes. I tried to add this collection to oDrawDoc.SelectSet.Multiple(oObjColl) but it failed. I know that brower node has method "DoSelect" but it works per browser node and not for multiple nodes at once. How should I "DoSelect" multiple nodes?

0 Likes
Accepted solutions (1)
2,381 Views
15 Replies
Replies (15)
Message 2 of 16

HideoYamada
Advisor
Advisor

Hello danilo.veljkovic,

 

Try make a ObjectCollection of the BrowserNode.NativeObject and SelectMultiple  it.

Here is a sample code.

Sub test()
    Dim nodes As BrowserNodesEnumerator
    Dim node As BrowserNode
    Dim oc As ObjectCollection
    
    Set oc = ThisApplication.TransientObjects.CreateObjectCollection
    Set nodes = ThisApplication.ActiveDocument.BrowserPanes("PmDefault").TopNode.BrowserNodes
    
    For Each node In nodes
        Debug.Print TypeName(node.NativeObject)
        If TypeName(node.NativeObject) = "ExtrudeFeature" Then
            oc.Add node.NativeObject
        End If
    Next
    
    ThisApplication.ActiveDocument.SelectSet.SelectMultiple oc
End Sub

Good luck!

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 3 of 16

Anonymous
Not applicable

Thank you for the reply.

I have oCompOcc from oObjOccColl object collection and I get Native object for each occurrence. oAsmBN is node I want to select sub-nodes within.

This is what I am doing with the code:

    Dim oNativeBrowserNodeDef As NativeBrowserNodeDefinition
    Dim oTargetNode As BrowserNode
    Dim oCompOcc As ComponentOccurrence
    
    Dim oObjColl As ObjectCollection
    Set oObjColl = ThisApplication.TransientObjects.CreateObjectCollection
    
    For Each oCompOccEnum In oObjOccColl
        For Each oCompOcc In oCompOccEnum
            Set oNativeBrowserNodeDef = oAsmDoc.BrowserPanes.GetNativeBrowserNodeDefinition(oCompOcc)
            Set oTargetNode = oAsmBN.AllReferencedNodes(oNativeBrowserNodeDef).Item(1)
            Call oObjColl.Add(oTargetNode)
            Debug.Print oTargetNode.NativeObject.Name
        Next
    Next
    
    Call oDrawDoc.SelectSet.SelectMultiple(oObjColl)

Last line ends in "Method 'SelectMultiple' of object 'SelectSet failed" error message.

0 Likes
Message 4 of 16

HideoYamada
Advisor
Advisor

Can each item of oObjColl be added individually to SelectSet?

 

I don't understand exactly what you want to do, but

you shuld

Call oObjColl.Add(oTargetNode.NativeObject)

instead of

Call oObjColl.Add(oTargetNode)

, I think.

 

Best regards,

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 5 of 16

Anonymous
Not applicable

Hideo,

NativeObject, in my case, is Occurrence. But want to select browser node for given occurrence. Browser node has DoSelect method but I cannot use it because I want to select multiple browser nodes. Just like we use Ctrl+Click to select multiple browser nodes, like this:

SelectMultiple.png

My code is for drawing module of inventor.

0 Likes
Message 6 of 16

HideoYamada
Advisor
Advisor

Oh, drawing document...

 

As far as I know, there is no way to select the browse nodes in drawing document via SelectSet.

Because the object type of there nodes does not disclosed.

 

capture.PNG

 

Sorry for not helping.

By the way, What will you do after selecting multiple browser nodes?

 

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 7 of 16

Anonymous
Not applicable

I checked the same way how SelectSet gets BrowserNodes. 🙂

0 Likes
Message 8 of 16

Anonymous
Not applicable

Selecting browser node will highlight components in drawing view based on certain search criteria.

0 Likes
Message 9 of 16

HideoYamada
Advisor
Advisor

How about a way to select all of drawing curves corresponding to the component instead of selecting browser nodes?

(It must be slow...)

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 10 of 16

Anonymous
Not applicable

I already made this code but, as you've said, it is slow ... so i thought to make it faster ...

0 Likes
Message 11 of 16

HideoYamada
Advisor
Advisor

Hello,

 

I have posted about this issue on Idea Board.

https://forums.autodesk.com/t5/inventor-ideas/please-disclose-the-type-of-browsernode-nativeobject-i...

 

Please vote and comment more information!

 

Best Regards,

 

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 12 of 16

HideoYamada
Advisor
Advisor
Accepted solution

Finally I got it!

 

Select Multiple NodesSelect Multiple Nodes

Option Explicit

Private Declare PtrSafe Function GetKeyboardState Lib "user32" (pbKeyState As Byte) As Long
Private Declare PtrSafe Function SetKeyboardState Lib "user32" (pbKeyState As Byte) As Long

Private Const VK_CONTROL = &H11
Private keys(256) As Byte
Private save As Byte

Private Sub SetCtrlKey()
    GetKeyboardState keys(0)
    save = keys(VK_CONTROL)
    
    keys(VK_CONTROL) = &H80
    SetKeyboardState keys(0)
End Sub

Private Sub ResetCtrlKey()
    keys(VK_CONTROL) = save
    SetKeyboardState keys(0)
End Sub

Private Sub SelectPartsLoop(nodes As BrowserNodesEnumerator)
    Dim node As BrowserNode
    Dim occ As ComponentOccurrence
    
    For Each node In nodes
        Set occ = Nothing
        On Error Resume Next
        Set occ = node.NativeObject
        On Error GoTo 0
    
        If Not occ Is Nothing Then
            If Left(occ.Name, 3) = "JIS" Then
                node.DoSelect
            End If
        End If
        
        SelectPartsLoop node.BrowserNodes
    Next
End Sub

Sub SelectParts()
    Dim obj As Object
    Dim dDoc As DrawingDocument
    
    Set dDoc = ThisApplication.ActiveDocument
    
    Dim nodes As BrowserNodesEnumerator
    
    Set nodes = dDoc.BrowserPanes.Item("DlHierarchy").TopNode.BrowserNodes
        
    SetCtrlKey
    SelectPartsLoop nodes
    ResetCtrlKey
End Sub

I found that BrowserNode.DoSelect kept already selected items when I held down the control key (yes, on physical keyboard).

So if the keyboard state is changed as a control key being pressed by Win32 API, DoSelect keeps last selecting.

 

The above code will select all occurrences whose name starts with "JIS" as shown in the screen capture.

 

How is this?

 

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
Message 13 of 16

Anonymous
Not applicable

Thank you Hideo for not giving up! I totally missed Ctrl button. Smart!

0 Likes
Message 14 of 16

liminma8458
Collaborator
Collaborator

Hi, Yamada,

When I convert your code into VB.NET,  it does not work. It can't select multiple browser nodes any more, only the last one is selected. Do you know why?

Thanks

Thanks
Limin
Inventor pro 2023 64 bit update 5.3; Windows 11 pro 64 bit version 24H2; Office 2013 64 bit

Download iCable in App Store to Create Cables Easily

0 Likes
Message 15 of 16

HideoYamada
Advisor
Advisor

Hello,

 

The following iLogic rule works fine for me.

Imports System.Runtime.InteropServices

Public Sub Main 
	MultipleSelectSample.ThisApplication = ThisApplication
	MultipleSelectSample.SelectParts()	
End Sub

Public Class MultipleSelectSample
    Public Shared ThisApplication As Application
    <DllImport("user32.dll", SetLastError:=True)>
    Private Shared Function GetKeyboardState(pbKeyState() As Byte) As <MarshalAs(UnmanagedType.Bool)> Boolean
    End Function
    <DllImport("user32.dll", SetLastError:=True)>
    Private Shared Function SetKeyboardState(pbKeyState() As Byte) As <MarshalAs(UnmanagedType.Bool)> Boolean
    End Function

    Private Const VK_CONTROL = &H11
    Private Shared keys(256) As Byte
    Private Shared save As Byte

    Private Shared Sub SetCtrlKey()
        GetKeyboardState(keys)
        save = keys(VK_CONTROL)

        keys(VK_CONTROL) = &H80
        SetKeyboardState(keys)
    End Sub

    Private Shared Sub ResetCtrlKey()
        keys(VK_CONTROL) = save
        SetKeyboardState(keys)
    End Sub

    Private Shared Sub SelectPartsLoop(nodes As BrowserNodesEnumerator)
        Dim node As BrowserNode
        Dim occ As ComponentOccurrence

        For Each node In nodes
            occ = Nothing
            On Error Resume Next
            occ = node.NativeObject
            On Error GoTo 0

            If Not occ Is Nothing Then
                If Left(occ.Name, 3) = "JIS" Then
                    node.DoSelect()
                End If
            End If

            SelectPartsLoop(node.BrowserNodes)
        Next
    End Sub

    Public Shared Sub SelectParts()
        Dim obj As Object
        Dim dDoc As DrawingDocument

        dDoc = ThisApplication.ActiveDocument

        Dim nodes As BrowserNodesEnumerator

        nodes = dDoc.BrowserPanes.Item("DlHierarchy").TopNode.BrowserNodes

        SetCtrlKey()
        SelectPartsLoop(nodes)
        ResetCtrlKey()
    End Sub
End Class

 

And my add-in that are written in C# works fine.

I have not tried it, but if it does not work for add-ins written in VB.net, then the problem must depend on the VB.net runtime.

 

Thanks,

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 16 of 16

liminma8458
Collaborator
Collaborator

Hi, Yamada,

With your help, I got the VB.NET code work. Thank you so much!

 

The following code should help if anyone need it!  Call SelectParts() to use it (You need to "Expand All Children" for the drawing browser as in expand_pane_drawing() to make the multiple selection work).

 

Imports Inventor

Public Class cls_browser_node_drawing

    Dim ThisApplication As Inventor.Application

 

    Private Declare Function SetKeyboardState Lib "user32" (pbKeyState() As Byte) As Boolean

    Private Declare Function GetKeyboardState Lib "user32" (pbKeyState() As Byte) As Boolean

 

    Private Const VK_CONTROL = &H11

    Private keys(256) As Byte

    Private osave As Byte

    Dim oDoc As DrawingDocument

 

    Dim node As BrowserNode

 

    Public Sub New(AppObj As Inventor.Application)

        Try

            ThisApplication = AppObj

            oDoc = ThisApplication.ActiveDocument

 

        Catch ex As Exception

            MsgBox("There is problem in new(...) " & vbCrLf & vbCrLf & ex.Message & vbCrLf & vbCrLf & ex.ToString)

            Exit Sub

        End Try

    End Sub

 

    Private Sub SetCtrlKey()

 

        GetKeyboardState(keys)

        osave = keys(VK_CONTROL)

 

        keys(VK_CONTROL) = &H80

        SetKeyboardState(keys)

  

    End Sub

 

    Private Sub ResetCtrlKey()

        keys(VK_CONTROL) = osave

        SetKeyboardState(keys)

    End Sub

 

    Private Sub SelectPartsLoop(nodes As BrowserNodesEnumerator)

 

        Dim occ As ComponentOccurrence

        For Each node In nodes

            occ = Nothing

            On Error Resume Next

 

            occ = node.NativeObject

            On Error GoTo 0

 

            If Not occ Is Nothing Then

                If occ.Name Like "*Ass1:1*" Then

                    node.DoSelect()

                End If

            End If

 

            SelectPartsLoop(node.BrowserNodes)

 

 

        Next

     End Sub

 

    Public Sub SelectParts() 

        Try

 

            Dim oObj As Object

            oObj = oDoc.SelectSet.Item(1)

 

            Call expand_pane_drawing()

 

            Dim nodes As BrowserNodesEnumerator

 

            nodes = oDoc.BrowserPanes.Item("DlHierarchy").TopNode.BrowserNodes

            AppActivate(ThisApplication.Caption)

            SetCtrlKey()

            SelectPartsLoop(nodes)

            ResetCtrlKey()

        Catch ex As Exception

 

            MsgBox("There is error in SelectParts" & vbCrLf & vbCrLf & vbCrLf & ex.ToString)

        End Try

    End Sub

 

    Public Sub expand_pane_drawing()

 

        Dim oModelBP As BrowserPane

        oModelBP = oDoc.BrowserPanes.Item("DlHierarchy")

 

        Call drawing_pane_expand(oModelBP.TopNode)

 

    End Sub

 

    'iterate to expand browser pane

    Private Sub drawing_pane_expand(oTopBrowserNode As BrowserNode)

 

        For Each oNode In oTopBrowserNode.BrowserNodes

 

            On Error Resume Next

            oNode.Expanded = True

            On Error GoTo 0

 

            If oNode.BrowserNodes.Count > 0 Then

                On Error Resume Next

                oNode.Expanded = True

                On Error GoTo 0

                Call drawing_pane_expand(oNode)

            End If

        Next

 

    End Sub

End Class

 

 

 

Thanks
Limin
Inventor pro 2023 64 bit update 5.3; Windows 11 pro 64 bit version 24H2; Office 2013 64 bit

Download iCable in App Store to Create Cables Easily