I am trying to get values for the rotation of joints in Maya into an external IDE. I have successfully been able to send commands and Maya responds properly but I am having trouble understanding how to receive the results back in the IDE.
I have tried using socket.recv and socket.recvmsg but got errors for both.
Code running in PyCharm
import socket
host = 'localhost'
port = 7720
code1 = ("servo_1 = [cmds.getAttr('joint2.rotateY')]\\n"
"print servo_1")
try:
# Connect to Maya Command Port
maya = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
maya.connect( (host,port) )
# Send Command Through Socket --> Can Only Send MEL Commands
message = 'python("{}")'.format(code1)
print message
maya.send(message)
reply = maya.recv(4096)
print reply
except:
raise Exception, 'Connection Failed To : %s:%s' % (host, port)
finally:
#Close Socket Connection
maya.close()
Code in Maya to open the commandPort
import maya.cmds as cmds
if not cmds.commandPort(':7720', q=True, echoOutput=True, noreturn=False):
cmds.commandPort(name=':7720')
The expected output is [43.74] as is shown in Maya but the actual output in PyCharm