Receving data in Maya commandPort

29 views
Skip to first unread message

unnikris...@gmail.com

unread,
Jan 9, 2019, 3:05:46 PM1/9/19
to Python Programming for Autodesk Maya
Hi,

I've been using Maya commandPort to input commands into Maya and it works fine.

I was wondering if there's a way to fetch the input command that's coming through the socket? This way, I don't want to send a command but send a string which invokes a function in my python code inside Maya.

Is there some form of listener I can add to the commandPort command in Maya?
I have echoOutput=true and that echoes the output as it says. But I can't seem to catch the string that's coming through the socket.

Thanks.

Justin Israel

unread,
Jan 9, 2019, 3:25:40 PM1/9/19
to python_in...@googlegroups.com
There is no hook to allow you to intercept the data on the commandPort socket before the commandPort evaluates the input. But this hook isn't actually neccessary. If you have created a python sourceType commandPort, then every string you are sending is evaluated as python source code. This may invoke whatever function you want (you can even use a python() call from MEL if its a default mel commandPort). So you may create whatever hook you want in Maya and invoke that as you see fit.

If you want a reference for this kind of logic you can review the work I have done on the MayaSublime project:


This plugin is responsible for running code from your SublimeText editor remotely within Maya over the commandPort. One aspect of that process is how it handles shuttling back the output text. The plugin will push a custom bit of code over the commandPort to be created in the Maya environment to install callbacks and open custom sockets.

 

Thanks.

--
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/5fb9f33d-e1d0-4a87-abd3-8366e5c9b303%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

unnikris...@gmail.com

unread,
Jan 9, 2019, 7:13:49 PM1/9/19
to Python Programming for Autodesk Maya
On Wednesday, 9 January 2019 12:25:40 UTC-8, Justin Israel wrote:
> On Thu, Jan 10, 2019 at 9:05 AM <unnikris...@gmail.com> wrote:
> Hi,
>
>
>
> I've been using Maya commandPort to input commands into Maya and it works fine.
>
>
>
> I was wondering if there's a way to fetch the input command that's coming through the socket? This way, I don't want to send a command but send a string which invokes a function in my python code inside Maya.
>
>
>
> Is there some form of listener I can add to the commandPort command in Maya?
>
> I have echoOutput=true and that echoes the output as it says. But I can't seem to catch the string that's coming through the socket.
>
>
>
> There is no hook to allow you to intercept the data on the commandPort socket before the commandPort evaluates the input. But this hook isn't actually neccessary. If you have created a python sourceType commandPort, then every string you are sending is evaluated as python source code. This may invoke whatever function you want (you can even use a python() call from MEL if its a default mel commandPort). So you may create whatever hook you want in Maya and invoke that as you see fit.
>
>
> If you want a reference for this kind of logic you can review the work I have done on the MayaSublime project:
>
>
> https://github.com/justinfx/MayaSublime/blob/master/MayaSublime.py
> https://github.com/justinfx/MayaSublime/blob/master/lib/pubScriptEditor.py
>
>
> This plugin is responsible for running code from your SublimeText editor remotely within Maya over the commandPort. One aspect of that process is how it handles shuttling back the output text. The plugin will push a custom bit of code over the commandPort to be created in the Maya environment to install callbacks and open custom sockets.
>
>
>  
>
>
> Thanks.
>
>
>

Thanks a lot Justin! As a follow-up, is there a way to know once I've performed certain Maya python commands. Like passing a success/failure? Do I write into the standard IO for the socket to pick it up or is there a better way of handling the same? Maybe by opening a new port and send the reply on that?

Justin Israel

unread,
Jan 9, 2019, 10:19:54 PM1/9/19
to python_in...@googlegroups.com
commandPort has the option to return the output from your commands, but I find it very limiting since it has a max size that could hit and kill your port. So in MayaSublime I open my own socket and take care of returning 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