It is presumed you already have the necessary tools installed and are ready to go. If you are not there yet, see Installing Tools (Mac).
HelloRhinoCommon
We will use the Rhino Visual Studio Extension to create a new, basic, command plugin called HelloRhinoCommon.
We are presuming you have never used Visual Studio for Mac before, so we’ll go through this one step at a time.
File New
- If you have not done so already, launch Visual Studio for Mac.
- Navigate to File > New Project…
- A New Project wizard should appear. In the left column, find the Other > Miscellaneous section. Under General, select the RhinoCommon Plug-In template…
- Click the Continue button.
- You will now Configure your new project. For the purposes of this Guide, we will name our demo plugin HelloRhinoCommon. Fill in the Project Name field. Leave the other defaults alone.
- Click the Continue button.
- Browse and select a location for this plugin on your Mac.
- Click the Create button. Note: You don’t have to create a .git repository for this demo.
- A new project called HelloRhinoCommon should open…
Boilerplate Build

- Before we do anything, let’s build and run HelloRhinoCommon to make sure everything is working as expected. We’ll just build the boilerplate Plugin template. Click the large Build > Run (play) button in the upper-left corner of Visual Studio for Mac…
- Rhinoceros launches. Create a New Model…
- Enter the HelloRhinoCommonCommand command. Notice that the command autocompletes…
- The HelloRhinoCommonCommand command begins and prompts you…
- Notice there is also a command status in Rhino’s command history area when the command begins…
- Also note there is a command status in Rhino’s command history area when the command ends.
- Quit Rhinoceros. This stops the session. Go back to Visual Studio for Mac. Let’s take a look at the…
Plugin Anatomy
- Use the Solution Explorer to expand the Solution (.sln) so that it looks like this…
- The HelloRhinoCommon project (.csproj) has the same name as its parent solution…this is the project that was created for us by the RhinoCommon Plugin template wizard earlier.
- Dependencies: Just as with most projects, you will be referencing other libraries. The RhinoCommon Plugin template added the necessary references to create a basic RhinoCommon plugin.
- EmbeddedResources: This is where you would place any image assets you want to ship with your plugin. The RhinoCommon Plugin template added an icon file with a default boilerplate icon.
- Properties contains the AssemblyInfo.cs source file. This file contains the meta-data (author, version, etc), including the very-important
Guid
, which identifies the plugin. - .gitignore is a file added by the git version control system. Feel free to ignore this for now.
- HelloRhinoCommonPlugin.cs is where this template plugin derives from Rhino.Plugins.Plugin and returns a static Instance of itself.
- HelloRhinoCommonCommand.cs is where the action is. Let’s take a look at this file…
Make Changes
-
Open HelloRhinoCommonCommand.cs in Visual Studio for Mac’s Source Editor (if it isn’t already).
-
Notice that
HelloRhinoCommonCommand
inherits fromRhino.Commands.Command
…public class HelloRhinoCommonCommand : Rhino.Commands.Command
-
…and overrides one inherited property called
EnglishName
…public override string EnglishName { get { return "HelloRhinoCommonCommand"; } }
-
All Rhino commands must have a
EnglishName
property. This command name is not very accurate. We know from running the boilerplate code that this command prompts the user to draw a line. Let’s rename the command to HelloDrawLine:public override string EnglishName { get { return "HelloDrawLine"; } }
-
Further down, notice that
HelloRhinoCommandCommand
overrides theRunCommand
method:protected override Result RunCommand (Rhino.RhinoDoc doc, RunMode mode)
-
All Rhino commands must have a
RunCommand
method. As you can see, this is where the action happens. Let’s create an intermediary line object that we can feed to theAddLine
method. Find the spot inRunCommand
after the user has been prompted to select two points. Type in…Rhino.Geometry.Line line1 = new Line (pt0, pt1);
-
Notice that - as you type - Visual Studio for Mac uses IntelliSense, just like Visual Studio for Windows (and many other editors). Now, feed
line1
as an argument to thedoc.Objects.AddLine
method…doc.Objects.AddLine (line1);
-
Now that we have a line of our own, let’s examine it…
Debugging
- Set a breakpoint on line1 59 of HelloRhinoCommonCommand.cs. You set breakpoints in Visual Studio for Mac by clicking in the gutter…
- Build and Run. Run HelloDrawLine in Rhino. Create the two points…as soon as you do, you should hit your breakpoint and pause…
- With Rhino paused, in Visual Studio for Mac switch to the Locals tab. In the list, find the
line1
object we authored. Click the dropdown arrow to expand the list of members online1
. Ourline1
is aRhino.Geometry.Line
this class has aLength
property…
- Continue Executing in Rhino by pressing the Play button in the upper navigation menu of Visual Studio for Mac…
- Control is passed back to Rhino and your command finishes. Quit Rhino or Stop the debugging session.
- Remove the breakpoint you created above by clicking on it in the gutter.
- Now, let’s use the
Length
value to report something to the user. Near the very end ofRunCommand
, add the following line…
RhinoApp.WriteLine ("The distance between the two points is {0}.", line1.Length);
- Build and Run. Run
HelloDrawLine
in Rhino yet again (create the two points…). Rhino now reports the length of the line you created. However, this is not very clean. - Quit Rhino to Stop the debugging session once more.
- Let’s add a unit system and be explicit about what we’re reporting…
RhinoApp.WriteLine ("The distance between the two points is {0} {1}.", line1.Length, doc.ModelUnitSystem.ToString().ToLower());
- Build and Run again. Now we’re reporting the length of the line we created with the document’s unit system (
doc.ModelUnitSystem
) with the proper case (ToLower()
). Much better.
DONE!
Well, we could go on and on - line1
was never necessary, we could have just used pt0.DistanceTo(pt1).ToString()
, etc. - but that is beside the point:
Congratulations! You have just built your first RhinoCommon plugin for Rhino for Mac. Now what?
Next Steps
You’re using RhinoCommon, so this plugin will actually run on both platforms. Check out the Your First Plugin (Cross Platform) guide.
Related topics
Footnotes
-
Line numbers in Visual Studio for Mac can be enabled and disabled in Visual Studio > Preferences… > Text Editor section > Markers and Rulers entry > check Show line numbers. ↩︎