通过 Python Socket 向 Maya 发送多行命令
我想知道有没有办法通过python套接字和Maya自己的“commandPort”命令向maya发送多行命令?
我使用下面的代码将代码发送到maya(“message”值是命令):
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()
当我发送像“polyCube()”这样的单个命令时,它可以工作,但例如发送一个python 命令例如:
import maya.cmds as mc
mc.polyCube()
引发“无效语法错误”!
I want to know is there a way to send a multiline command to maya through python socket and the Maya's own "commandPort" command?
I'm using below code for sending the code to maya("message" value is the command):
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()
When I send a single command like 'polyCube()' it works but for example sending a python
Command such as:
import maya.cmds as mc
mc.polyCube()
Raises an "invalid syntax error"!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试:
Try:
要向 Maya 发送小命令,@pajton 的方法有效,或者您可以使用
;
作为分隔符:如果可能,一次发送多行的最简单方法是创建单独的
.py Maya 有权访问的
文件。For sending small commands to Maya, @pajton's method works, or you can use
;
as a separator:If possible, the easiest way to send many lines at once is to create a separate
.py
file that Maya has access to.