Comment on page
3.2: Basic Component Setup
The example in this section assumes that you have Visual Studio 2017 and the above mentioned GH add-on installed. In order to make things easy, the script will be analogous to that presented in section 2.4.2. Follow these steps to set up a project for creating a GH component which makes use of Karamba3D functionality:
- 1.Start Visual Studio and select âFile/New/Project . . . â from the main menu. A Window appears which lets you select from among different project types (see fig 3.2.1).
- 2.Go to the bottom of the window and set the name of the project to âTensionElimâ.Grasshopper loads plug-ins according to the alphanumeric order of their file-names. If a component intends to use Karamba3D functionality make sure its name comes after âKaramba3Dâ otherwise it will not be able to reference it.
- 3.Browse to a folder where your project shall be created using the âBrowseâ-button
- 4.Unhook the âCreate directory for solutionâ-option.
- 5.Select âVisual C#â from the right hand side tree-menu of installed templates. In case you want to script in VB select the corresponding entry. Double-click on âGrasshopper Add-Onâ in the middle part of the window (see fig. 3.2.1).
- 6.Another window appears that lets you configure the properties of the Grasshopper component.
- 7.You can now change the name, nick-name, category (e.g. âKaramba3Dâ) and subcategory (e.g. âExtraâ) under which the component appears inside Grasshopper â but they can also be changed later on.
- 8.In case that the path to Grasshopper, RhinoCommon or Rhino appears in red click on the â...â button and point to the right directory.
- 9.Press âFinishâ. The GH component wizard now creates the project âTensionElimâ which already contains the basic frame for a GH component.

Fig. 3.2.1: Select Grasshopper Add-On from the templates available for C# or VB.
Select âView/SolutionExplorerâ to get a list of all files that belong to the project. The file âAssem- blyInfo.csâ in the âPropertiesâ-folder of the SolutionExplorer lets you set the title of your assembly, a description, a copyright message and so on. The folder âReferencesâ lists all those assemblies which the component borrows functionality from. By default these are âGH_IOâ, âGrasshopperâ, âRhinoCom- monâ and some system assemblies. In âTensionElimComponent.csâ you will find the definition of the class âTensionElimComponentâ. It inherits its functionality from the class âGH_Componentâ and thus lets you define the properties and behavior of the component later visible in GH.
As a first try right-click on the project âTensionElimâ and select âBuildâ from the context menu. If all goes well the file âTensionElim.ghaâ gets created in the âbinâ-folder of the Visual Studio project. Copy this file to one of the places where Grasshopper looks for plug-ins at start-up. Among others these two choices exist:
- The âLibrariesâ-folder of Grasshopper. It sits in the user-directors under âC:/Users/Username/App- Data/Roaming/Grasshopper/Librariesâ an can be accessed from within Grasshopper via the menu âFile/Special Folders/Components Folderâ. The advantage of putting a plug-in there is, that a user does not need any special privileges to install it.
- The âPlug-insâ-folder of Rhino to be found at e.g. âC:/Program Files/Rhino6â when working with Rhinoceros 6. Placing a plug-in there makes it accessible to all users of the computer. The disadvantage of this file location lies in the fact that one needs to have admin-rights to install a file there.
Karamba3D lives in the âPlug-insâ-folder of Rhino. So plug-ins which reference its functionality need to be placed there as well.
In order to avoid the manual copying of the â.ghaâ-file you can setup a post-build-event in the Visual Studio Project settings â this makes debugging more comfortable: Right-click on the project entry in the Solution Explorer, select âPropertiesâ, choose âBuild Eventsâ from the left-hand tabs, and add in one line at the end of the âPost-build event command lineâ text window:
Copy ââ$(TargetDir)$(ProjectName).ghaââ
ââC:\Users\YourUserNameHere!!\App Data\Roaming\Grasshopper\Libraries\$(ProjectName).ghaââ
or
Copy ââ$(TargetDir)$(ProjectName).ghaââ
ââC:\ProgramFiles\Rhino6\$(ProjectName).ghaââ
In case you use Rhino 6. Do not forget to replace âYourUserNameHere!!â by your user name in case of option one. For option one has to assume ownership of of the Rhino âPlug-insâ-folder and acquire write-rights otherwise the copy command fails.
Upon starting (or restarting) GH there should now show up a new icon in the category and subcategory previously provided by you in the constructor of the âTensionElimComponentâ-class (see fig. 3.2.2). As yet there is no image attached to the new button. Therefore it shows up as a circle filled with black and white rectangles. Take a look at the function âIconâ of the âTensionElimComponentâ- class to change this if you want. You will also notice that the new component has neither input- nor output-plugs.

Fig. 3.2.2: First step: Custom component without input- or output-plugs.