Run command/plugin automatically when Rhino starts


#1

Hi,

I am developing a plugin that needs to run automatically whenever Rhino starts. Is there a way to do so?

Thanks,
Best
Yifan


(Steve Baer) #2

Override the LoadTime property on the plug-in class and return AtStartUp


#3

Thanks Steve,

I tried it out but does not work as I expected. Overriding loadTime property allows to load the plugin at startup, does that mean the plugin will run automatically, or just loaded and ready to be run?

Yifan


(Steve Baer) #4

The plug-in will be loaded automatically when Rhino starts. What version of Rhino are you using.?Older versions did not change the load time setting stored in the registry.


#5

I am using Rhino 5 and RhinoCommon. I launched Rhino 5 through Visual Studio debug.

To further clarify, I would like to, at the startup of Rhino, load the plugin, and run a command of the plugin. I may have loaded the plugin at startup, but how do I run my command as soon as the plugin is loaded?

I copied my plugin class here, hoping I am not doing anything wrong.
Thanks!
Yifan

  public class Plugin : Rhino.PlugIns.PlugIn
    {
        public IrisReaderPlugin()
        {
            Instance = this;
        }

        ///<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;}
        }
    }

(Menno Deij - van Rijswijk) #6

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:


#7

Menno,

Yes, that is exactly what I’d like to do.

Your code works like a charm!

Thank you so much!


#8

Hi @menno

Any other option instead of RunScript…

-Sarath


(Dale Fugier) #9

To execute a Rhino command? No.

– Dale