here's a quick and dirty way:
import socket
import re
stringOPy = """
print "howdy"
class X():
def __init__(self):
print "in X.__init__"
x = X()"""
stringOPy = stringOPy.replace('"','\\"')
stringOPy = re.sub("\n","\\\\n",stringOPy)
print stringOPy
HOST = 'localhost'
PORT = 7720
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.send("python(\""+ stringOPy + "\")"+ "\n")
s.close()
On Feb 1, 11:34 am, AK Eric <[email protected]> wrote:
> To my knowledge, Maya intercepts incoming commands as mel,
> irregardless of send methodology. You can send any type of data you
> want to Maya over the socket... but Maya will expect it to be mel when
> it receives it. I've not used MayaPad, but maybe it does something
> similar to what I do to work around this issue. Goes more or less
> like this:
>
> Open command port in Maya.
> In external app connect to that socket, save python code out as
> temp.py file.
> Ping Maya through command port to exec on temp.py.
>
> I do this via the API of my IDE: I can query what is hilighted, save
> that out as temp.py, and then have Maya execute it... lets me bypass
> the Maya script editor entirely.
> As an aside: While you can open a socket with both mel and Python...
> I've found that no matter what I do, if I open a socket with Python,
> the above solution won't work.. I have to open it with mel.
> Frustrating.
>
> On Feb 1, 6:27 am, Jo Jürgens <[email protected]> wrote:
>
> > MayaPad does just that. Its a wxPython Python editor that can send commands
> > to Maya. Maybe you can copy the way its done there
>
> >http://code.google.com/p/mayapad/
>
> > On Mon, Feb 1, 2010 at 9:05 AM, Shaun Friedberg
> > <[email protected]>wrote:
>
> > > Right, perhaps I miss-spoke…
>
> > > I use Python to open a socket and then send Mel code.
>
> > > My question is does anyone know how to send Python code instead of Mel…
>
>
--
http://groups.google.com/group/python_inside_maya