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