First open a commandPort in Maya
commandPort -n ":2222";
Here is a sublime text plugin that sends the selection to that port.
import sublime, sublime_plugin, socket, re
class SendToMayaCommand(sublime_plugin.TextCommand):
def run(self, edit):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('localhost', 2222))
regions = self.view.sel()
for r in regions:
txt = self.view.substr(r)
txt = re.sub('//.*?(\r\n?|\n)|/\*.*?\*/', '', txt, re.S)
txt = txt.replace('\n', ' ').replace('\r',' ')
s.send(txt)
s.close()
Each region is treated as submission. I guess there will usually be only one.
The regex gets rid of comments in a fairy naive way.
Then the next line puts the whole script on one line so you can submit multiline scripts.
To run, select the code you want to send, and enter the following in the console:
view.run_command('send_to_maya')