Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to select multiple browser nodes

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
Anonymous
1712 Views, 12 Replies

How to select multiple browser nodes

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?

12 REPLIES 12
Message 2 of 13
HideoYamada
in reply to: Anonymous

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
Message 3 of 13
Anonymous
in reply to: HideoYamada

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.

Message 4 of 13
HideoYamada
in reply to: Anonymous

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
Message 5 of 13
Anonymous
in reply to: HideoYamada

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.

Message 6 of 13
HideoYamada
in reply to: Anonymous

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
Message 7 of 13
Anonymous
in reply to: HideoYamada

I checked the same way how SelectSet gets BrowserNodes. 🙂

Message 8 of 13
Anonymous
in reply to: HideoYamada

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

Message 9 of 13
HideoYamada
in reply to: Anonymous

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
Message 10 of 13
Anonymous
in reply to: HideoYamada

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

Message 11 of 13
HideoYamada
in reply to: Anonymous

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
Message 12 of 13
HideoYamada
in reply to: HideoYamada

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 13
Anonymous
in reply to: HideoYamada

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report