I spent some time this weekend trying to figure out how to run an external process and send any updates back to Maya. I'm not too familiar with network programming but with some scrounging around on blogs and stack-overflow of course, I started to get a reasonable understanding of socket communication. After writing and debugging many examples I have a working server, an external process updating that server and several clients that receive the process updates from the server.
My last goal was to have this external process inform Maya and the tool that resides in Maya, of any updates that may need to be made. If you've written any Python and user interfaces with Python you are likely familiar with GIL (global interpreter lock). In a simplified explanation you could being running a process that will lock up your tool and any parent of the tool, in this case Maya. By using threads you can run your processes in the background and not lock up your tool or Maya. Well, it's less likely to happen. Now that I can communicate with Maya from an external source, I should be able to update any tools within as needed.
Many thanks to the TDAnon guys, including @DhruvGovil for pointing me in the right direction.
Here is an example of me sending external messages to Maya. The scripts I use can be found below.
Thank you, Randall!
ReplyDeleteOnly would to mention that Maya now using the syntax "except Exception as e:", not "except Exception, e:"
Just in case if anybody have a syntax error in Maya 2022, for example...
Cheers!
Vlad
PS. Also, I'd like to suggest to use: message = message.encode() instead of .strip()
ReplyDeleteAnd, on Maya side: data = client.recv(1024).decode()
So, you will don't need to use quotes on input.