i want to pass multiline python command as a string variable to maya commandPort in following format. But looks like it errors out , when executed in maya through port. It erros as Unterminated string. //
In maya , i have opened a command port as
import maya.cmds as cmds cmds.commandPort(name=":6001")
Here is the command i execute in nuke to pass to maya command port , when supplied multiline command in form code1 variable it doesnt work, but when we supply command in code2 , it works. Is there a way to pass long multiline command string without using \n or ; in the same line ?
### multiline string like below doesn't work, errors as unterminated sring
code1="""
cmds.polySphere()
"""
### if supplied in below format ,it works
code2="cmds.polySphere()"
import socket
host = 'localhost'
port = 6001
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)
except:
raise Exception, 'Connection Failed To : %s:%s' % (host, port)
finally:
# Close Socket Connection
maya.close()