Maya lets the user access to its scene over the network with commandPort. Recently I felt the need of sending Python command instead of MEL script. I could use commadnPort and use MEL commnd 'python' everytime but I didn't like the way. I searched highend3d for it. I found a tool 'mapy' http://www.highend3d.com/f/mapy but it's fully GUI based, and the source code doesn't seem to be open. So I made it myself. Since I used asyncore (one of Python module for easy network programming), currently it doesn't support multiple connections, and I made modification on purpose, it's somewhat different from Maya's standard commandPort.
Some of big differences are:
- You can open one port at a time.
- Close connection every time a command is executed and the error message is transmitted back.
- Only error messages are returned. (Currently it always returns null string when "MEL" is specified).
- Command is terminated until the server receives the terminator string.
(You may feel some of them big restrictions but for my usage it's enough ;)
To use the plug-in, just place everything in the plug-in dir and load pyCommandPort.py (not pyCommandPortImpl.py), then execute a MEL command (Why there are pyCommandPort and pyCommandPortImpl? I will write the reason on a different post).
pyCommandPort
It opens a port 7070 by default. You can see it's working using telnet command
telnet localhost 7070
and type
print range(5)
then you'll see the result in the script editor
# print range(5) #
[0, 1, 2, 3, 4]
There are several flags available.
-address(-a)
Address. e.g. "192.168.0.3", "localhost", "".
It defaults to "".
-port(-p)
Port number. Any unused port number between 1024-65535 will do.
It defaults to 7070.
The command fails if the port is already used.
In that case use another number.
-shutdown(-sd)
If this flag is specified, it stops the server.
-terminator(-t)
Command terminator string.
It defaults to '\r\n' (i.e. enter)
-scriptlang(-sl)
"Python" or "MEL". Defaults to "Python"
-displaycommand(-dc)
On or off.
If on, it shows commands to be executed on the script
editor. It defaults to on.
-query(-q)
Query sever settings. Use with other flags.
It returns value only when the server is running
except -shutdown.
I put the source code here. Note that this is still a beta version.
http://hohehohe2.hp.infoseek.co.jp/misc/pyCommandPort/source.zip
No comments:
Post a Comment