Site Tools


Simple VB.NET Plug-In

.NET

Version: Rhino 3 and Rhino 4
Summary: How to create a basic Rhino plug-in with VB.NET. Discusses each of the major components that go into creating a plug-in.

Sometimes the hardest part to learning a new subject is the very first step. This article shows how to create a simple Rhino plug-in with VB.NET using the Rhino.NET SDK.

Part 1

Step 1 - Required tools

To develop Rhino plug-ins with VB.NET, you need the following:

Rhino 3

Latest build of the Rhino.NET SDK.

A VB.NET compiler. The Rhino.NET SDK is tested to work with Microsoft VB.NET 2003, but you should be able to use VB.NET 2002 or the freeware SharpDevelop

Rhino 4

A VB.NET compiler that will compile using Microsoft .NET 2.0. This includes VB.NET 2005 or SharpDevelop 2.0.

Step 2 - Create a plug-in with the .NET plug-in wizard

(This step requires VB.NET) Rhino 3.

After you have installed all of the software items in Step 1, open VB.NET and select New Project… from the File menu. Select the Rhino Utility Plug-In icon as shown below. I set my project name to “FirstPlugIn” and saved it to “C:\Samples” on my computer.

Rhino 4

Download and install the Visual Studio project wizards. Open VB.NET and create a new project. Rhino Plug-In should be one of the optional project types.

After you click OK, the project wizard creates a new Rhino.NET plug-in project for you.

Step 3 - Build your Rhino.NET plug-in

Now that you have a simple project created by the wizard, click on the Build solution… menu item in the Build menu. This creates a Rhino.NET plug-in (also known as a .NET assembly.) The file extension for your plug-in will be .DLL and will be located in the bin directory for your project.

Step 4 - Run your Rhino.NET plug-in

Rhino 3

Start up Rhino and execute the DotNetManager command. This will pop up the .NET plug-in manager dialog. Click the Load Plug-In button and select the plug-in dll that you just created. If you were successful, the dialog will show your loaded plug-in and its associated command.

Rhino 4

Start up Rhino and execute the PlugInManager command. Click the Install… button and select the plug-in dll that you just created. If you were successful, the dialog will show your loaded plug-in.

Now close the dialog and run your VB.NET command. The command name will be the same as the your project name. In my case, my VB.NET command is called “FirstPlugIn”. The command will run and tell you that it is under construction.

VB.NET

Note: Discusses the source code and project settings for a simple VB.NET plug-in created with the project wizard.

Part 1 of this article showed how to create and run a VB.NET plug-in using the project wizard. Getting the plug-in to run is great, but what is really going on? This article covers the project settings and source code that are “auto-magically” created with the Rhino.NET Utility Plug-In project wizard.

Let's examine just what the project wizard for Rhino.NET Utility plug-ins created. I will refer to the sample project that you can download at the top of this article. This example is an unmodified VB.NET Rhino plug-in project generated with the wizard.

VB.NET

The other important item to look at in the project properties dialog is the Debugging item under the Configuration Properties folder. Since this is a class library project, it does not start and run on its own. To debug the plug-in, Rhino has to be running so the Start Action is set to Start external program and rhino3.exe (or rhino4.exe) is specified as the application.

Close the project properties dialog and expand the References node for the tree control in the Solution Explorer (or click on References tab in VB.NET 2005). You'll notice that there is a reference to Rhino3_DotNET (or Rhino_DotNET in Rhino 4). This is the Rhino.NET SDK and it contains all the class and function information for Rhino.NET. If you were creating a Rhino.NET plug-in without the project wizard, you would need to add this as a reference by clicking on Add Reference… under the Project menu. Make sure the .NET tab is active and click on the Browse… button. The Rhino.NET SDK is named “Rhino3_DotNET.DLL” or “Rhino_DotNET.DLL” and is located in Rhino's System directory. Select this file and click OK. Make sure that the properties for the Rhino3_DotNet reference have Copy Local set to false.

Note: Project references to Rhino3_DotNET appear to be stored as absolute paths to the DLL. If you open a project from someone else, most likely your path to this DLL than what was set on the computer where the project originated from. To fix this, remove the reference to Rhino3_DotNET and add it back in using the steps outlined in the previous paragraph.

AssemblyInfo.vb

This file contains several attributes that are associated with the plug-in.

 Imports System
 Imports System.Reflection
 Imports System.Runtime.InteropServices
 ' General Information about an assembly is controlled through the following
 ' set of attributes. Change these attribute values to modify the information
 ' associated with an assembly.
 ' Review the values of the assembly attributes
 <Assembly: RMA.Organization("My Oranization Name")>
 <Assembly: RMA.Address("123 Developer Lane" & Vbcrlf & "Developerville USA")>
 <Assembly: RMA.Country("United States")>
 <Assembly: RMA.Phone("206-555-1212")>
 <Assembly: RMA.Fax("206-123-4567")>
 <Assembly: RMA.EMail("<support@make_a_rh_plugin.com>")>
 <Assembly: RMA.WebSite("http://www.make_a_rh_plugin.com")>
 <Assembly: RMA.UpdateURL("http://www.make_a_rh_plugin.com/myplugin")>
 'The following GUID is used as the Rhino Plug-In unique ID
 <Assembly: Guid("5FB01338-E5AA-4118-9BB6-C931A9568DFB")>

All of the above attributes must be defined to create a valid Rhino.NET plug-in. Your plug-in will compile without these, but the DotNetManager will complain when it tries to load a plug-in that does not have all of the above attributes.

Most of the attributes should be pretty self explanatory. The Guid attribute is important to ensure uniqueness of your plug-in. Every plug-in must have a different Guid (so don't just copy and paste the same Guid around from plug-in to plug-in.) VB.NET has a tool for creating Guids. Click Create Guid under the Tools menu. Make sure your Guid style is set to 4. Registry Format and click Copy. You can then paste a new Guid into your project.

Rhino 4

These attributes have been moved to the beginning of the plug-in file.

Plug-in class (RhinoPlugIn.vb)

Every Rhino.NET plug-in must contain one (and only one) MRhinoPlugIn derived class.

Rhino 3

You are limited to having a MRhinoUtilityPlugIn derived class.

You must override the PlugInName property and provide a name for your plug-in.

 'SAMPLE RHINO 3 .NET PLUG-IN CLASS
 'Single Rhino plug-in class. All .NET plug-ins must have one class
 'that inherits from RMA.Rhino.MRhinoPlugIn
 Public Class RhinoPlugIn
   Inherits RMA.Rhino.MRhinoUtilityPlugIn
   Public Overrides ReadOnly Property PlugInName() As String
     Get
       Return "FirstPlugIn"
     End Get
   End Property
 End Class

You can give your plug-in class any name you want. Rhino.NET will create an instance of this class when it is loaded into Rhino.

Rhino 4

Supports deriving from MRhinoUtilityPlugIn, MRhinoFileImportPlugIn, MRhinoRenderPlugIn, or MRhinoFileExportPlugIn

 'SAMPLE RHINO 4 .NET PLUG-IN CLASS
 'Single Rhino plug-in class. All .NET plug-ins must have one class
 'that inherits from RMA.Rhino.MRhinoPlugIn
 Public Class RhinoPlugIn
   Inherits RMA.Rhino.MRhinoUtilityPlugIn
   ' Every plug-in must have a truely unique ID.
   ' Use the Create Guid tool in visual studio to make a new guid
   Public Overrides Function PlugInID() As System.Guid
     Return New System.Guid("{56a8fe4e-d2cd-4c45-8bcc-c2ee258da2e5}")
   End Function
   Public Overrides Function PlugInName() As String()
     Return "FirstPlugIn"
   End Function
   Public Overrides Function PlugInVersion() As String
     Return "1.0.0.0"
   End Function
 End Class

Command class (RhinoCommand1.vb)

Each Rhino.NET plug-in can contain as many MRhinoCommand subclasses as you want (0 or more). Each MRhinoCommand subclass defines a new command that shows up in Rhino.

 'SAMPLE RHINO 3 .NET COMMAND CLASS
 Imports RMA.Rhino
 Public Class FirstPlugInCommand
   Inherits RMA.Rhino.MRhinoCommand
   Public Overrides ReadOnly Property EnglishCommandName() As String
     Get
       Return "FirstPlugIn"
     End Get
   End Property
   Public Overrides Function RunCommand(ByVal context As IRhinoCommandContext) _
     As IRhinoCommand.result
     Dim prompt As String =
       String.Format("The {0} command is under construction", EnglishCommandName)
     RhUtil.RhinoApp.Print(prompt + vbCrLf)
     Return IRhinoCommand.result.success
   End Function
 End Class
 'SAMPLE RHINO 4 .NET COMMAND CLASS
 Public Class FirstPlugInCommand
   Inherits RMA.Rhino.MRhinoCommand
   ' Every command must have a truely unique ID.
   ' Use the Create Guid tool in visual studio to make a new guid
   Public Overrides Function CommandUUID() As System.Guid
     Return New Guid("{eb9dd2cf-7e3d-4f8a-93e9-e3272925b191}")
   End Function
   Public Overrides Function EnglishCommandName() As String
     Return "FirstPlugIn"
   End Function
   Public Overrides Function RunCommand(ByVal context As IRhinoCommandContext) _
     As IRhinoCommand.result
     Dim prompt As String =
       String.Format("The {0} command is under construction", EnglishCommandName)
     RhUtil.RhinoApp.Print(prompt + vbCrLf)
     Return IRhinoCommand.result.success
   End Function

There are two important items that a MRhinoCommand subclass should override, EnglishCommandName and RunCommand. The EnglishCommandName is the command name as it shows up in Rhino. The RunCommand function is what is executed when your command is entered in Rhino.

developer/simplevbplugin.txt · Last modified: 2016/03/22 by sandy