In order to complete this tutorial, you will need to have the following installed on your system:
From a user’s standpoint, a Rhino plug-in is a software module that extends the functionality of Rhino by adding new commands, features, or capabilities. From a programmer’s perspective, a Rhino plug-in is a regular Windows Dynamic Link Libraries, or DLLs that links with the Rhino SDK libraries.
Examples of Rhino plug-ins include:
There are five different types of Rhino plug-ins.
Note: File Import, File Export, Custom Rendering and 3-D Digitizing plug-ins are all specialized enhancements to the General Utility plug-in. Thus, all plug-in types can contain one or more commands.
The Rhino SDK includes a Visual Studio Project Wizard. The wizard program generates the code a functioning plug-in. Follow these steps to build the plug-in.
Launch Visual Studio 20100 and select File → New → Project…. From the New Project dialog, select the Rhino 5.0 Plug-in template from the list of installed templates.
Type the project name as shown. You can enter a different name if you want. The wizard uses the project name when it creates files and classes. If you enter a different name, your files and classes will have a name different from that of the files and classes mentioned in this tutorial.
Don’t forget to choose a location to store the project. When finished, click the OK button.
Upon clicking OK, the Overview page of the Rhino 5.0 Plug-In Wizard dialog will appear. This page gives you an overview of the type of project that the wizard is going to create. By default, the wizard will do the following:
If you are satisfied with the default settings, just click the Finish button. If you want to change any of these settings, just click the Next button.
The Plug-in Settings page allows you to modify a number of settings used by the wizard when generating the plug-in source code.
For this tutorial, just accept the default settings. Click the Finish button, and the wizard begins to generate your plug-in project’s folders, files, and classes. When the wizard is finished, look through the plug-in project using Visual Studio’s Solution Explorer. The following files are of interest:
With Visual Studio 2010, a project can target a different version of the Visual C++ libraries and compiler. This is done by configuring the project use a different Platform toolset.
Reviewing the above image, you can see that the Rhino 5 plug-in project wizard configures 32-bit builds to use the v80rhinos platform toolset, which equates to using Visual Studio 2005's libraries and compiler. This platform toolset configuration is installed on your system by the Rhino C++ SDK Installer.
If you change the active platform from Win32 to x64, you will see that 64-bit builds will use v100, or Visual Studio 2010.
The advantage that platform toolsets provide is that they enable you to take advantage of the IDE enhancements in Visual Studio 2010 while you continue to use an older version of the Visual C++ libraries and compiler.
The Rhino plug-in wizard, in addition to generating code, creates a custom project file for your plug-in. This file, Test.vcxproj, specifies all of the file dependencies together with the compile and link option flags.
Before we can build our project, we need to fill in the Rhino plug-in developer declarations. These declarations will let the user of our plug-in know who produced the plug-in and where they can support information if needed. Open TestPlugIn.cpp and modify the following lines of code, providing your company name and other support information.
RHINO_PLUG_IN_DEVELOPER_ORGANIZATION( L"My Company Name" ); RHINO_PLUG_IN_DEVELOPER_ADDRESS( L"123 Developer Street\r\nCity State 12345-6789" ); RHINO_PLUG_IN_DEVELOPER_COUNTRY( L"My Country" ); RHINO_PLUG_IN_DEVELOPER_PHONE( L"123.456.7890" ); RHINO_PLUG_IN_DEVELOPER_FAX( L"123.456.7891" ); RHINO_PLUG_IN_DEVELOPER_EMAIL( L"firstname.lastname@example.org" ); RHINO_PLUG_IN_DEVELOPER_WEBSITE( L"http://www.mycompany.com" ); RHINO_PLUG_IN_UPDATE_URL( L"http://www.mycompany.com/support" );
When finished, delete the following line of source code as the #error directive will prevent the project from building.
#error Developer declarations block is incomplete!
If you do not delete this line, the plug-in will build. You are now ready to build the project by picking Build Test from the Build menu. If the build was successful, a plug-in file named Test_d.rhp is created in the project’s Debug folder.
From Visual Studio, select Debug → Start Debugging. This will load Rhino. The version of Rhino that is launched depends on the configuration that you build. The wizard adds the following configurations to your project.
For this tutorial, build the Debug configuration.
From within Rhino, select Tools → Options. Navigate to the Plug-ins page under Rhino Options and install your plug-in. Note, being that the debug version of Rhino will only load debug plug-ins, no other plug-ins will show up in the list.
Once your plug-in is loaded, close the options dialog and run your Test command. You have finished creating your first plug-in.