Skip to main content
1-Visitor
September 9, 2022
Solved

How to stop ProSelect() programmatically (no user interaction)?

  • September 9, 2022
  • 1 reply
  • 3710 views

Hello friends,

 

We run ProSelect() in our extension, and want to make the ProSelect() function call return on demand using some kind of API.

 

One thing I noticed is that the ProSelect() function call returns immediately after clicking Cancel on the select dialog, which makes me think that we may imitate such behavior using an API without the user actually clicking that button.

 

Thanks for your answers.

BR.

Best answer by YaroslavSin

What I think:

1. In the filter string use all acceptably types ("surfsce,edge,point")

2. ProSelectionPreFilter read value from GUI list for filter. Check type of the item to compare with GUI value. GUI value == item.type then return PRO_TK_NO_ERROR to accept the selection.

3. In ProSelectionPostSelact work with selected items. Return PRO_TK_GENERAL_ERROR to continue selection "loop" . ProSelect() will be active.

4. User click middle mouse button to abort selection. Write the message to info panel (console) "Press middle mouse button to cancel the operation".

1 reply

21-Topaz I
September 12, 2022

In order to address your request efficiently, there is need to clarify what you mean by "on demand". What click sequences or keyboard keys do you mean by that? 

 

Thanks to this clarification, this will narrow down your question and enable us to make relevant replies.

1-Visitor
September 12, 2022

Hello Remy,

 

On demand, is whenever I want to stop the current instance of ProSelect() (it runs within the infinite loop in the synchronous mode), in order to start it again with other parameters.

 

while (true)
{
   err = ProSelectionEnvAlloc(options, 1, &env);
   if (err != PRO_TK_NO_ERROR) {
        return PRO_TK_GENERAL_ERROR;
   }

   err = ProSelect("surface", 1, NULL, &sel_functions, env, NULL, &p_sel, &n_sel);
   ProSelectionEnvFree(env);

   ProWindowRepaint(PRO_VALUE_UNUSED);

   if (err != PRO_TK_NO_ERROR) {
      return(PRO_TK_GENERAL_ERROR);
  }

  if (n_sel > 0) {
  ProSelectionHighlight(p_sel[0], PRO_COLOR_SHEETMETAL);

  ProModelitem item;
  err = ProSelectionModelitemGet(p_sel[0], &item);
  ProTKFprintf(logfile1, "ID: %d\n", item.id);
  }
}

 

In the selection dialog box that I keep hidden, there is a 'Cancel' button which does it. I want to make loop stopped without this dialog.

Pls, let me know if that is clear enough.

Thanks.

BR - 

21-Topaz I
September 12, 2022

thank for your clarification. 
there is a lot to unpack, so let me roll it in an order so we can understand your current situation:

Your code calls ProSelect and hides the "Select" menu. 

First what is the purpose of hiding it? And how do you perform that (by default that menu shows)?

 

One thing that i can add is that to the Out of the box workflow to cancel ProSelect consists either in LMB Cancel or in selecting the "Select" menu and press ESC (because Creo needs the "Select" menu be focused.

 

Because you hide the "Select" menu the user can't give back the hand to Creo and pressing ESC is powerless.

 

Finally and it is less related to Creo and more to coding, allow me to simply tell that best practice has it that when creating a while loop, the first thing is to define the exit/failure condition in order to prevent infinite loop and all the consequences. Maybe you can restart from there.