C# Visual Studio New command in Plugin not recognized

Hi there,

this might be a rather stupid question, but…

When I create a new command in a plugin it is not recognized.
It is only recognized when I completely reload the plugin.
Is the reason for this, that obviously on my machine the default setting in Visual Studio is “Do not copy”?

image

If yes, how can I change this setting… and is then “Copy if newer” the best option?

Thanks,
T.

This is by design.

When your plug-in loads, Rhino “remembers” the plug-in command. In doing this, Rhino can load your plug-in “on demand” when you run one of the commands.

Rhino cannot remember new commands until the plug-in is loaded.

Hope this helps.

– Dale

@dale, thanks for the rapid reply.
Just that I understand 100%:
I always thought that a plugin is loaded when I compile it new.
But this is obviously then not the case, right?

A command will notice it changes when “registered” in Rhino and then it’s changed in the code and complied again.
A plugin has to be loaded completely new when a new command is written.

Is that correct :slight_smile: ?

@tobias.stoltmann if you want your new commands to register when Rhino starts, without having to use an existing command to to trigger it, you can change your plugin load time to AtStartup

https://developer.rhino3d.com/api/rhinocommon/rhino.plugins.pluginloadtime

The default is WhenNeeded which is why you need to run an existing command to trigger the updated plugin to be loaded.

There’s an example of how to set plugin load time here => rhino-developer-samples/rhinocommon/cs/SampleCsSharedData/SampleCsMain/SampleCsMainPlugIn.cs at 8 · mcneel/rhino-developer-samples · GitHub

Specifically this part:

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

Although I write it as public override PlugInLoadTime LoadTime => PlugInLoadTime.AtStartup;

I don’t think setting load time to AtStartup is best practice as it does increase Rhino’s load time – if your plugin is not always needed by users, or not needed immediately, it’s best to leave it to WhenNeeded and get into the habit of using an existing command to trigger load. I was definitely confused when I first started developing a plugin that the commands weren’t showing up, so if this is a development convenience thing you could setup a command that runs on startup when debugging through Visual Studio that will trigger your plugin to load.

Hope this helps!

1 Like

We do not recommend doing this, as it makes a slow-starting Rhino even slower.

@tobias.stoltmann - if you setup your launchSettings.json file as follows, then Rhino will automatically load your plug-in when debugging.

{
  "profiles": {
    "Rhino 8 - netcore": {
      "commandName": "Executable",
      "executablePath": "C:\\Program Files\\Rhino 8\\System\\Rhino.exe",
      "commandLineArgs": "/netcore",
      "environmentVariables": {
        "RHINO_PACKAGE_DIRS": "$(ProjectDir)$(OutputPath)\\"
      }
    },
    "Rhino 8 - netfx": {
      "commandName": "Executable",
      "executablePath": "C:\\Program Files\\Rhino 8\\System\\Rhino.exe",
      "commandLineArgs": "/netfx",
      "environmentVariables": {
        "RHINO_PACKAGE_DIRS": "$(ProjectDir)$(OutputPath)\\"
      }
    },
  }
}

Note, the RhinoCommon project wizard sets this up for you automatially.

– Dale

2 Likes