commandPort : Query output/results

157 views
Skip to first unread message

Nicholas Yue

unread,
Jun 4, 2015, 1:59:15 PM6/4/15
to python_in...@googlegroups.com
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

Justin Israel

unread,
Jun 4, 2015, 5:17:11 PM6/4/15
to python_in...@googlegroups.com
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)



--
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/557091F0.5010808%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Nicholas Yue

unread,
Jun 4, 2015, 5:37:13 PM6/4/15
to python_in...@googlegroups.com
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.



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

Justin Israel

unread,
Jun 4, 2015, 5:39:21 PM6/4/15
to python_in...@googlegroups.com
You need to recv from the first send() before you send again. 

Nicholas Yue

unread,
Jun 4, 2015, 5:41:16 PM6/4/15
to python_in...@googlegroups.com
Thanks Justin. It works

nyue@francoislake 146% python maya_command_port_pickle.py
19577



For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages