Sublime Forum

Executing mel or python script from sublime to Maya

#1

Hi,

Not sure if this has been discussed before but is it possible to pass a script to maya (3d package)???
Something like a text editor called maxya do (They were made especially for Maya BTW)

Second, can I import a text of command list (maya commands) so sublime recognize it to auto complete?

Thank you all

C

0 Likes

#2

bump… noone?

0 Likes

#3

Come on… Someone??? Please?

0 Likes

#4

Not sure about the first question because I don’t use Maya but I can help with the second. You can create a sublime-completions file that adds a list of words to autocomplete: docs.sublimetext.info/en/latest/ … tions.html

0 Likes

#5

I’m also interested in having a connection to Maya (using a hotkey, python code is sent to Maya’s script editor via a software port and then executed. I’m replying here to keep track of the topic.
Thanks.

0 Likes

#6

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')
0 Likes

#7

[quote=“hoolymama”]First open a commandPort in Maya

commandPort -n ":2222";

Here is a sublime text plugin that sends the selection to that port.
…8<…
[/quote]

The whole package, including MEL syntax highlighting and some common snippets can be found on bitbucket. Go to your packages directory and type:

:git clone git@bitbucket.org:hoolymama/mel.tmbundle.git MEL

The send_to_maya command will appear in the right mouse context menu over the view.

Hope it helps

0 Likes

#8

@hoolymama
Sorry for the noob question…I have downloaded your MEL repository into my …\AppData\Roaming\Sublime Text 2\Packages\ directory…but I’m not seeing the syntax highlighting. What am I doing wrong?

0 Likes

#9

Thank you so much for the tip.

It worked on MEL script. How can i modify it to run with python as well?
And last, I was trying to bind the send to maya command to a hotkey but it’s wuite hard to trace what shortcut is still available in hotkey editor. Any tip?

Thanks again i really appreciate it

0 Likes

#10

nevermind. Thanks a lot for your contribution.

For those who cannot get the hotkey to work, the syntax highlighteron the bottom right has to be set to a correct one (mel or python)

0 Likes

#11

got it sending to Maya now, but won’t work on multiline python.

0 Likes