Basic C# plugin help

Hi all,
I’ve developed a rhino toolbar for my company - pretty basic stuff, mostly links to standards and resources.
I was positively surprised by how easy that was. The problem I’m having now is the deployment. My understanding is that I should develop a C# plugin and deploy this with an installer. My knowledge of C# and Visual studio is very limited. Would anyone be so kind to guide me through the necessary steps to do this?
I’ve already followed this guide here:

which felt like a good start even if I can’t figure out where or how to bind the toolbar to the plugin.
Also found this:

but I have no idea where I should place that code. :sob:

If I understand correctly, you have created a .RUI file for the toolbar.
In that case, you can distribute just that file to your colleagues, who can start using it by dragging the RUI file onto Rhino I think, or by importing it in the Options > Toolbars dialog.

That’s right, but it would be preferable to have .rhi file.
That way it could be installed as a package when we install Rhino from software center.
It also could be handy to have a plugin because we might add a few rhinocommon functions in the future. Most importantly, it would be nice to be able to release new versions of the plugin and the ability to overwrite the toolbar which is the point where I’m stuck at, right now.

Alright, coming back to you original question, how to bind the toolbar, and where to place the code.

  1. Binding the toolbar is done by giving it the same name as the plug-in (except for the file extension) and putting in the same directory as the plug-in. The upon installation rhino will figure out what to do with it.

  2. Where to put the code. The code on the page is optional and only needed if you want to update the toolbar after it was originally deployed. The code goes in your plug-in class source file.

Hi Menno, Thanks for your help.
For point 1 I’m ok. It would be amazing to have updates working too!

This is probably super basic stuff but I just can’t figure it out :frowning:
Is the class source file already somewhere in the template or would I have to create one?

No worries, the class source file is created once you use the template.

If you look at the page you referred to, Your First Plugin (Windows) with C#, you see a screenshot just above the heading “Boilerplate Build”. In that screenshot from Visual Studio, you see the plug-in project and under that “HelloRhinoCommnCommand.cs” and “HelloRhinoCommonPlugIn.cs”. Your files may differ in name if you used a different plug-in name, but the file ends in “…PlugIn.cs”. The file extension (.cs) is for C# (C-sharp), the programming language used.

It is also explained a bit lower in the section “Plug-in anatomy”, where item 11 is the plug-in source file.

1 Like


there’s a lot of red-underlined code …that cant be good

1 Like

try moving that code above this closing brace

image

no change

Am I missing something?

Go to the top of the file and add a using System.Text; similar to the other using statements you will find there. After you do this, you should see the squiggles disappear from the line that creates a new StringBuilder().

This is because the StringBuilder class resides in the System.Text namespace, and you have to tell the compiler where to find it, either by adding a using statement, or (and you can try this before adding the using statement) by fully-qualifying the name, by writing new System.Text.StringBuilder().

After you try that, then note that you can hover your mouse over one of those errors with squiggles, and be shown a popup that contains some possible suggestions for how to fix them, and in most cases here, it looks like it will suggest to do similar to what I described above for System.Text.StringBuilder.

2 Likes

Thanks so much for your help,
Turnes out it wasn’t so basic, at least not for me.
By following @jdhill suggestions I’m down to 7 errors from 12.
Most were missing namespaces

using Rhino.PlugIns;
using System.IO;
using System.Text;

the remaining are

On Load
Settings
Version
Assembly

What are these?
missing classes?

It is difficult to say what is going on, not being able to see the project or code, so let’s just start from the beginning. I will be using vs2019:

image

From the link in your first post, I installed the Rhino sdk tools, since I did not have these installed for my vs2019:

From the linked page I followed the link for installing the RhinoCommon templates:

That link led here, and I clicked the download button:

This downloaded a .vsix file, so I made sure vs2019 was not running, and double-clicked the .vsix file to install it:

image

The installer ran successfully, I started vs2019, and chose Create a new project:

I then browsed to the C# RhinoCommon plugin for Rhino 7 project type and clicked Next:

I set up the project as desired and clicked Create:

The extension then showed a dialog with some more options:

Looks ok, so clicked Finish, and I got my solution:

image

Clicking main menu > Build > Build Solution, the solution built fine:

image

By default the main plugin file looks like this:

Overriding the OnLoad method looks like this:

Inside of OnLoad, we can replace the code with that from Dale’s example:

We have some errors, which will be taken care of by two using statements:

With those errors fixed, the solution once again builds successfully:

image

So, try following through these steps, and you can then move forward from there, once you have it working.

2 Likes

I’ve been using 2022 :thinking:

I think you have composed the perfect “Compile a Rhino plugin for dummies” guide
Thanks!!!
No errors on VS2019.
I’ll have another go with 2022 to see if I had missed something.

when I ran the vsix, it only wanted to install for vs2019, even though I have 2017/19/22 installed, so you may have to use some other method of getting the plugin templates on 2022 – the installing tools page shows a different way, using the extension manager

If you’re looking for more C# plug-in writing info I have done 5 livestreams here

The companion literate example code is at https://jesterking.github.io/rhics/jesterLiveCode/jesterLiveCode.html with its code repository at GitHub - jesterKing/rhics: Literate Programming Rhino C# Plug-ins.

Note, here I don’t use wizards though, but once you have set up your system I hope the videos help in working through creating a plug-in if you plan on writing commands for Rhino :slight_smile:

2 Likes

No trouble with installing rhinocommon Rh7 extension, just went to menu> Extensions> extension manager.
Turnes out your first suggestion on fixing the indentation was spot on. I just had to move two braces inward not just one. :person_facepalming:t4:

Thanks @nathanletwory,
seems very clear and easy to follow.

1 Like