cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

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

ZS_10383889
6-Contributor

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

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.

1 ACCEPTED SOLUTION

Accepted Solutions

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".

View solution in original post

10 REPLIES 10
remy
21-Topaz I
(To:ZS_10383889)

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.

ZS_10383889
6-Contributor
(To:remy)

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 - 

remy
21-Topaz I
(To:ZS_10383889)

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. 

ZS_10383889
6-Contributor
(To:remy)

Hi Remi,

Thanks for your answer.

 

1. We want to hide the "Select" menu, because that is the design requirement.  It follows  our identical add-on to SolidWorks, which provides the OnSelection notification from the box on clicking the ModelItem. If you recall, I started my search from looking after this possibility, since this is the most obvious choice. You suggested me to use ProSelect as the only existing alternative. I'm aware that this does not match our requirements, I don't like to be be trapped in the ProSelect function until mouse clicked.

 

2. I use the ProSelectionEnvOption options[] = { {PRO_SELECT_HIDE_SEL_DLG, 1} }; suggested to hide dialog.

 

3. If LMB Cancel  can issue the command to cancel ProSelect() then this functionality exists and should be accessible somehow.

 

4. It is said in TK UserGuide, I quote: "When using the function ProSelect() from within a loop, if you encounter the error PRO_TK_PICK_ABOVE (-14), then you must handle this error by returning control back to Creo Parametric."  I follow this advise. I certainly don't like it, but I don't see any other way to satisfy required functionality. Please advise otherwise.

 

BR.

For first look is cumbersome. You ask user to make a selection, but want to break operation without user.

What user story? What user must to do?

Maybe, functions ProSelFunctions* sel_func (4-th attribute in ProSelect()) will help you to test result before user make a choice. But need to understand your goal.

 

Hey @YaroslavSin ,

 

The situation is rather simple. We have a dialog box in the navigation pane (similar to the tree pane), which expects an input from the currently open model. This input is performed by click on a model (once again very similar to the tree).  There seems to be no notification provided by the API on LeftMouseButton on selection (very problematic). We are obliged to run permanently ProSelection() and wait for the user input. The mechanism we invented is very troublesome (and we are looking for possible alternatives) but it supports our purposes.

Unfortunately, we need to run ProSelection() with different params.  For this we need to cancel the current loop, and then immediately start it over again . The UI dialog provided by Creo is able to stop ProSelection(). By design we want to avoid the dialog box.  May I do this without UI, using some API?

Pls, confirm that this is clear enough.

 

Thanks for your a advice.

You need to stop first loop after the user make a selection (click the model)?

 

 

boolean isRun = true;
while (isRun )
{

   err = ProSelect("surface", 1, NULL, &sel_functions, env, NULL, &p_sel, &n_sel);
  if (n_sel > 0) {
  ProSelectionHighlight(p_sel[0], PRO_COLOR_SHEETMETAL);

  ProModelitem item;
  err = ProSelectionModelitemGet(p_sel[0], &item);
  if (item.id == 100) isRun = false;
  }
}
isRun = true;
while (isRun )
{
  err = ProSelect("edge", 1, NULL, &sel_functions, env, NULL, &p_sel, &n_sel);
}

 

ps: If I'm not mistaken, user can press middle mouse button (wheel) - this will complete selection with empty p_sel, n_sel = 0

 

Almost. I need to stop the loop as my UI changes of what I may select, lets say: Stop selecting "surface" and start selecting "edge" from now.

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".

Thanks for your ideas. I will consult my bosses about possible compromises.

Kudos @YaroslavSin 

 

Top Tags