-_Insert command never triggers Command.EndCommand?


#1

Hello!

I’m running Rhino 5, with users interacting with my plugin via a dockable pane. Among other things, we need to at times insert files into the model, wait until the data is available, and then work with it. In order to detect that the insertion has completed, I tried instrumenting Command.EndCommand around a RhinoApp.RunScript command:

        ManualResetEvent oSignalEvent = new ManualResetEvent(false);
        var Command_EndCommand = new EventHandler<CommandEventArgs>((object sender, CommandEventArgs e) =>
        {
            if (e.CommandEnglishName.Contains("Insert"))
            {
                oSignalEvent.Set();
            }
            else
            {
                RhinoApp.WriteLine("Other command " + e.CommandEnglishName);
            }
        });

        var script =  string.Format("_-Insert _File=_Yes _LinkMode=Link \"{0}\" Block _Enter 0,0,0 1 _Enter _Enter", MY_PATH);
        Command.EndCommand += Command_EndCommand;
        RhinoApp.RunScript(script, false);

        oSignalEvent.WaitOne();
        Command.EndCommand -= Command_EndCommand;

What I’m seeing here is that the EndCommand handler is never called into.

Based on the advice given here (How to run scripts synchronized?), I also wrapped the RunScript call for “-_Insert …” in its own RhinoCommand, and ran a similar block of code to the above, but with the EnglishName of my RunScriptWrappingCommand:

        ManualResetEvent oSignalEvent = new ManualResetEvent(false);
        var Command_EndCommand = new EventHandler<CommandEventArgs>((object sender, CommandEventArgs e) =>
            {
                if (e.CommandId == command.Id)
                {
                    oSignalEvent.Set();
                }
            });
        Command.EndCommand += Command_EndCommand;

        RhinoApp.RunScript(command.EnglishName, false);

        oSignalEvent.WaitOne();
        Command.EndCommand -= Command_EndCommand;

Anybody have any ideas on how to detect when -_Insert has finished it’s business?

EDIT: I will note that I’ve successfully used the above patterns to wrap other document-modifying operations in rhino commands.


(Dale Fugier) #2

Hi @Andrew_Zukoski,

In this simple event watcher sample, the EndCommand event is called with the Insert command finishes.

– Dale