How to check if command prompt is busy and, if so, cancel current command

Hello everyone,

I would like to ask how to find out programatically through C# if there is currently a command waiting for input in the command line and, if so, cancel the current command.

For example, suppose the user typed line. How do you find out if there is something waiting for input in the command line and, if so, cancel it.

Thank you,

Hi @scudelari,
It depends at what point you want to cancel the current command. If you want to cancel as soon as the command is run, then you can subscribe to Command.BeginCommand event, and cancel the command by checking its name

private void OnBeginCommand(object sender, CommandEventArgs e)
        {
            if(e.CommandEnglishName == "Line")
            {
                if (Rhino.Commands.Command.InCommand())
                    RhinoApp.RunScript("!", false);
            }
        }

Since there is no event that triggers when Rhino is “InCommand”, we can only do this inside other event handlers. For example, if an object is selected while a command is running

RhinoDoc.SelectObjects += OnSelectRhinoObjects;

private void OnSelectRhinoObjects(object sender, RhinoObjectSelectionEventArgs e)
        {
            if (Rhino.Commands.Command.InCommand())
                RhinoApp.RunScript("!", false);                        
    }

Thanks! I think that the Command.InCommand() is what I was looking for (I was looking for something like this in the RhinoApp class but couldn’t find).

Thank you!