Block other commands from executing while a command is active


#1

Hi,

I created a command that inherits Rhino.Commands.Command and in this command, I added a Rhino.Input.Custom.GetObject instance. While the command is waiting for the user to select an object, the user might trigger another command or the same command by clicking on the buttons on the toolbars.

Based on my observation: (Please correct me if my observation is wrong)
If the active command is not decorated with [Rhino.Commands.CommandStyle(Rhino.Commands.Style.ScriptRunner)], other commands are blocked from being triggered.

As the command that I added requires to run Rhino.RhinoApp.RunScript(…), I can’t remove the CommandStyle attribute.

How can I block other commands from executing while a command is active?

Thank you


(Dale Fugier) #2

Hi @PohNee,

Your observation is incorrect.

The reason your command is canceling is because, during a GetObject operation, the picker is passed an ‘Esc’ key token. And your code is exiting the command based on this.

For example:

var go = new GetObject();
go.SetCommandPrompt("Pick something")
go.Get();
if (go.CommandResult() != Result.Success)
  return go.CommandResult();

While waiting for user input, and ‘Esc’ key token is received, which in turn set the command result to Result.Cancel. Since this isn’t equal to Result.Success, the code returns, thus exiting the command.

Does this help?

– Dale


#3

Hi Dale,

Do you mean that internally, an ‘Esc’ key is passed when a new command is being triggered to start?
This is because there is no ‘Esc’ key press by end user.


(Dale Fugier) #4

No.

If, while your command is waiting for user input, if the user presses the Esc key or if he clicks a toolbar button that has a “!” character in the button macro, then your command might return.

– Dale


#5

The user does not press the Esc key or clicks a toolbar button that has a “!” character in the button macro.


(Dale Fugier) #6

Hi @PohNee,

I am not show how else to help you. Perhaps you should re-read my first reply?

– Dale


#7

Hi Dale,

I have re-read your first reply. But I still do not understand your explanation. The problem that I am encountering is that my command does not return. I have added a break point a line after the line: go.Get() and it does not get triggered. Instead, the new command started.
However, I found a solution. There is a method in GetBaseClass: EnableTransparentCommands(bool). When I calls it and provide a “false” value to the parameter before the Get() call, other commands are blocked from executing.