I'm writing a python tool passes commands into Maya. I got a socket going between Maya and my program, and I can pass MEL commands into Maya without a hitch. However, I've switched over to mostly python scripting in Maya, and I'd like to pass python commands over the commandPort. Maya throws an error at python commands, and even if I wrap them in python(""); it still doesn't like it.
Is there any way to inform Maya that the data coming over the commandPort is meant to be interpreted by python?
I wrote a tool for it before. http://www.highend3d.com/f/mapy. I used python command to pass python to maya. It works with multilines and long scripts also. I didn't find a way to send command to python directly and it is not needed. because python command works well.
Could you tell me more specifically what commands you're using in python to pass commands to maya so that it interprets them as python instead of mel? I tried to look at the library.zip file included with your software, but it appears that file is corrupt. When I open a commandPort it seems it's expecting MEL only to be coming through the socket. How do I tell it otherwise?
First, download latest version. I just update it. use mapy -check to see if you use latest version or not. Second you can use python command to send python scripts to maya. see this example:
python: mc.Sphere() mel: python("mc.Sphere()");
and this mel command sends mc.Sphere() command to python in maya. Join my Python-Maya Club for many useful info.
Everything is actually working when I wrap my commands in the python("") mel, but the command I was testing was "import maya.cmds as mc" and instead of returning something meaningful over the socket, Maya sends sends back "// WARNING: unknown result type" which I mistook for an error.
ok so are you saying that mapy runs the python (as python interpreter or such) and everytime it comes across a maya command it sends it to maya. because i know you can not send more than one line through wrapping with python(""), which would make for loops impossible and i depend on them soo much. i have not downloaded mapy cos im happy just using idle and maya, but it sounds like a nice idea to speed testing up.
well you can allways issue maya to read and execute the file on disk BUt yes you can listen to the data yourslef and do whatever you want with it even trough a command port and just lter decide what to do.
QUOTE because i know you can not send more than one line through wrapping with python("")
Then you know wrong!
python("for i in range(10):\r\n print \"foo\"\r\n print \"bar\"")
works fine for me and it has 3 lines, as does:
python("for i in range(10):\n print \"foo\"\n print \"bar\"")
i admit i slightly misunderstood the API but it still has a one line limit, so atleast im not going completely crazy
"This command may be used to execute Python scripts from MEL. The command is passed a string containing a snippet of Python code. That code is then executed and the result in resturned to MEL. Note that only single-line Python scripts will return a result due to a limitation in the Python interpreter"