Thanks Justin. It works

nyue@francoislake 146% python maya_command_port_pickle.py
19577


On 4 June 2015 at 14:39, Justin Israel <[email protected]> wrote:

> You need to recv from the first send() before you send again.
>
> On Fri, Jun 5, 2015 at 9:37 AM Nicholas Yue <[email protected]>
> wrote:
>
>> Thanks for the example Justin.
>>
>> In Maya 2014 (Linux x64), in the MEL script editor, I executed the
>> following code
>> ==========================================================
>>
>> commandPort -name ":6001" -stp "python" -po;
>>
>> On the CentOS command line, I launch this code with python
>> ============================================
>>
>> import socket
>> import cPickle
>>
>> maya = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>> maya.connect(('localhost', 6001))
>> maya.send("import os\n")
>> maya.send("os.getpid()\n")
>> ret = maya.recv(1024)
>> print cPickle.loads(ret)
>>
>> Here is the result being printed on the shell console
>> =====================================
>> nyue@francoislake 145% python maya_command_port_pickle.py
>> None
>>
>> NOTE : I did add "\n" to the command being sent, otherwise, they are not
>> being executed.
>>
>>
>> On 4 June 2015 at 14:16, Justin Israel <[email protected]> wrote:
>>
>>> One thing that would help, to start, is make sure you are using the
>>> pickleOutput option when you open the commandPort. That will make it easier
>>> to receive values. Then, if you make sure to send just a single operation,
>>> you should get back the result:
>>>
>>> import cPickle
>>>
>>> sock.send("import os")
>>> #...
>>> sock.send("os.getpid()")
>>> ret = sock.recv(BUF)print cPickle.loads(ret)
>>>
>>> ​
>>>
>>>
>>>
>>> On Fri, Jun 5, 2015 at 5:59 AM Nicholas Yue <[email protected]>
>>> wrote:
>>>
>>>> Hi,
>>>>
>>>>      Newbie question.
>>>>
>>>>      So far, I have used an external python application to send commands
>>>> to Maya and it works. (doing simple things, create geometry etc)
>>>>
>>>>      What additional steps do I need to do in order to query the results
>>>> from python command that was sent over ?
>>>>
>>>>      I sent over a 'import os\npid=os.getpid()\n'
>>>>
>>>>      I'd like to get the resulting pid value.
>>>>
>>>>      Is there a basic example I can learn from for such query ?
>>>>
>>>> Cheers
>>>>
>>>> --
>>>> 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 [email protected].
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/python_inside_maya/557091F0.5010808%40gmail.com
>>>> .
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>  --
>>> 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 [email protected].
>>>
>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2v4%3DcwYoqi0oDVM4mte7_2fUeW_DEGE37QO9RVhV_7HQ%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2v4%3DcwYoqi0oDVM4mte7_2fUeW_DEGE37QO9RVhV_7HQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>
>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> Nicholas Yue
>> Graphics - Arnold, Alembic, RenderMan, OpenGL, HDF5
>> Custom Dev - C++ porting, OSX, Linux, Windows
>> http://au.linkedin.com/in/nicholasyue
>> https://vimeo.com/channels/naiadtools
>>
>> --
>> 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 [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/python_inside_maya/CADYXiJLOANuRcT6xBjP-bcTF_jGo7YU4rSLN47WE6816RmnpQg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/python_inside_maya/CADYXiJLOANuRcT6xBjP-bcTF_jGo7YU4rSLN47WE6816RmnpQg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>  --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1L-qtvFtuJ_KJ_Tt-3t8FAj8Dut7rstMuLBUCjhf07Zw%40mail.gmail.com
> <https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1L-qtvFtuJ_KJ_Tt-3t8FAj8Dut7rstMuLBUCjhf07Zw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Nicholas Yue
Graphics - Arnold, Alembic, RenderMan, OpenGL, HDF5
Custom Dev - C++ porting, OSX, Linux, Windows
http://au.linkedin.com/in/nicholasyue
https://vimeo.com/channels/naiadtools

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CADYXiJJYNkgC9iz182vumA%3D4sswkn5mrXMXMbqYqJMz56upmbA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to