OnLoad() not being called?( c#, rhinocommon)

Hi,

I’m trying to load some plugin data which is stored along with the brep objects in a user dictionary. After building and running the whole thing, everything worked fine once. When reopening the file it does not seem to run the OnLoad method or subscribe to the event handlers again. If I completely uninstall the plugin (including the registry entries) and reinstall it, it works another single time and on the next subsequent opening of the file doesn’t work anymore. I also tried a clean Rhino install, no luck there…

Am I misinterpreting how OnLoad is supposed to work? I had problems getting it to work the first time because EndOpenDocument wouldn’t fire reliably, but now I’m specifically waiting for RhinoApp to go into idle before doing anything. LoadFAData() currently does nothing but loop through the files objects and fetch any breps which carry the dictionary key, then replacing them with a new instance of the CustomBrepObject… I feel the problem lies upstream though, but i can’t nail it down.

Any help would be greatly appreciated.

best,
Lukas

public class FAPlugIn : Rhino.PlugIns.PlugIn

{
    public FAPlugIn()
    {
        Instance = this;
    }

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

    #region initialization sequence
    protected override LoadReturnCode OnLoad(ref string errorMessage)
    {
        RhinoDoc.EndOpenDocument += OnEndOpenDocument;

        return LoadReturnCode.Success;
    }

    private void OnEndOpenDocument(object sender, EventArgs e)
    {
        RhinoApp.Idle += OnIdle;
    }

    private void OnIdle(object sender, EventArgs e)
    {
        RhinoApp.Idle -= OnIdle;

        //load stuff
        LoadFAData();

    }
    #endregion

I thought I had checked everything before asking, turns out i didn’t. I just found the solution while (for the 10th time) re-checking the code and the registry entry: LoadMode was set to 2 (on demand). Change it to 1 (at startup) or add the following lines to the code and voila…

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