I spent 2 hours looking into this and you solved it in 2 minutes XD. I 
looked into that documentation definition before, but I didn't understand 
as you did what was going on.
All good now.(In cpp bootstrap is MString type).
Thanks Justin.

El domingo, 30 de abril de 2023 a las 23:14:38 UTC+2, Justin Israel 
escribió:

> "Executes a Python command that returns a string result from the command 
> engine"
>
> Given the documentation, executePythonCommandStringResult wants to parse 
> the python statement through its own command engine. It kind of assumes 
> that the statement sent to this particular function is a single command 
> where it can automatically arrange to capture the string result. So if you 
> feed it larger snippets, the parser gets all wonky. What you can do instead 
> is first feed your supporting code to executePythonCommand(), and then just 
> call executePythonCommandStringResult() with your command. The following 
> works in python:
>
> import maya.OpenMaya as om
>
> bootstrap = """
> def foo():
>     xx = cmds.joint()
>     return xx
> """
> om.MGlobal.executePythonCommand(bootstrap)
>
> c = "foo()"
> ret = om.MGlobal.executePythonCommandStringResult(c)
> print(ret)
>
>
> On Mon, May 1, 2023 at 8:22 AM Rudi Hammad <rudih...@gmail.com> wrote:
>
>> Hi,
>> I am writing a Plugin in C++ and I am having trouble figuring out how to 
>> get a return from python execute code.
>> For instance, this works perfectly:
>>
>>  MString pyCommand2;
>> pyCommand2 = "cmds.joint()";
>> auto test2 = MGlobal::executePythonCommandStringResult(pyCommand2);
>> MGlobal::displayInfo(test2);
>>
>> Here I get displayed "joint1", so it is catching the return. But this 
>> doesn't work
>>
>> MString pyCommand;
>> pyCommand =
>> "def foo():\n"
>> "    xx = cmds.joint()\n"
>> "    return xx\n"
>> " foo()";
>>
>> auto test1 = MGlobal::executePythonCommandStringResult(pyCommand);
>> MGlobal::displayInfo(test1);
>>
>> Here the return value that MGlobal::displayInfo(test1) should provide is 
>> empty.
>> Any ideas?
>>
>> thanks
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Python Programming for Autodesk Maya" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to python_inside_m...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/python_inside_maya/f8e57985-df64-40fe-b8fb-12906ab943b2n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/python_inside_maya/f8e57985-df64-40fe-b8fb-12906ab943b2n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/2d7cdd35-f585-48a1-82db-cafd0f17ac15n%40googlegroups.com.

Reply via email to