Quantcast
Channel: Rhino Developer - McNeel Forum
Viewing all articles
Browse latest Browse all 8532

Rhino6 Com Interface

$
0
0

@fujihira wrote:

Hello,
We try connect our program to rhino6 via COM interface.
“rs = rhino.GetScriptObject();” is not work.

Error message from visual studio:

Unable to cast object of type 'System.DBNull' to type 'RhinoScript.RhinoScript'

sample code:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading;

using Rhino;
using RhinoScript;

namespace rhinoCOM
{
class Program
{
static void Main()
{
RhinoScript.RhinoScript rs = null;

        // Try creating an instance of Rhino
        dynamic rhino = null;
        try
        {
            //string rhinoId = "Rhino.Application";
            string rhinoId = "Rhino.Interface";
            System.Type type = System.Type.GetTypeFromProgID(rhinoId);
            rhino = System.Activator.CreateInstance(type);
        }
        catch
        {
        }

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

        // Wait until Rhino is initialized before calling into it
        const int bail_milliseconds = 15 * 1000;
        int time_waiting = 0;
        while (0 == rhino.IsInitialized())
        {
            Thread.Sleep(100);
            time_waiting += 100;
            if (time_waiting > bail_milliseconds)
            {
                Console.WriteLine("Rhino initialization failed");
                return;
            }
        }

        //rhino.Visible = 1;

        // get error here
        rs = rhino.GetScriptObject();

        double[] pt_1 = { 0, 0, 0 };
        double[] pt_2 = { 100, 100, 100 };

        rs.AddLine(pt_1, pt_2);
    }
}

}

We try this code in other computer, it works.
I have no idea why some computer get error.

Thanks

Posts: 3

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 8532

Trending Articles