Your First Component (Mac)

This guide walks you through your first Grasshopper component for Rhino for Mac using RhinoCommon and Xamarin Studio.

Prerequisites

Grasshopper for Mac only exists in the RhinoWIP until the next major version of Rhino for Mac is released.

WARNING

Early-adopters: the following steps will NOT work with the currently released Rhinoceros (5.x.x). You will need to use WIP version of Rhinoceros.

Due to this, there are a few additional steps that need to be taken to install all of the tools needed to develop components. You will need to do the following:

  1. Install the latest RhinoWIP. The WIP can be safely installed along side the stable release of Rhino for Mac (but they cannot be run simultaneously).
  2. Install Xamarin Studio. Instructions can be found in the Installing Tools (Mac) guide.
  3. Install the Rhino Xamarin Add-in. Instructions can be found in the Installing Tools (Mac) guide in the Install the Rhino Add-in section.

HelloGrasshopper

We will use the Rhino Xamarin Add-in to create a new, basic, Grasshopper component called HelloGrasshopper.

If you are familiar with Visual Studio or Xamarin Studio, these step-by-step instructions may be overly detailed for you. The executive summary: create a new Solution using the Grasshopper Component template, build and run, and then make a change.

We are presuming you have never used Xamarin Studio before, so we’ll go through this one step at a time.

File New

  1. If you have not done so already, launch Xamarin Studio.
  2. Navigate to File > New > SolutionFile New Solution
  3. A New Project wizard should appear. In the left column, find the Other > Miscellaneous section. Under General, select the Grasshopper Component template… New Project
  4. Click the Next button.
  5. You will now Configure your new project. For the purposes of this Guide, we will name our demo component HelloGrasshopper. Fill in the Project Name field. Browse and select a location for this component on your Mac… Project Configuration
  6. Click the Create button.
  7. A new solution called HelloGrasshopper should open… HelloRhinoCommon Solution

Boilerplate Build

  1. Before we do anything, let’s build and run HelloGrasshopper to make sure everything is working as expected. We’ll just build the boilerplate Component template. Click the large Build > Run (play) button in the upper-left corner of Xamarin Studio… Play Button
  2. Rhinoceros launches. Create a New ModelNew Model Button
  3. Enter the ExplicitHistory command. Notice that your new component is listed a loaded by Grasshopper… HelloGrasshopper Loaded
  4. Go to the Curve tab in Grasshopper and you should see a new blank icon for your new component… Curve Tab
  5. Drag this component on to the Grasshopper canvas to verify that it is working… Command Starts
  6. Quit Rhinoceros. This stops the session. Go back to Xamarin Studio. Let’s take a look at the…

Component Anatomy

  1. Use the Solution Explorer to expand the Solution (.sln) so that it looks like this… Solution Anatomy
  2. The HelloGrasshopper project (.csproj) has the same name as its parent solution…this is the project that was created for us by the Grasshopper Component template wizard earlier.
  3. References: Just as with most projects, you will be referencing other libraries. The Grasshopper Component template added the necessary references to create a basic Grasshopper component.
  4. Eto is the cross-platform User Interface (UI) library Rhino uses. If you examine its properties, you will notice it comes bundled as part of Rhino for Mac.
  5. GH_IO is used for reading and writing Grasshopper definitions.
  6. Grasshopper is the Rhino for Mac main grasshopper DLL. Classes in this DLL are subclassed and used by your custom component.
  7. Rhino.UI is the Rhino-specific User Interface (UI) library associated with…
  8. RhinoCommon is used by your component to work with all of the geometry defined in Rhino.
  9. System, System.Core, and System.Drawing are .NET foundational libraries…in this case, we are referencing the Mono versions of these libraries (on Windows, these references will point to the canonical, Microsoft-provided, versions).
  10. Packages is used the the NuGet package-manager. There are no referenced packages in this boilerplate project, but note that Xamarin Studio supports NuGet, just like Visual Studio does.
  11. Properties contains the AssemblyInfo.cs source file. This file contains general information about your component.
  12. HelloGrasshopperComponent.cs is where a custom Grasshopper.Kernal.GH_Component subclass is defined. Your project may contain multiple subclasses of GH_Component if you want to ship multiple components in a single gha.
  13. HelloGrasshopperInfo.cs defines general information about this gha.

Debugging

  1. Set a breakpoint on line1 103 of HelloGrasshopperComponent.cs. You set breakpoints in Xamarin Studio by clicking in the gutter… Set a breakpoint
  2. Build and Run. Drag one of your new components on to the Grasshopper canvas…as soon as you do, you should hit your breakpoint and pause… Hit a breakpoint
  3. With Rhino paused, in Xamarin Studio switch to the Locals tab. In the list, you can inspect all of the values for the variables in your function…
    Locals panel
  4. Continue Executing in Rhino by pressing the Play button in the upper navigation menu of Xamarin StudioContinue Executing
  5. Control is passed back to Rhino and your command finishes. Quit Rhino or Stop the debugging session.
  6. Remove the breakpoint you created above by clicking on it in the gutter.

DONE!

Congratulations! You have just built your first Grasshopper component for Rhino for Mac. Now what?


Next Steps

Adding components

A single gha can contain more than one GH_Component derived class (and commonly does). The Xamarin Studio has support for adding more custom components to your project.

  1. Navigate to File > New > FileFile New Solution
  2. A New File wizard should appear. In the left column, find the Rhinoceros section. This should give you the ability to select an “Empty Grasshopper Component”… New Project
  3. After deciding on a name for the component click the New button.

This article is focused on initial setup and debugging a Grasshopper component in Rhino for Mac. For further reading on customizing your component please see: TODO - provide good reference for component development


Footnotes

  1. Line numbers in Xamarin Studio can be enabled and disabled in Xamarin Studio > Preferences… > Text Editor section > Markers and Rulers entry > check Show line numbers