Created
February 4, 2014 23:59
-
-
Save pumacamargo/8814922 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket, os | |
from org.gjt.sp.jedit import Macros | |
#Grabs the currently selected text or else grabs the document | |
curText = (textArea.getSelectedText()) | |
if not curText: | |
curText = (textArea.getText()) | |
#Only goes forward if there is some text to work with | |
if curText: | |
#Strips off the extension from the name of the file to have a module name | |
scriptBuffer = view.getBuffer() | |
scriptName = scriptBuffer.getName() | |
module = os.path.splitext(scriptName)[0] | |
#Creates a temp directory | |
#Change this appropriately if working on OSX | |
tempDir = r"C:\temp" | |
if not os.path.isdir(tempDir): | |
os.makedirs(tempDir) | |
#Creates a temp file where the text is put | |
tempFile = os.path.join(tempDir, scriptName) | |
fObj = open(tempFile, 'w') | |
fObj.write(curText) | |
fObj.close() | |
#Makes a socket and tries to connect it into maya | |
mayaSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
try: | |
mayaSocket.connect(('localhost', 6000)) | |
except: | |
Macros.message(view, 'Please Open the socket in Maya and retry.') | |
#Creates the code string to hand to maya | |
#It's doing the following | |
#if module in dir(): | |
# reload(module) | |
#else: | |
# import module | |
cmd = 'python("if \\"' + module + '\\" in dir():' | |
cmd += 'reload(' + module + ');\\nelse:' | |
cmd += 'import ' + module + '");' | |
#Sends over the code and closes the socket | |
mayaSocket.send(cmd) | |
mayaSocket.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment