Console application with Rhino instance check

script

#1

Hi everyone!

I’m new to Rhino (but loving what I’m seeing so far!) and am trying to automate some tasks with a console application. I came across the examples within the docs and by @dale, and was having some issues when checking whether a Rhino instance had been created or not.

The C# code segment from the docs is this:

// Try creating an instance of Rhino
dynamic rhino = null;
try
{
  //string rhinoId = "Rhino5.Application";
  string rhinoId = "Rhino5x64.Application";
  System.Type type = System.Type.GetTypeFromProgID(rhinoId);
  rhino = System.Activator.CreateInstance(type);
}
catch
{
}
                
if (null == rhino)
{
  Console.WriteLine("Failed to create Rhino application");
  return;
}

But it is getting caught on this check and exiting the process early.

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

If I remove this check, everything appears to work correctly - i.e. I can run scripts etc. So, I’d like to work out what is wrong with the check, and how to fix it if possible.

Does anyone have any suggestions as to why the null comparison is true, or have an equivalent workaround?

Cheers


(Dale Fugier) #2

This seems to be the sample you are using:

https://github.com/mcneel/rhino-developer-samples/blob/5/rhinocommon/cs/SampleCsAutomation/SampleCsCommand/Program.cs

Rhino is a big application and sometimes (I’ve seen) situations where the Rhino object is not ready for use when you start to call into it. So you might consider sleeping for a bit before verifying the object is available.

– Dale


#3

Ahh, so simple!

Thanks for the help @dale!