[IronPython] Using IronPython as an assembly in dotNET

Dino Viehland dinov at microsoft.com
Thu Aug 13 19:34:56 CEST 2009

What language are you doing this from?

ScriptEngine.Execute has an overload which is generic and an overload
which is not generic.  The generic version will get the result and
convert it to the provided generic type.  It looks like for some reason
you end up trying to call the generic version here.  Does the language
have support for generics?  If so you could do:

engine.Execute<object>(...) (C# syntax)

which would be the same as the non-generic version.

For communication I'd suggest injecting a class into the ScriptScope
You execute the code in.  Then the Python code can call back on it or
subscribe to events on it.

> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:users-
> bounces at lists.ironpython.com] On Behalf Of Lukas Dubeda
> Sent: Thursday, August 13, 2009 10:15 AM
> To: users at lists.ironpython.com
> Subject: [IronPython] Using IronPython as an assembly in dotNET
> Hi there everyone,
> I have a problem I can't seem to figure out.
> I want to use IronPython as an assembly via dotNET, I managed to load
> it
> as an assembly and access various constructors, classes etc...
> However, I have a problem with executing Python code from the host
> application. I'm using 3ds Max to load up the assembly via dotNET. The
> code looks like this:
> Assembly = dotNetClass "System.Reflection.Assembly" -- loading the
> assembly class
> Assembly.LoadFrom "C:\IronPython-2.0.1\IronPython.dll" -- loading
> IronPython
> ironPythonHosting = dotNetClass "IronPython.Hosting.Python" -- loading
> the hosting class
> pythonEngine = ironPythonHosting.CreateEngine() -- creating an engine
> Now, when I execute:
> pythonEngine.ExecuteFile("C:\\tst.py")
> it runs smoothly and executes the tst.py and whatever Python code
> that's
> inside.
> Now, I want to execute the code directly, not via a saved file. I tried
> this:
> pythonEngine.Execute("print 'TEST'")
> but it throws me an error:
> -- Error occurred in anonymous codeblock; filename: ; position: 344
> -- Runtime error: dotNet runtime exception: Late bound operations
> cannot
> be performed on types or methods for which ContainsGenericParameters is
> true.
> Also, if I execute the Python code inside a file, is there a way to get
> the result/feedback from the code back to the host application? Via
> dotNET or IronPython? Or anyhow? So that I can write more complex tools
> that'd communicate with Pyhon code from within 3ds Max.
> Thanks a lot in advance, cheers,
> - Lukas Dubeda
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

More information about the Ironpython-users mailing list