PDA

View Full Version : sending raw MEL code over Python socket connection


cgbeige
02-11-2011, 01:13 AM
I got annoyed that BBEdit doesn't have the ability to natively send MEL to Maya so I started playing around imitating how Textmate does it (with commandPort) and am very close to having something working. It's fine with single lines of code but once you get line breaks, they need to be escaped or Python chokes on the execution:

$>python /tmp/sender.py (contents:)

import socket
maya = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
maya.connect(("127.0.0.1", 5055))

Maya_text = "sphere;
string $mySelection[] = `ls -sl`;
print $mySelection[0];"
maya.send(r''+Maya_text+'')


I'm not familiar with Python, so I'm wondering if there's a way to tell it to send the text without choking on the syntax, or should I write my stdout MEL contents to a file and have Python pipe that through the socket? Textmate uses Ruby so maybe this is an easier way to do it. Dunno.

cgbeige
02-11-2011, 01:52 AM
nevermind - I got it working, with no hassles with Ruby. Easier too since it's easier to work with stdin with Ruby. This works great with huge pieces of code:

http://grab.by/grabs/15ffe423a0c0b0edcca80ebd7d0054ef.png

results:

http://vimeo.com/19814187

cgbeige
02-12-2011, 05:39 PM
someone helped me with a Python version, in case someone was wondering what the code looks like.

http://www.can-con.ca/tumblrpics/automator_python.png

Be curious to see if someone could get something similar working in Linux. It would probably have to work with pasteboard contents or something since there's no Automator for Linux. But stdin, Python, etc are the same

CGTalk Moderation
02-12-2011, 05:39 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.