commandPort

Its been long long time since I posted anything on my blog.

So here is a way to send data from Python to Maya and vice versa,

------------------------------------------------------------------------------------------------------------------------------

#echoFromMaya.py

import socket
import re

port = 3033

maya_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
maya_socket.connect((socket.gethostname(), port))
maya_socket.send(r'print"\nConnected to Python ...\n";')

while 1:
    data = maya_socket.recv(4096)
    data = data.replace("\n","")
    if re.search("callPythonSocketServer",data):
        print "Closing..."
        break

print "Socket closed"

------------------------------------------------------------------------------------------------------------------------------

in Maya,

commandPort -eo -n ":3033";   to connect to python socket

then,

print "Hi from Maya\n";   will print the string in command line, where python server is listening

and then finally, we are using this string "callPythonSocketServer" to tell python server to quit,

print "callPythonSocketServer";

 

Enjoy

:-)

No comments: