Search code examples
javascriptpythonweb-applicationsmaya

Connecting to Maya through javascript


I am working on an app for sending commands to Maya, much like the iOS app CameraMan. However, I am looking for a way to make this web-based, rather than building a native app. I believe this can be done, but I'm stuck on how to make that initial connection. Maya creates a commandport that is accessible via a specific ip address:port number. I can send commands from Eclipse, for example, or even short python scripts. I've seen this in action in a native app, but how to do this through Javascript?

Maya does offer a browser plugin that does this, but of course it's a plugin and won't work on mobile browsers nor can I customize it for the exact application I'm trying to make.

By way of background, I have basic knowledge of Javascript, Python, and MEL scripting.

Update: I should specify that I'm not looking to control Maya over the internet. Rather, I'm looking for a way to make a connection over a local network, where I know the ip address, just like the CameraMan app I referenced above (just not as a native app).

Update 2: Unfortunately, this project is a bit of a no-go at this point. What I didn't realize was that in order to enable websockets on the Maya "server," I'd need to implement some third party libraries. Fine for individual use, but not if I'm trying to release a tool for other people.


Solution

  • Everything is possible, might not be practical or in this case the license of Autodesk might be a tiny problem. First lets define JavaScript a bit better, see JavaScript is a programming language and the web browser embedded JavaScript is bound by the browser. Its not a general thing about JavaScript, not all JavaScript runs in a browser. The JavaScript inside a web browser bound by the security rules of a browser and a browser can not in general communicate with the overall system just with the data inside the webpage and a server. So in order for java script in browser to talk to Maya you need a server connection.

    Wrapping Maya as a web server is possible, I have done it in past with mel. Doing it with python would be easier. You can find existing demo code on CreativeCrash, tough its more of a proof of concept than anything else. There is not much you can do with the demo except introspect the open scene. Contrary to what some posts say the code should work as is. Its just hard to remotely debug peoples firewalls, as most firewall software will block the server unless otherwise stated, many users block entire Maya from the outside world with a override so be sure to check those things carefully.

    Alternatively you can just take a existing java script telnet tool and telnet to a non filtered Maya command port and directly call mel/python inside Maya over that. Something like anyterm would fit the bill. I've successfully used Maya with a phone ssh application before to fix a script error on a my vacation. This could be a easier attack vector if you need to just have programmatic access.

    When you do something like this be sure you understand that there is a big security problem involved with this. Maya has full user access to the system, often full admin access. Maya can call everything on the computer at user level so nothing stops an attacker to take over the entire computer remotely.

    PS: to be honest using a remote desktop or VNC over a private virtual network would probably be much better option.