Run command/plugin automatically when Rhino starts

You cannot run a command while the plug-in is loading. Instead, you have to wait until Rhino has fully initialized, and then run the command. This is done by subscribing to the RhinoApp.Idle event, and then when it fires, to run the command like so:

public class IrisReaderPlugin: Rhino.PlugIns.PlugIn
{
    public IrisReaderPlugin()
    {
        Instance = this;
        RhinoApp.Idle += OnIdle; //subscribe
    }

    private void OnIdle(object sender, EventArgs e)
    {
        RhinoApp.Idle -= OnIdle; // unsubscribe
        RhinoApp.RunScript("_MyCommand Option1=Value1 Option2=Value2", false);
    }

    ///<summary>Gets the only instance of the IrisReaderPlugin plug-in.</summary>
    public static IrisReaderPlugin Instance
    {
        get;
        private set;
    }

    public override PlugInLoadTime LoadTime
    {
        get { return PlugInLoadTime.AtStartup;}
    }
}

I haven’t tested this, but it should work :smile:

4 Likes