Hello,
I have a tool that I am migrating from Rhino 5x64 to Rhino 6. My Rhino 5x64 tool uses IRhinoApplication as follows:
Type type = Type.GetTypeFromProgID("Rhino5x64.Application");
dynamic rhino = Activator.CreateInstance(type);
IRhino5x64Application RhinoApp = rhino as IRhino5x64Application;
This is the code I am using for Rhino 6 COM is:
Type type = Type.GetTypeFromProgID("Rhino.Application.6");
dynamic rhino = Activator.CreateInstance(type);
IRhinoApplication RhinoApp = rhino as IRhinoApplication;
Activator.CreateInstance returns a COM object. However, casting the “rhino” as IRhinoApplication (Rhino 6) returns null.
If I try to do a something like:
IRhinoApplication RhinoApp = rhino;
Then I get:
{“Unable to cast COM object of type ‘System.__ComObject’ to interface type ‘Rhino.IRhinoApplication’. This operation failed because the QueryInterface call on the COM component for the interface with IID ‘{9837542C-DC30-4EBE-BA30-B6EBDF471508}’ failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).”}
UPDATE: So after some trial and error, it appears I can simply use the dynamic type directly for everything I need (and not attempt to cast it as IRhinoApplication)
For example, this appears to work…
Type type = Type.GetTypeFromProgID(“Rhino.Application.6”);
dynamic rhino = Activator.CreateInstance(type);
rhino.Visible = 1;
Still interesting that this differs from the Rhino5x64 setup.
Note, starting with Rhino 6, Rhino.Application will always retrieve the current version of Rhino (e.g. 6, 7, 8, etc.). To get a specific version, then append the major version number to the end (e.g. Rhino.Application.6).
Is there a way to get find which members are exposed through COM in this way? The .Visible property isn’t defined on Rhino.RhinoApp in the API docs and while .RunScript() and .GetPluginObject() work, other methods do not.
Keep in mind that Com != .NET. Thus, you will not find a Rhino.RhinoApp object in COM, for example.
But if you want intellisense and autocomplete on the Rhino or RhinoScript COM objects, then add a reference to the type libraries. These articles should help.
Following your instructions I referenced the required type libraries (i.e. Rhino.tlb), and in the object browser I can indeed have all its members exposed. But that’s where I stop.
Once I have my dynamic rhino instance, how can I enable Visualstudio’s Intellisense on it?