Rhino 6 COM Interface

Hello,
Our program uses Rhino via COM interface using C#.
In Rhino 5 it worked fine, but it doesn’t work in Rhino 6.

A simple sample programs are shown below.

In Rhino 5, it works fine:

        Type type = Type.GetTypeFromProgID("Rhino5x64.Application");
        if(type == null)
        {
            MessageBox.Show("Cannot find the COM type of Rhino5x64.Application");
            return;
        }
        else
        {
            try
            {
                object obj = Activator.CreateInstance(type);
                Rhino5x64.IRhino5x64Application rhinoApplication = (Rhino5x64.IRhino5x64Application)obj;
                rhinoApplication.Visible = 1;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

In Rhino 6, doesn’t work, InvalidCastException occurred:

        Type type = Type.GetTypeFromProgID("Rhino.Application");
        if (type == null)
        {
            MessageBox.Show("Cannot find the COM type of Rhino.Application");
            return;
        }
        else
        {
            try
            {
                object obj = Activator.CreateInstance(type);
                Rhino.IRhinoApplication rhinoApplication = (Rhino.IRhinoApplication)obj;
                rhinoApplication.Visible = 1;
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

How to use COM on Rhino 6?

Thanks.

The exception message is as follows.
com_error

Hi @koganezawak,

Does this sample work for you?

– Dale

Dale-san,
thank you for your reply.

This sample works fine well.
I also applied this advice to my program and confirmed it works fine.

Thank you very much.

Hi @dale. This doesn’t seem to be working for me. how do i choose between versions of rhino? I have 5, 6 and 7 WIP installed. When i build and run SampleCsConsole.exe it:

  • opens a console
  • acquires my licence
  • opens the rhino 7 WIP UI
  • prints to console "Failed to create Rhino application"
  • closes console and Rhino

I want to choose between 5 and 6, not WIP at this stage.
What can i change in string rhinoId = "Rhino.Application"; is there a different ProgID for each version?

Hi @dharman,

To create a version specific object, use these program ids;

// Rhino 5
Rhino5x64.Application

// Rhino 6
Rhino.Application.6

// Rhino WIP
Rhino.Application.7

– Dale

Thanks Dale. Will try it out when I’m back at work. Is there any way I could have figured that out on my own without guessing? Some kind of documentation?

Hi @dharman,

The details of COM automation and external access are generally found in the RhinoScript help file, as it’s the RhinoScript (COM) object you’ll be using.

https://developer.rhino3d.com/api/rhinoscript/introduction/external_access.htm

– Dale