forked from akmrsk/maxscript-mode
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmaxCom.py
62 lines (51 loc) · 2.02 KB
/
maxCom.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
""" Communicate with 3dsMax
"""
import winCom
MAX_TITLE_IDENTIFIER = r"Autodesk 3ds Max"
MAX_SCINTILLA = r"MXS_Scintilla"
MAX_LISTENER_IDENTIFIER = r"MAXScript Listener"
MAX_NOT_FOUND = r"Could not find a 3ds Max instance."
RECORDER_NOT_FOUND = r"Could not find MAXScript Macro Recorder"
OUTPUT_NOT_FOUND = r"Could not find the Listener Output window"
CommunicatorInstance = None
def getCommunicator():
global CommunicatorInstance
if not CommunicatorInstance:
mw = _getMainWindow()
CommunicatorInstance = MaxCommunicator(mw)
return CommunicatorInstance
def _getMainWindow():
mw = winCom.get_window_by_title(MAX_TITLE_IDENTIFIER)
if not mw:
raise winCom.WindowNotFoundException(MAX_NOT_FOUND)
return mw
class MaxCommunicator():
def __init__(self, maxMainWindow):
self.mainWindow = maxMainWindow
self.miniMacroRecorder = self.mainWindow.get_child_window(cls = MAX_SCINTILLA,
instance = 1)
if not self.miniMacroRecorder:
raise winCom.WindowNotFoundException(RECORDER_NOT_FOUND)
listenerWin = self.mainWindow.get_thread_window(name = MAX_LISTENER_IDENTIFIER)
self.logWindow = listenerWin.get_child_window(cls = MAX_SCINTILLA,
instance = 1)
if not self.logWindow:
raise winCom.WindowNotFoundException(OUTPUT_NOT_FOUND)
def sendCmdToMax(self, cmd):
self._connect()
self.miniMacroRecorder.set_text(cmd)
self.miniMacroRecorder.send_return()
self._disconnect()
def getOutputFromMax(self):
self._connect()
text = self.logWindow.get_text()
self._disconnect()
return text
def clearListenerOutput(self):
self._connect()
self.logWindow.set_text(unicode(""))
self._disconnect()
def _connect(self):
winCom.attachThreads( self.mainWindow.hwnd )
def _disconnect(self):
winCom.detachThreads( self.mainWindow.hwnd )