Skip to content

Instantly share code, notes, and snippets.

@sbaer
Created May 15, 2013 21:27
Show Gist options
  • Save sbaer/5587540 to your computer and use it in GitHub Desktop.
Save sbaer/5587540 to your computer and use it in GitHub Desktop.
Automate Rhino5 with IronPython
# The following script is meant to be run inside of IronPython
# It demonstrates how to automate Rhino from a script
import System
# start an instance of Rhino
t = System.Type.GetTypeFromProgID("Rhino5.Application")
rhino = System.Activator.CreateInstance(t)
# show Rhino (optional)
rhino.Visible = True
# run your script or a bunch of scripts
rhino.RunScript("!-_RunPythonScript myscript.py", 1)
# shut down rhino
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(rhino)
@goswinr
Copy link

goswinr commented May 16, 2013

Hi Steve,
Thanks for posting this.
I tried if the same would work with F# interactive from VS:

let t = System.Type.GetTypeFromProgID("Rhino5.Application")
let rhino = System.Activator.CreateInstance(t)

but I get this COM error on CreateInstance:
"..class not registered..." REGDB_E_CLASSNOTREG

do you have any idea if this can be fixed?

System.Runtime.InteropServices.COMException (0x80040154): Die COM-Klassenfactory für die Komponente mit CLSID {ECE2F51F-F374-4736-96E7-9DF182CCC178} konnte aufgrund des folgenden Fehlers nicht abgerufen werden: 80040154 Klasse nicht registriert (Ausnahme von HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
bei System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
bei System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
bei System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
bei System.Activator.CreateInstance(Type type, Boolean nonPublic)
bei System.Activator.CreateInstance(Type type)
bei <StartupCode$FSI_0003>.$FSI_0003.main@() in C:\temp~vsA4EA.fsx:Zeile 3.

@acormier
Copy link

Hi Goswin,

let t = System.Type.GetTypeFromProgID("Rhino5.Application")
let rhino = System.Activator.CreateInstance(t)

works for me and gives me a System.__ComObject

I didn't try to go further

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment