Is there a way to hand over a running rhino application to an external program?

Hi to everyone,

I want to do the following:

Hand over information from an running external program I developed, to a running instance of Rhino. (In my case Version 5)

The external Program is developed in

I sadly cannot run this Prog as plugin in rhino.
In other systems (i.e. inventor) I use the following steps to get the existing application. Is there something equal for Rhino? Would be perfect.

Public Function InventorApp() As Inventor.Application
        InventorApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
    Catch Error As Exception
        InventorApp = Nothing
    End Try
End Function

Or maybe there exists something equal?

From that point everything else should be ok :smile:

Thanks to everyone.

I think you’re looking for something similar to this

In this example, a new instance of Rhino is started. It should (?) also be possible to hook into a running instance of Rhino in a similar way that you posted.

// Try creating an instance of Rhino
  dynamic rhino = null;
    // string rhinoId = "Rhino5.Application";
    string rhinoId = "Rhino5x64.Application";
    System.Type type = System.Type.GetTypeFromProgID(rhinoId);
    rhino = System.Activator.CreateInstance(type);

  if (null == rhino)
    Console.WriteLine("Failed to create Rhino application");

Hi, and first of all, thanks for your very quick reply.

It’s my first attempt with the Rhino programming.

With your advice, I got a running instance of Rhino, perfect so far, but there I stopped, because I don’t know, how I can use it.

Public Function RhinoAPP() As Object
    Dim rhino As Object = Nothing
        Dim rhinoId As String = "Rhino5x64.Application"
        Dim type As System.Type = System.Type.GetTypeFromProgID(rhinoId)
        rhino = System.Activator.CreateInstance(type)
    End Try

    RhinoAPP = rhino

End Function

In my case you’ll see, I have an object of the running instance. But it should be something like “Rhino.Application”. Instead of “RhinoAPP() As Object”.

I have no idea in the moment, what kind of object the result is. Sorry, but I think, there’s only a small step on to the right side :smile: But I standing behind a wall in the moment and cannot see the way :smile:

This is the sample @menno is reffering too.

I’ve just tested this:

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim rh As Object = RhinoAPP()

        If rh IsNot Nothing Then
            rh.RunScript("_Line 0,0,0 100,0,0 -_SaveAs C:\Test.3dm _enterEnd", 0)
        End If

    End Sub

    Public Function RhinoAPP() As Object
        Dim rhino As Object = Nothing
            Dim rhinoId As String = "Rhino5.Application"
            Dim type As System.Type = System.Type.GetTypeFromProgID(rhinoId)
            rhino = System.Activator.CreateInstance(type)
        End Try
        Return rhino
    End Function

It will create a Rhino5 32Bit instance, draws a line, SaveAs on C:\test.3dm and this works.

1 Like

Some useful links:
An overview of external access

VBScript automation samples

C# automation samples

VB.NET automation sample

Hi to all of you three,

So many interesting input :slight_smile:

The main thing, I got the Rhino App in my Program and now, the fun can start :smile:

I think, I searched for a Object with a real name and not like “Rhino As Object”. Was a step to complicated from my side :wink:

So, thanks a lot to all of you for your useful help, informations etc. (Rhino and it’s community is still almost perfect)

Hi again,

I created now a lot of stuff into my model, but now I come to a point where I need something else the runscript.

Example: I want to change the layer according to the element I create. Is that possible with the external access to the Rhino Application?

In the moment I only have access to everything I can access via runscript, but that’s all.

I think, there exists also a solution… :smile:

Best Regards

You can either script the Properties command - RunScript("_-Properties....")

or you can use RhinoScript’s ObjectLayer method.

1 Like

Hi, thanks for the reply, but I think, my brain is not able to understand it in the moment.

What do I want to achieve in the moment:

I have against list of informations and want to visualize them in Rhino.
For making it simple let’s say, I want to draw points. That’s easy. But now, I want to change the colors of the objects. My plan was: Changing the Layer to the one, I want to use and then create the point. Then check if I have to change the color again and create the next point and so on.

In the moment I have 3 problems:

  1. I have no idea of how to get the running instance of Rhino in the moment. So I’ll have to start a new instance each time… But that’s not so worse
  2. If I use the _-properties script, I’ll have to select the element I created before… (Would be easier to change the layer before, create element and then continue)
  3. My Brain is to weak :smile:

Any ideas??


I’m so dumb from time to time, point 1 is solved :slight_smile: I don’t see the running instance point :smile:
The second and third (mainly the third are still existing)

Public Function RhinoAPP() As Object
    Dim rhino As Object = Nothing
        'Dim rhinoId As String = "Rhino5x64.Application"
        'Dim type As System.Type = System.Type.GetTypeFromProgID(rhinoId)
        'rhino = System.Activator.CreateInstance(type)
        rhino = CreateObject("Rhino5x64.Interface")
    End Try

    RhinoAPP = rhino

End Function
1 Like

Every method on the RhinoScript object - all 1000+ methods - are callable from an externally running application. So see what is available in RhinoScript, select Help -> Plug-ins -> RhinoScript.

To see how to get the RhinoScript object, from the Rhino object, see the following example.

Pay attention to the code in MainModule.vb in and around line 42.

1 Like

To reference it as RhinoScript you need to add a reference to your project.

Add the file from your rhino folder > Plug-ins > Rhinoscript.tlb
Now you can Imports RhinoScript4 and see the whole library.

Hi, and thanks for the replies.

I will look into that. Seems really that the scripting is the best way. Must get used to it.

Thanks and of I need more assistance I will raise my hand :slight_smile:

1 Like