Receiving data from commandPort

202 views
Skip to first unread message

unnikris...@gmail.com

unread,
Jan 9, 2019, 8:26:18 PM1/9/19
to Python Programming for Autodesk Maya
Hi,

I'm sending a command through the commandPort (from a C# server) and it executes a bunch of other python commands in Maya. I get the response in my Maya console but none of this is being passed onto the C# server through the commandPort. The C# server prints 'None' (breakpoints) the same moment my Maya console is populated by the logs from the python code.

This is what opens the commandPort:

cmds.commandPort(name="localhost:8010", bufferSize=4096, sourceType="python", noreturn=False)

On the C# side, I have a NetworkStream.Read() that's fetching the data.

TIA

Justin Israel

unread,
Jan 9, 2019, 10:40:32 PM1/9/19
to python_in...@googlegroups.com
There is a difference between the logging I/O output and the return value of the function.  When I write a function like this:

def add(x, y):
    z = x + y
    print "OUTPUT:", z
    return z

I set the OUTPUT go to the Maya script editor, and the value 3 is returned in the commandPort stream. But one thing to be aware of is that if your command has multiple statements separated with a semicolon, then None will be returned:

$  echo '1+1 ; 2+2' | nc localhost 8010
None

$  echo '2+2' | nc localhost 8010
4

So if you need to send a bunch of logic, you might need to wrap it into a function and then have it return your output.


TIA

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/1e7024ea-354e-47a2-a9ca-05bb91c57149%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

unnikris...@gmail.com

unread,
Jan 10, 2019, 1:42:37 PM1/10/19
to Python Programming for Autodesk Maya
I'm doing something similar to what you said. I tried with the '|' operator but I was getting syntax errors returning through the commandPort. The below command is what I'm sending through the commandPort:

import maya.cmds ;
import os ;
proj_root = os.environ['PROJ_ENV'] ;
import sys ;
sys.path.append(proj_root + '\\plugins\\python\\maya') ;
import pluginTest ;
import imp ;
imp.reload(pluginTest) ;
pluginTest.SaveTest.save_file() ;

I'm only calling this function and its supposed to return the value once it's done. But I keep getting None as the response.

Justin Israel

unread,
Jan 10, 2019, 4:04:22 PM1/10/19
to python_in...@googlegroups.com
That isn't a function though. Its 9 different statements. The limitation of the commandPort is that it will only return a value if its a single statement. The problem though is that even if you wrap this into a "def do()" function, you still need more than one statement to call it, which means no return value. 

I just avoided this whole situation and used a custom socket for return output. 
 

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages