IronPython integration via dotNET

View: New views
4 Messages — Rating Filter:   Alert me  

IronPython integration via dotNET

by loocas duber :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi there,

me again with the same issue of me trying to integrate IronPython into
3ds Max via .NET. So far, after tons of trials/errors, I've reached
a point where I really don't know where to go next.

I understand most of you won't probably know MAXScript and 3ds Max,
but I bet you're all pretty good at .NET and IP :) so, here's what I'm
doing so far ("--" are single comment lines in MAXScript):

-- I load an assembly class:
assembly = dotNetClass "System.Reflection.Assembly"

-- I load the IronPython dll:
assembly.loadFrom "C:\IronPython-2.6\IronPython.dll"

-- Then I load the iP hosting:
ironPythonHosting = dotNetClass "IronPython.Hosting.Python"

-- now I need the iP runtime:
pythonRuntime = ironPythonHosting.CreateRuntime()

-- I then try to get the Python engine itself:
engine = pythonRuntime.GetEngine("Python")

-- I understand that for running Python code in the current scope
-- I need to create a scope object in order to "listen" to the
-- output of Python, right?
scope = engine.CreateScope()

-- so far so good, now I'd like to execute a simple Print() function
-- in iP and get its output back to Max:
src = engine.CreateScriptSourceFromString("Print 'hello'")

-- unfortunately this is where I hit the major road block
-- when I try to execute the following code block:
src.execute(scope)

I get the following error:

-- Runtime error: dotNet runtime exception: Late bound operations cannot
be performed on types or methods for which ContainsGenericParameters is
true.


I have absolutely no idea how to get around this issue and how to get
IronPython execute the Python code and return whatever it calculates
back to the application I'm running it from so I could catch the return
and use the values from within Max.

Anyone has any idea?

I should also mention that MAXScript is a dynamic scripting language
within 3ds Max and that, even though I know MXS quite well as well as
I know Python and have done tons of scripts and tools with these
languages, I'm not a programmer, I'm a technical artist (as the official
title says :) ).

Thanks a lot in advance, I'll appretiate any tips and hints on this
issue.

- Lukas
_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Re: IronPython integration via dotNET

by Michael Foord-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Lukas Dubeda wrote:

> [snip...]
> -- unfortunately this is where I hit the major road block
> -- when I try to execute the following code block:
> src.execute(scope)
>
> I get the following error:
>
> -- Runtime error: dotNet runtime exception: Late bound operations
> cannot be performed on types or methods for which
> ContainsGenericParameters is true.
>

ScriptSource.Execute is a generic method. Attempting to call generic
methods like this using reflection (which presumably is what Max is
doing) causes this kind of error. You have the same problem in
Powershell - here's an example from Lee Holmes of how he solved it in
Powershell:

   
http://www.leeholmes.com/blog/InvokingGenericMethodsOnNonGenericClassesInPowerShell.aspx

(Note that you will have to change 'P' in the 'Print' from your example
code to 'p' (lowercase) for it to work anyway.)

All the best,

Michael Foord

>
> I have absolutely no idea how to get around this issue and how to get
> IronPython execute the Python code and return whatever it calculates
> back to the application I'm running it from so I could catch the return
> and use the values from within Max.
>
> Anyone has any idea?
>
> I should also mention that MAXScript is a dynamic scripting language
> within 3ds Max and that, even though I know MXS quite well as well as
> I know Python and have done tons of scripts and tools with these
> languages, I'm not a programmer, I'm a technical artist (as the official
> title says :) ).
>
> Thanks a lot in advance, I'll appretiate any tips and hints on this
> issue.
>
> - Lukas
> _______________________________________________
> Users mailing list
> Users@...
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog


_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Re: IronPython integration via dotNET

by loocas duber :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hmm,

thanks for the tip, I'll have a look at the code examples.

Pitty I don't know C# nor C++ at all :/

- Lukas

Michael Foord wrote:

> Lukas Dubeda wrote:
>> [snip...]
>> -- unfortunately this is where I hit the major road block
>> -- when I try to execute the following code block:
>> src.execute(scope)
>>
>> I get the following error:
>>
>> -- Runtime error: dotNet runtime exception: Late bound operations
>> cannot be performed on types or methods for which
>> ContainsGenericParameters is true.
>>
>
> ScriptSource.Execute is a generic method. Attempting to call generic
> methods like this using reflection (which presumably is what Max is
> doing) causes this kind of error. You have the same problem in
> Powershell - here's an example from Lee Holmes of how he solved it in
> Powershell:
>
>    
> http://www.leeholmes.com/blog/InvokingGenericMethodsOnNonGenericClassesInPowerShell.aspx 
>
>
> (Note that you will have to change 'P' in the 'Print' from your example
> code to 'p' (lowercase) for it to work anyway.)
>
> All the best,
>
> Michael Foord
>>
>> I have absolutely no idea how to get around this issue and how to get
>> IronPython execute the Python code and return whatever it calculates
>> back to the application I'm running it from so I could catch the return
>> and use the values from within Max.
>>
>> Anyone has any idea?
>>
>> I should also mention that MAXScript is a dynamic scripting language
>> within 3ds Max and that, even though I know MXS quite well as well as
>> I know Python and have done tons of scripts and tools with these
>> languages, I'm not a programmer, I'm a technical artist (as the official
>> title says :) ).
>>
>> Thanks a lot in advance, I'll appretiate any tips and hints on this
>> issue.
>>
>> - Lukas
>> _______________________________________________
>> Users mailing list
>> Users@...
>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Re: IronPython integration via dotNET

by loocas duber :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Oh, by the way, Michael,

your IronPython In Action book is FANTASTIC!

Kudos to you, Chris Muirhead and all who contributed!

- Lukas

Michael Foord wrote:

> Lukas Dubeda wrote:
>> [snip...]
>> -- unfortunately this is where I hit the major road block
>> -- when I try to execute the following code block:
>> src.execute(scope)
>>
>> I get the following error:
>>
>> -- Runtime error: dotNet runtime exception: Late bound operations
>> cannot be performed on types or methods for which
>> ContainsGenericParameters is true.
>>
>
> ScriptSource.Execute is a generic method. Attempting to call generic
> methods like this using reflection (which presumably is what Max is
> doing) causes this kind of error. You have the same problem in
> Powershell - here's an example from Lee Holmes of how he solved it in
> Powershell:
>
>    
> http://www.leeholmes.com/blog/InvokingGenericMethodsOnNonGenericClassesInPowerShell.aspx 
>
>
> (Note that you will have to change 'P' in the 'Print' from your example
> code to 'p' (lowercase) for it to work anyway.)
>
> All the best,
>
> Michael Foord
>>
>> I have absolutely no idea how to get around this issue and how to get
>> IronPython execute the Python code and return whatever it calculates
>> back to the application I'm running it from so I could catch the return
>> and use the values from within Max.
>>
>> Anyone has any idea?
>>
>> I should also mention that MAXScript is a dynamic scripting language
>> within 3ds Max and that, even though I know MXS quite well as well as
>> I know Python and have done tons of scripts and tools with these
>> languages, I'm not a programmer, I'm a technical artist (as the official
>> title says :) ).
>>
>> Thanks a lot in advance, I'll appretiate any tips and hints on this
>> issue.
>>
>> - Lukas
>> _______________________________________________
>> Users mailing list
>> Users@...
>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com