Home Download Buy Blog Forum Support

Executing mel or python script from sublime to Maya

Executing mel or python script from sublime to Maya

Postby cloud68 on Sun Apr 01, 2012 12:42 pm

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
cloud68
 
Posts: 5
Joined: Sun Apr 01, 2012 12:39 pm

Re: Executing mel or python script from sublime to Maya

Postby cloud68 on Wed Apr 11, 2012 5:51 am

bump... noone?
cloud68
 
Posts: 5
Joined: Sun Apr 01, 2012 12:39 pm

Re: Executing mel or python script from sublime to Maya

Postby cloud68 on Mon Jun 04, 2012 2:39 am

Come on... Someone??? Please?
cloud68
 
Posts: 5
Joined: Sun Apr 01, 2012 12:39 pm

Re: Executing mel or python script from sublime to Maya

Postby C0D312 on Mon Jun 04, 2012 2:45 am

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: http://docs.sublimetext.info/en/latest/ ... tions.html
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Executing mel or python script from sublime to Maya

Postby pixeldroid on Tue Jul 03, 2012 4:02 am

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.
pixeldroid
 
Posts: 1
Joined: Tue Jul 03, 2012 3:58 am

Re: Executing mel or python script from sublime to Maya

Postby hoolymama on Tue Jul 03, 2012 10:43 am

First open a commandPort in Maya

Code: Select all
commandPort -n ":2222";


Here is a sublime text plugin that sends the selection to that port.

Code: Select all
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:
Code: Select all
view.run_command('send_to_maya')
hoolymama
 
Posts: 3
Joined: Tue Jul 03, 2012 7:37 am

Re: Executing mel or python script from sublime to Maya

Postby hoolymama on Tue Jul 03, 2012 10:26 pm

hoolymama wrote:First open a commandPort in Maya

Code: Select all
commandPort -n ":2222";


Here is a sublime text plugin that sends the selection to that port.
.......8<.......


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

Code: Select all
: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
hoolymama
 
Posts: 3
Joined: Tue Jul 03, 2012 7:37 am

Re: Executing mel or python script from sublime to Maya

Postby Mambo4 on Tue Sep 11, 2012 4:27 pm

@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?
Mambo4
 
Posts: 6
Joined: Sat Sep 08, 2012 5:53 pm

Re: Executing mel or python script from sublime to Maya

Postby cloud68 on Mon Sep 24, 2012 1:03 am

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
cloud68
 
Posts: 5
Joined: Sun Apr 01, 2012 12:39 pm

Re: Executing mel or python script from sublime to Maya

Postby cloud68 on Mon Sep 24, 2012 11:39 am

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)
cloud68
 
Posts: 5
Joined: Sun Apr 01, 2012 12:39 pm

Next

Return to General Discussion

Who is online

Users browsing this forum: Yahoo [Bot] and 27 guests