通过Python套接字将多行命令发送到Maya [英] Sending multiline commands to Maya Through Python Socket

查看:147
本文介绍了通过Python套接字将多行命令发送到Maya的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种方法可以通过python套接字和Maya自己的"commandPort"命令向Maya发送多行命令?

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?

我正在使用以下代码将代码发送到maya("message"值为命令):

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()

当我发送诸如polyCube()之类的单个命令时,它可以工作,但是例如发送一个python 命令,例如:

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()

引发无效语法错误"!

推荐答案

尝试:

command = 'import maya.cmds as mc\n mc.polyCube()'

这篇关于通过Python套接字将多行命令发送到Maya的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆