Your First Component (Mac)
This guide walks you through your first Grasshopper component for Rhino for Mac using RhinoCommon and Xamarin Studio.
Grasshopper for Mac only exists in the RhinoWIP until the next major version of Rhino for Mac is released.
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:
- 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).
- Install Xamarin Studio. Instructions can be found in the Installing Tools (Mac) guide.
- Install the Rhino Xamarin Add-in. Instructions can be found in the Installing Tools (Mac) guide in the Install the Rhino Add-in section.
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.
- If you have not done so already, launch Xamarin Studio.
- Navigate to File > New > Solution…
- A New Project wizard should appear. In the left column, find the Other > Miscellaneous section. Under General, select the Grasshopper Component template…
- Click the Next button.
- 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…
- Click the Create button.
- A new solution called HelloGrasshopper should open…
- 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…
- Rhinoceros launches. Create a New Model…
- Enter the ExplicitHistory command. Notice that your new component is listed a loaded by Grasshopper…
- Go to the Curve tab in Grasshopper and you should see a new blank icon for your new component…
- Drag this component on to the Grasshopper canvas to verify that it is working…
- Quit Rhinoceros. This stops the session. Go back to Xamarin Studio. Let’s take a look at the…
- Use the Solution Explorer to expand the Solution (.sln) so that it looks like this…
- 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.
- 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.
- 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.
- GH_IO is used for reading and writing Grasshopper definitions.
- Grasshopper is the Rhino for Mac main grasshopper DLL. Classes in this DLL are subclassed and used by your custom component.
- Rhino.UI is the Rhino-specific User Interface (UI) library associated with…
- RhinoCommon is used by your component to work with all of the geometry defined in Rhino.
- 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).
- 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.
- Properties contains the AssemblyInfo.cs source file. This file contains general information about your component.
- HelloGrasshopperComponent.cs is where a custom
Grasshopper.Kernal.GH_Componentsubclass is defined. Your project may contain multiple subclasses of GH_Component if you want to ship multiple components in a single gha.
- HelloGrasshopperInfo.cs defines general information about this gha.
- Set a breakpoint on line1 103 of HelloGrasshopperComponent.cs. You set breakpoints in Xamarin Studio by clicking in the gutter…
- 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…
- 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…
- Continue Executing in Rhino by pressing the Play button in the upper navigation menu of Xamarin Studio…
- 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.
Congratulations! You have just built your first Grasshopper component for Rhino for Mac. Now what?
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.
- Navigate to File > New > File…
- 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”…
- 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
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. ↩