Running Maya/Python commands from external editor

Hey I was wondering if any one could help me figure out how to run maya commands through an external editor (Aptana Studio 3). I’m not really sure where to start because I haven’t ever really done something like this before. I know it involves maya standalone but I don’t know where to go from there. I found a couple codes online but I didn’t understand what they were doing and they didn’t work when I tried running it. If anyone could shed some light and help me out I would really appreciate it. Thank you for your time.

#A few sources I found
http://forums.cgsociety.org/archive/index.php/t-966699.html
http://tech-artists.org/forum/showthread.php?t=1391
http://mayamel.tiddlyspot.com/

I use this ->
http://www.creativecrash.com/maya/downloads/applications/syntax-scripting/c/eclipse-maya-editor/

I agree with lemmon. You might find it easier to switch to a more commonly used IDE unless you have a specific reason to stick with Aptana.

For example this walk-through is what I used to get totally set up in Eclipse: Company Art Pipeline

Good luck. It is a tricky thing to set up at first.

Arite awesome, I’ll definitely check it out. The reason I wanted to figure out for aptana is so that I would get a better understanding of what was going so that i could do it for any external editor, but I’ll use this for now until I get a better understand of what is going on inside maya. Thank you guys for your help!

The basic overview premise is this:

Bind this to a hotkey (I use Eclipse Monkey to run a script):

  1. Grab your text from the editor (or from the current selection) Eclipse can do this by using code like this:

editor = window.getActivePage().getActiveEditor()
editorInput = editor.getEditorInput()
document = editor.getDocumentProvider().getDocument(editorInput)

  1. Send that text to a file somewhere in your scripts directories using a file object. I write to a file called ~/scripts/SENDTOMAYA.py
  2. Open a socket stream and connect it to a port (you’ll have to have already opened this port in Maya with something like this: mc.commandPort (name=‘localhost:7546’) (I have this on a shelf button)
  3. Send a command through the open socket that calls “import SENDTOMAYA” (or reload if it is already loaded)

The way this works is sort of like this (might not be 100% correct):


socketToMaya = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socketToMaya.connect(('localhost', 7546)) #same port as in Maya
myCommand = 'python("if \\"' + basename + '\\" in dir(): reload(' + basename + ');\
else: import ' + basename + '\
");'
socketToMaya .send(mayaCommand)
socketToMaya .close()

socketToMaya is the open socket that is running on a port. You send myCommand through it, which is just some text, but Maya knows how to interpret it because it is listening through the port you previous opened.

I hope that might make it a bit more clear.

Good luck!