Message 1 of 3
How do I Execute Multi-Line commandPort Code?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've managed to send single-line commands via commandPort, but haven't figured out how to send multi-line Python code. I'm getting a lot weirdness on scripts that otherwise work if executed as shelf buttons. Maya reads the lines one by one, as separate commands!
This is my send_to_Maya.pyw script:
import socket
HOST = '127.0.0.1'
PORT = 54322 # I'm using 54321 for MEL and 54322 for Python commands
ADDR = (HOST, PORT)
def send_command():
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(ADDR)
command = '#HOW DO I PROPERLY FORMAT MULTILINE CODE HERE?'
message = command
client.send(str.encode(message))
data = client.recv(1024) # receive the result info
client.close()
print(data)
if __name__ == '__main__':
# Run this within Maya to open the ports. The port can be any 5 digits
"""
import maya.cmds as cmds
cmds.commandPort(name=":54322", sourceType="python")
"""
send_command()
Here's an example snippet that I want to send to Maya:
import maya.cmds as cmds
ver = cmds.about(v=True)
cmds.loadPlugin("ziCut_{}".format(ver))
if cmds.contextInfo('ziDrillCtx1', ex=True):
cmds.deleteUI('ziDrillCtx1', tc=True)
ziCutctx = cmds.ziDrillCtx()
cmds.setToolTo(ziCutctx)
^ How do I incorporate this in the send_to_Maya.pyw file?