Sorry for the major delay on posts to the sherpa blog. I’ve been engrossed in several projects like some Rhino plug-ins. One thing that is severely undocumented is the process of migrating a Rhino 3 plug-in to Rhino 4. A while back I contacted Dave Fugier of McNeel & A about accomplishing this, and he naturally directed me to RhinoWiki.
There really are only two good articles on their plug-in site that discuss the migration process:
It’s up for you to connect the dots. Ugh. I hope I can clear up some of the confusion.
Before we begin, one thing to understand about Rhino Plugin development is that it’s totally different than Rhinoscript. Rhinoscript uses a Visual Basic-ish language and is a simple code to automate tasks. The file extension is .rvb and these are saved as scripts. Rhino Plugins are .rhp files that are compiles with an outside application like Visual Studio. Then this .rhp file is saved with your other plugins (usually c:\program files\rhino x\plugins\) and installed in your Rhino Plugin Manager. These plug-ins are written in c++ and are a LOT harder than just cranking out a measly Rhinoscript file. You gotta have your programming chops.
Speaking of programming plugins, you’ll need to install the SDK (Software Development Kit). This is a set of tools that you’ll use to program your Rhino rhp. Its free and can be downloaded from the Rhino site. This SDK installs next your real version of Rhino and has a special installation of Rhino they call the “debug version.” In order to run this debug version, run a search on your hard drive for “Rhino_d.exe”. It’s sort of hidden and if you are using a 64-bit computer, you’ll notice that your SDK will install in the non-x64 Program Files, while the real Rhino version may install in the x64 directory. One thing to note, you cannot use the SDK debugging version of Rhino unless your software releases match. A while back, I ran into a problem where my real version of Rhino had a different release number than the debug version of Rhino.
With your SDK installed and your old Rhino 3 plugin just itching to hang out in Rhino 4, you’ll need to install Visual Studio 2005. BTW, Visual Studio 2005 (VS05) is a program authoring application that allows a user to write in several different languages. For Rhino plugins, you’ll need to configure your session of VS05 for c++, which is really easy to do when you install the app. Just follow the instructions on the screen. One thing to note for Rhino 4, all plugin coding must be completed in VS05, and not in V6 or other. It’s just the way it works. And it needs to be the complete version.
If you have a Rhino 3 plug-in, you can’t just open it up in Visual Studio and expect it to compile. First off, you’re probably wondering how you can open the .rhp file you have in VS05. If you are wondering this, then it’s safe to assume that you didn’t originally author the R3 plugin. The .rhp is the outcome of programming in VS05. In order to work in VS05, you’ll need several header, cpp, def and resource files in c++. So if you don’t have those files, you’ll need to contact the original author and get them.
But let’s assume you have all the .cpp’s, .h’s, .def’s, and so on, and they are assembled into a VS05 project (usually a .dsp file for VC6, .sln for VS05). You can’t just open this up and hit “Build Project.” Instead you’ll need to do the “Migrating Plugin Projects” process described on Rhino’s wiki site, as follows: (link)
As mentioned above, to build plug-ins for Rhino 4.0, you will need to use a different compiler – Visual C++ 2005. There have also been a number of changes in the project settings (e.g. compiler, linker, etc) required by V4 plug-ins. Because of these changes, we recommend that you do not try to migrate V3 plug-in projects to V4 by just opening Visual Studio 6.0 projects or workspaces (DSP, DSW) in Visual Studio 2005.
Instead, we recommend that you run the new plug-in project wizard that comes with the V4 SDK to build new plug-in projects. Then, copy your project specific code from your V3 projects to your new V4 projects. In doing this, you can be assured that your compiler settings will agree with what is required by Rhino 4.0.
Well that’s awesome. First off, don’t make it harder than it seems. As you can read above, they say “run the new plug-in project wizard that comes with the V4 SDK,” which leads some to believe that you should search the SDK directories for this “wizard.” For some reason, Rhino developers thru into the SDK some html project wizard that is a bit confusing. Forget about that. Just open up VS05 and create a new project. That’s the wizard (in VS05). Then in that wizard, pick the Rhino tools, the type of plugin and so on.
Once the VS05 project is established you can copy over your old Rhino 3 plugin code. For the most part, it will be a direct transfer. However, the main bug I encounter is the Unicode strings issue. Rhino 4 uses the Unicode format for their global strings. If your old code used non-unicode strings, you’ll need to use the wchar_t type for most of your strings. Also, by prefacing your string with the “L” character, you’ll quickly eliminate the bugs until your compiling is complete. BTW, you can compile your project by clicking “Build NameOfProject.”
If all goes well, you’ll get a rhp file in your target directory. If you don’t know where that is, it’s in the General tab when you right-click > properties on the top level of the project in the Solution Window. You can test out your plug-in by installing it in the Plug-in Manager in your “debug version” of Rhino. Then go back into VS05 and use the command “Attach to Process” to run the plug-in script. “Attach to Process” will let you look at all the processes running at that moment. Near the bottom will be Rhino_d, which is your debug Rhino that has the plug-in previously installed. Put in a few stops in the code and run your Rhino plugin either by running the command or import/export tools, whichever corresponds to your plugin type. As long as your plugin code matches the installed code, it will cycle thru the VS05 editor and let you debug it. However, if you installed an rhp and then changed the code in VS05, you’ll need to recompile the rhp in VS05, uninstall the original rhp in Rhino_d, and then reinstall the new rhp in Rhino_d. Or else you’ll get a message in VS05 stating that your codes don’t match.
That’s it for now. Hopefully this clears up some gaps and gets you rolling with rhp’s.