<p>我想知道有没有办法通过python套接字和maya自己的“commandPort”命令向maya发送多行命令?</p>
<p>我使用以下代码将代码发送到maya(“消息”值是命令):</p>
<pre><code>import socket
#HOST = '192.168.1.122' # The remote host
HOST = '127.0.0.1' # the local host
PORT = 54321 # The same port as used by the server
ADDR=(HOST,PORT)
def SendCommand():
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(ADDR)
command = 'import maya.cmds as mc mc.polyCube()' # the commang from external editor to maya
MyMessage = command
client.send(MyMessage)
data = client.recv(1024) #receive the result info
client.close()
print 'The Result is %s'%data
if __name__=='__main__':
SendCommand()
</code></pre>
<p>当我发送一个像“polyCube()”这样的命令时,它可以工作,但是例如发送一个python
命令,例如:</p>
<pre><code>import maya.cmds as mc
mc.polyCube()
</code></pre>
<p>引发“无效语法错误”!</p>