Skip to main content
4-Participant
May 28, 2026
Question

[Macro] How to select the first item in Search Tool results?

  • May 28, 2026
  • 3 replies
  • 35 views

I'm creating a macro to automatically select a 3D Curve using the Search Tool.

The search returns multiple results and I need to always select the first item in the result list.

In Creo, it seems that selection is based on the ID. Is there a way to make it always select the first item.

mapkey(continued) ~ Command `ProCmdMdlTreeSearch` ;\
mapkey(continued) ~ Open `selspecdlg0` `SelOptionRadio`;~ Close `selspecdlg0` `SelOptionRadio`;\
mapkey(continued) ~ Select `selspecdlg0` `SelOptionRadio` 1 `3D Curve`;\
mapkey(continued) ~ Update `selspecdlg0` `ExtRulesLayout.ExtBasicNameLayout.BasicNameList` \
mapkey(continued) `SKETCH6`;~ Activate `selspecdlg0` `EvaluateBtn`;\
mapkey(continued) ~ Select `selspecdlg0` `ResultList` 1 `260:59:`;\
mapkey(continued) ~ Activate `selspecdlg0` `ApplyBtn`;

3 replies

21-Topaz I
May 28, 2026

Macro wise i come to the same conclusion as yours.

tbraxton
22-Sapphire II
22-Sapphire II
May 28, 2026

Try replacing line 6 of your mapkey posted with the following:

mapkey(continued) ~ Select `selspecdlg0` `ResultList` -1; \

This should return the first item in the slection filter results array.

 

This approach is not officially supported by PTC so consider this in the context of how you are using it. It may not always work in all mapkeys or situations.

Van_AG
15-Moonstone
May 28, 2026

You can also select the first item from the search results using a VBS script


A standard macro launches the search tool, configures the search for curves, and sorts the results by feature number

mapkey search_curves ~ Activate `main_dlg_cur` `accl_ProCmdMdlTreeSearch`;\
mapkey(continued) ~ Select `selspecdlg0` `RuleTypes` 1 `Type`;\
mapkey(continued) ~ Open `selspecdlg0` `ExtRulesLayout.ExtTyperuleLayout.TyperuleTypesList`;\
mapkey(continued) ~ Select `selspecdlg0` `ExtRulesLayout.ExtTyperuleLayout.TyperuleTypesList` \
mapkey(continued) 1 ` Curve#1, 949`;~ Select `selspecdlg0` `CascadeButton1`;\
mapkey(continued) ~ Select `selspecdlg0` `SortByCasc`;~ Close `selspecdlg0` `CascadeButton1`;\
mapkey(continued) ~ Select `selspecdlg0` `ItemSortRadio` 1 `feature #`;\
mapkey(continued) ~ Activate `selspecdlg0` `EvaluateBtn`;

 

And there is macro to invoke vbs script
 

mapkey set1 @SYSTEMstart WScript.exe set1.vbs;

 

The script calls the standard macro above and then presses
the spacebar (to select the first row in the search results)
Tab to move to the ‘>>’ button
Spacebar to push the ‘>>’ button
Tab to move to the ‘Close’ button
And spacebar to push the ‘Close’ button

Dim WshShell
set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "search_curves"
WScript.Sleep 300
WshShell.SendKeys "{ }"
WScript.Sleep 100
WshShell.SendKeys "{TAB}"
WScript.Sleep 100
WshShell.SendKeys "{ }"
WScript.Sleep 100
WshShell.SendKeys "{TAB}"
WScript.Sleep 100
WshShell.SendKeys "{ }"
WScript.Quit()