how to run Search Command through API

how to run Search Command through API

liminma8458
Collaborator Collaborator
570 Views
3 Replies
Message 1 of 4

how to run Search Command through API

liminma8458
Collaborator
Collaborator

Hi, all,

There is a Search function in Inventor browser:

search.PNG

At the same time, Inventor provides a API command "AppBrowserSearchCmd" for that. But how to use this API command?  I try to use following, but it doesn't work out.

 

Public Sub Run_Search_Command()
' Get the CommandManager object.
Dim oCommandMgr As CommandManager
Set oCommandMgr = ThisApplication.CommandManager

'Call oCommandMgr.PostPrivateEvent(kNameEvent, "VALPRD09")
'Call oCommandMgr.PostPrivateEvent(kFileNameEvent, "VALPRD09")

Call oCommandMgr.PostPrivateEvent(kStringEvent, "VALPRD09")

 

' Get control definition for the line command.
Dim oControlDef As ControlDefinition
Set oControlDef = oCommandMgr.ControlDefinitions.Item("AppBrowserSearchCmd")
' Execute the command.
Call oControlDef.Execute
End Sub

 

So, How to provide input to the API command? And where to get the search result?

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
Accepted solutions (2)
571 Views
3 Replies
Replies (3)
Message 2 of 4

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@liminma8458,

 

Nice question,

 

In Inventor 2020 API, a new object called "SearchBox" is exposed in BrowserPane. To do your task, try below VBA code to search in box

Sub SearchBoxSample()
    Dim oDoc As Document
    Set oDoc = ThisApplication.ActiveDocument
     
    Dim oPane As BrowserPane
    ' Get the BrowserPane that support the search box.
    If oDoc.DocumentType = kPartDocumentObject Then
        Set oPane = oDoc.BrowserPanes("PmDefault")
    ElseIf oDoc.DocumentType = kAssemblyDocumentObject Then
        Set oPane = oDoc.BrowserPanes("AmBrowserArrangement")
    ElseIf oDoc.DocumentType = kDrawingDocumentObject Then
        Set oPane = oDoc.BrowserPanes("DlHierarchy")
    ElseIf oDoc.DocumentType = kPresentationDocumentObject Then
        Set oPane = oDoc.BrowserPanes("DxHierarchy")
    End If
    
    Dim oSearchBox As SearchBox
    Set oSearchBox = oPane.SearchBox
    
    ' Enable the search box and display it in the broser pane for search text.
    oSearchBox.Enabled = True
    oSearchBox.Visible = True
    Call oSearchBox.Search("VALPRD09")
End Sub

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 4

liminma8458
Collaborator
Collaborator

Chandra,

Yes, the code works, even in Inventor 2019. I got the search result shown in the browser pane. But how can I get the resulted occurrence information through the API so I can deal with them with program? Looks like Object oSearchBox does not provide such information. Is it?

 

browserpane.PNG

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 4 of 4

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@liminma8458,

 

Try below VBA code to search occurrence in an assembly by mentioning name.

 

Sub SerachOccurrence()
    Dim oDoc As AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oDef As AssemblyComponentDefinition
    Set oDef = oDoc.ComponentDefinition
    
    Dim occ As ComponentOccurrence
    
    Dim coll As ObjectCollection
    Set coll = ThisApplication.TransientObjects.CreateObjectCollection
    
    For Each occ In oDef.Occurrences
        If InStr(UCase(occ.Name), UCase("VALPRD09")) = 1 Then
            Call coll.Add(occ)
        End If
    Next
    
End Sub

Note: It is tested for one level and can be extended further to get sub occurrences as well.

 

Thanks and regards


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes