Grasshopper Plugin Development Mac C#

Hey guys,
I want to develop my first Grasshopper Plugin for Mac. I have never done this before. I am currently watching the large course from Long Nugyen, however, they use Mac and are using a Rhino Grasshopper Plugin Template for Visual Studio. Is there a similar template available for Mac? Or any sources how to start from scratch?

Best
Mxa

I think the same templates work for macOS. I tested on macOS my GH plugins that were written in Visual Studio on Windows.

found it in the Developer forum!

1 Like

I found the tutorial you linked decent enough for a quick start, but missing some fairly critical elements like making my components have icons. For icons, I found this forum post very helpful.

Could you tell me more about which elements missing from GH Component/Plugin tutorials such as Icons? :slight_smile:

For now there are some samples which might help fill the gaps.

I think it would be super helpful if the tutorial above included adding an icon. It took a fair leap to get there, when I think adding an icon to a training template project should be a 3-minute task.

I got there by

  1. adding an IconLoader.cs file, which provides a lil code that gets load the icon file just given the filename. Got this directly from the forum post I linked.
  2. adding my icon files inside Properties/Resources/
  3. Adding an ItemGroup to my project.csproj file with a wildcard so I don’t have to manually list all the png icon files. I can just drop them in the folder and I’m good to go.
  4. For each component, using a call to the IconLoader.GetIcon

It took me quite an effort to get all these things set up, and it would be great for the tutorial to include this (or for the template to just include these things with a sample icon file that a component uses). I accomplished these steps mainly using the forum post I linked above. But the steps aren’t concise and there’s a lot of extra steps not written.


Could you tell me more about which elements missing from GH Component/Plugin tutorials such as Icons?

Did I address your prompt? Thanks!

Very nicely thankyou, yes!
Was it just icons or was there anything else?

Adding this icon code into the template seems like the best approach to me.
I’ve ticketed myself to make sure this gets done
https://mcneel.myjetbrains.com/youtrack/issue/RH-86418/Add-Icon-Loader-to-GH1-Template

I think there is another thing I think would be good as part of the tutorial: Local installation.

From the tutorial, I know how to run my plugin in debug mode, so I can use my plugin when I launch Rhino/Grasshopper from VS Code. But how do I locally install it? Like, once my plugin gets working enough for my own use in an art project I’m working on, how do I just install the plugin “for good”, but without submitting to the grasshopper package distribution system, for which my plugin is either too niche, or is not mature enough?

I see instructions on how to submit my plugin to a repo for distribution to others, but I’m looking for the middle ground, and it would be cool to have those instructions as part of the tutorial.

I would additionally suggest a change for the VS toolkit for grasshopper plugins. When I run the command

dotnet new ghcomponent -n "arst"     

it makes a new file “arst.cs”, with some boilerplate code for a component. Nice! But, it doesn’t use the namespace or category as my other components.

It would be great for the dotnet command to pre-populate these, so I don’t forget. Thus, I mostly copy-paste another component instead of using this dotnet command (and because I am using the IconLoader method from that other thread, not what’s provided in the template. I would even suggest the IconLoader should just be standard, as it solves an annoying problem.).

I know this isn’t part of the tutorial, but it’s related to being new at plugin development, so I figured I’d ask for it here.

Thanks!

Great question. The latest templates also create Yak packages when you build and these can be drag dropped onto Rhino to install the plugins inside, this would then be permanently installed.

I’ll think about where to add this into the docs.

1 Like

This is perfect thank-you, always good to know where developers struggle so we can help :slight_smile:.

Hmm, I’ll have a look and see if this is possible, not sure if dotnet is smart enough.

I’ll add the IconLoader in r.e the ticket.

I have another request. I wish the template came with a launch configuration that just builds, but doesn’t launch Rhino. This would be helpful after I’m through a debugging stage and after I’ve locally installed my plugin, as a precursor to distribution.

Edit: To add some context, I’m using Visual Studio Code on MacOS, so I don’t have the “Build” menu that Visual Studio has on Windows.

I believe CMD + Shift + P and search Run Tasks you should have a build item.

You can also run dotnet build in the terminal

1 Like

Will you please help me a bit more with the local installation step? I see the /obj and /bin folders that got generated when I built, and inside I see .gha files. But I need yet a bit of coaching, please. Should I just copy the .gha file into my Components folder? (I would probably just make a symlink…) Or do I need more of the built files? Thanks!

Absolutely :slight_smile:

Debugging

For debugging you don’t need to do this, Rhino 8 + will load your .gha automatically.

Release

For Release, yes this is the place. Note that you’ll need to uninstall before debugging again however as GH will try to load both plugins.

It depends on your project. If you did not reference any libraries outside of RhinoCommon/Grasshopper/System you should just need the .gha

Thank you. In the /bin folder, I see a few dll files:

  • System.Text.Encodings.Web.dll
  • System.Text.Json.dll

The union of my using statements are these:

Grasshopper
Grasshopper.Kernel
Grasshopper.Kernel.Components
Grasshopper.Kernel.Data
Grasshopper.Kernel.Types
Rhino
Rhino.Collections
Rhino.DocObjects
Rhino.Geometry
Rhino.Geometry.Collections
Rhino.PlugIns
Rhino.Render.ChangeQueue
Rhino.Render.PostEffects
System
System.Collections
System.Collections.Generic
System.Configuration
System.Drawing
System.IO
System.Linq
System.Net.Sockets
System.Numerics
System.Reflection
System.Runtime.CompilerServices
System.Text
System.Text.Json
System.Threading
System.Threading.Tasks
System.Windows.Forms

I how do I know which need special treatment for local installation? (I’m also not entirely sure I need all of them, but that’s a me-problem).

Good questions. It’s all about references.

Nuget packages (inside your csproj).

If you reference nugets other than RhinoCommon/Grasshopper you’ll need to include those DLLs

Project References

If you create a project library and reference this you’ll need to include it.

These reference DLLs are easy to bundle when using Yak rather than sharing .gha’s

(I think) all System.Something dlls that are not nugets will be included by default with Rhino, so you don’t need to include them. e.g these 2, Rhino includes these, so there is no need to bundle them.

System.Text.Encodings.Web.dll
System.Text.Json.dll

Great, thank you. I have this for my references section in my .csproj file:

  <ItemGroup>
    <PackageReference Include="Grasshopper" Version="8.0.23304.9001" ExcludeAssets="runtime" />
    <PackageReference Include="System.Text.Json" Version="8.0.5" />
  </ItemGroup>

And I’m not referencing any other projects, it’s self-contained.

So I think I should just need just the .gha file. I’ll give it a whirl and report back.

Simply copying the .gha worked fine for me, thank you. I think I’m good for a while. I super appreciate your help :heart:

I’d think so yep.

Anytime. All great questions, keep 'em coming. Other users will find these answers for their issues too :slight_smile: