Reuse of Rhino.net code in Rhino Common

Hello, Forum!

I’ve a huge amount of classes developed under Rhino.NET, then using Visual C# 2007 and .net 2.0 . My client now chose to upgrade all of its Rhino installations to R5 and asked me to port my project to Rhino Common.

From the RhinoCommon Plug-in SDK web page I read:

Rhino 4 and Rhino 5 already contain a .NET plug-in SDK called Rhino.NET. We will continue to ship and support the Rhino.NET SDK in Rhino 5. The good news is that you can use both SDKs in a single .NET plug-in. If there is a new feature in the RhinoCommon SDK that you want to use in your Rhino.NET based plug-in, just add a reference to RhinoCommon.dll and start using it.

Can anybody give me an example of how to do it? Shall I start from a Rhino Common project and use Rhino.net namespaces? Under what SDK, 2007 or 2010 to 2013?

Thanks. L

If you have the old projects from the initial development, you can load these into any newer version of Visual Studio (it will ask you to convert the projects to the new version). Then, add a reference to RhinoCommon.dll (this is found in the System folder where Rhino is installed).

Take care to select the added RhinoCommon reference, then right-click Properties and set “Copy to output folder” to False: RhinoCommon.dll should not be copied to the location where the plug-in is written.

Conversely, you can start a new RhinoCommon project and add a reference to Rhino_DotNet.dll (found in the same location). Also here, set copy-to-output folder to False. Then, you can use both RhinoCommon and Rhino_DotNet in one project.

You can find documentation on RhinoCommon here http://4.rhino3d.com/5/rhinocommon/
Specifically, it is possible to convert objects from the Rhino_DotNet to RhinoCommon and vice-versa with the FromOn* and ToOn* methods in the Rhino.Runtime.Interop class, see http://4.rhino3d.com/5/rhinocommon/html/AllMembers_T_Rhino_Runtime_Interop.htm

To add to Menno’s comments, RhinoCommon plug-ins are .NET Framework 4 assemblies. So you can use Visual Studio 2010 or above. Just make sure to set the target framework in the project settings.

Menno, Dale,

perfect! Thanks! It’s working fine. Just two minor questions:

1) In my installation (Windows 7 64bit, Rhino 5 64bit) I have a “Rhinoceros 5” folder under “Program Files (x86)” and a “Rhinoceros 5 (64-bit)” folder under “Program Files”. Both folders contain in their “System” folder “RhinoCommon.dll” and “Rhino_DotNet.dll”.

I tried the four combinations of my project configuration: start from a Rhino.net project and add reference to the two possible rhinoCommon and the other way around starting from a rhinoCommon project adding a reference to the two possible rhino_DotNet dlls). All of then worked fine, but all of them fired this warning:

There was a mismatch between the processor architecture of the project being built “MSIL” and the processor architecture of the reference “Rhino_DotNET”, “x86”. This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.

When i point to the x86 dlls I also get this other warning:

Found conflicts between different versions of the same dependent assembly that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed.

As I wrote all is working properly. Shall I ignore those warnings? I assume I should use 64 bit dlls to target Rhino 5 64 bit.

2) RhinoCommon RunCommand method is passed a RhinoDoc argument, while the equivalent Rhno_DotNet method is passed a IRhinoCommandContext argument. How can I pass from one to the other?

Thanks. L

This can be ignored. You will want to compile your plug-in as ‘Any CPU’. Rhino.NET is platform specific and there is nothing that can really be done about that while you still have a Rhino.NET reference.

I’m trying to figure out a case where you actually want to pass from one to the other. Are you trying to get a hold of the RhinoDoc?

Steve,

thanks. When I add a reference of RhinoCommon to my current Rhino.net project I might fall in a situation like this:

public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
    {
        ....
        // new code
        doc.Objects.AddLine(pt0, pt1);
        doc.Views.Redraw();
        ....
    }

This “doc” instance is the current doc which, in a pure rhinoCommon code, is one of the two arguments of the equivalent method. In this case the equivalent argument is “IRhinoCommandContext context” instead. This is why I need to find a way to evaluate “doc” from “context”.

Thanks. L

Shouldnt your first line look something like this:

Protected Overrides Function RunCommand(ByVal doc As RhinoDoc, ByVal mode As RunMode) As Result

This is vb.Net but maybe it helps you.

While you are migrating your code, I would recommend just using RhinoDoc.ActiveDoc. Once the command is completely changed to RhinoCommon code, then you will just use the doc that is passed in RunCommand.

Steve,

Great! I will follow your recommendations.

Thanks. L