[IronPython] Using IronPython as an assembly in dotNET

Lukas Dubeda loocas at duber.cz
Thu Aug 13 19:42:23 CEST 2009


Hey, thanks Dino,

some interesting points. However, I'm not a programmer, I'm more of a 
"scripter" so all I'm familiar with is Python and MAXScript (native 3ds 
Max scripting language).

I have no idea how to access the generic/non-generic engine, further 
more, I have no idea what the difference is.

As for scope, I can do that, the problem is, I have no idea how exactly 
to do that. Is there a documentation on this subject somewhere?

Thanks a lot for the tips, I appretiate it.

- Lukas

Dino Viehland wrote:
> 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
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> 
> __________ Information from ESET NOD32 Antivirus, version of virus signature database 4332 (20090813) __________
> 
> The message was checked by ESET NOD32 Antivirus.
> 
> http://www.eset.com
> 
> 
> 
> 



More information about the Ironpython-users mailing list