Is there a function of c++ sdk that has the same effect as RhinoApp().OnIdle(1)+=OnIdle() of c# sdk?

Hi;
In c# when I run this code:

public class MyPlugin: Rhino.PlugIns.PlugIn
{
    public MyPlugin()
    {
        Instance = this;
        RhinoApp.Idle += OnIdle; 
    }
    private void OnIdle(object sender, EventArgs e)
    {
        RhinoApp.Idle -= OnIdle; 
        DoSomething();
    }
    public static MyPlugin Instance
    {
        get;
        private set;
    }
    public override PlugInLoadTime LoadTime
    {
        get { return PlugInLoadTime.AtStartup;}
    }
    DoSomething()
    {
          //to do what I want
    }
}

Rhino will run the function DoSomething() after Rhino open, now I want to change my code to c++,
but I can not find function whicth same effect as this code, which friend can help me?

There is sample in the Rhino developer samples on GitHub.

cmdSampleIdleProcessor.cpp

– Dale

Hi @ dale:
Get it, think you.
In the sample, I must run the “_SampleIdleProcessor” command, but I want run it when rhino startup.
I means I just want to run some function, turn the event on v…v at rhino startup, in c# it easy to implement, I just need set “RhinoApp.Idle += OnIdle”, and add the “public override PlugInLoadTime LoadTime” function, now I need the same effect in c++.

CRhinoPlugIn::plugin_load_time CMyPlugIn::PlugInLoadTime()
{
	return CRhinoPlugIn::load_plugin_at_startup;
}

I have found add the function above cant load plugin at rhino startup,but rhino still print nothing when I do like:

int myfunction(int x, int y)
{
	int z = x + y;
	return z;
}

BOOL CJewellyForRhinoPlugIn::OnLoadPlugIn()
{
	int z = myfunction(1, 2);
	RhinoApp().Print(L"%d\n",z);
	return CRhinoUtilityPlugIn::OnLoadPlugIn();
}

Can you give me some sample to solve it?

Just curious, why would you want to switch to c++?

@stevebaer
Protect code from decompiling :grinning:

Hi @suc_kiet,

Based on the sample that I referenced, add the following to your plug-in’s OnLoad overide:

BOOL CSamplePlugIn::OnLoadPlugIn()
{
  // TODO: Add plug-in initialization code here.
  theSampleIdleEventWatcher.Register();
  theSampleIdleEventWatcher.Enable(true);
  return TRUE;
}

– Dale