get current toolmode


#1

Hi there,

I want my script to recognize if the user changes the current tool mode (move, rotate, scale).
I have found the scriptJob command and assigned a function to the ToolChanged event, which works, but I don’t know how to find out which the current tool mode is.

Any ideas?


#2

try using the currentCtx comand


#3

thanks a lot, that works :wink:


#4

hm… ok, now i ran into another problem…

Here is a short description:
I have a python script with three checkbuttons, “Move”, “Rotate”, “Scale”.
All i want is a connection between these buttons and the current Tool Mode. I.e. when i select “Move” in Maya, i want the “Move” button in the script to be checked.

Since i have done such things a couple of times in 3dsmax with callbacks, i thought setting up a scriptJob would be the right way in Maya.
Well, theoretically it works, but there seems to be a problem with the connection to python. The scriptJob seems only to work when the python script is closed, as soon as i start the script, i don’t get any events…

here is the code i am using, it is not very functionally, just testing around:

########## IMPORT MODULES
 
 from PyQt4 import QtCore, QtGui
 from movetools_ui import Ui_win_MoveTools
 import sys
 import maya.cmds as mcmd
 
 
 class mt_MainWindow(QtGui.QMainWindow):
 	def __init__(self, parent=None):
 		QtGui.QMainWindow.__init__(self, parent)
 		self.ui = Ui_win_MoveTools()
 		self.ui.setupUi(self)		
 
 
 ####################################################################################################################################################
 ########## DEFINE CLASSES
 
 ####################################################################################################################################################
 ########## DEFINE GLOBAL VARIABLES
 
 global mtUI, _mt_ScriptJob_Tool_ID, _mt_ToolCallback
 
 mtUI = ""																  # Main UserInterface
 
 ####################################################################################################################################################
 ########## UI SETUP FUNCTIONS
 
 def _mt_fn_ResetTransButtons():
 	if mtUI.but_Move.isChecked() == True: mtUI.but_Move.toggle()
 	if mtUI.but_Rotate.isChecked() == True: mtUI.but_Rotate.toggle()
 	if mtUI.but_Scale.isChecked() == True: mtUI.but_Scale.toggle()
 
 def uiFN_Move_Click():
 	_mt_fn_ResetTransButtons()
 	mtUI.but_Move.toggle()
 	mcmd.setToolTo ("Move")
 	mcmd.refresh()
 
 def uiFN_Rotate_Click():
 	_mt_fn_ResetTransButtons()
 	mtUI.but_Rotate.toggle()
 	mcmd.setToolTo ("Rotate")
 	mcmd.refresh()
 	
 def uiFN_Scale_Click():
 	_mt_fn_ResetTransButtons()
 	mtUI.but_Scale.toggle()
 	mcmd.setToolTo ("Scale")
 	mcmd.refresh()
 
 def _mt_fn_setupUIconnections():										   # Setup UI Connections
 	# BUTTONS
 	mtUI.but_Move.connect(mtUI.but_Move, QtCore.SIGNAL("clicked()"), uiFN_Move_Click)
 	mtUI.but_Rotate.connect(mtUI.but_Rotate, QtCore.SIGNAL("clicked()"), uiFN_Rotate_Click)	
 	mtUI.but_Scale.connect(mtUI.but_Scale, QtCore.SIGNAL("clicked()"), uiFN_Scale_Click)	
 	# END
 
 
 ##########################################################################
 ########## DEFINE FUNCTIONS
 
 
 def _mt_ToolCallback():
 	currentTool = mcmd.currentCtx()
 	print currentTool
 	
 def _mt_fn_Startup():													   # Initialize
 	print "START"
 	_mt_ScriptJob_Tool_ID = mcmd.scriptJob (event = ["ToolChanged", _mt_ToolCallback])
 
 
 
 
 ####################################################################################################################################################
 ########## MAIN LOOP
 
 
 if __name__ == '__main__':	
 	app = QtGui.QApplication(sys.argv)
 	
 	mt_MainWindow = QtGui.QMainWindow()
 	mtUI = Ui_win_MoveTools()
 	mtUI.setupUi(mt_MainWindow)
 	mt_MainWindow.show()
 	
 	_mt_fn_setupUIconnections()
 	_mt_fn_Startup()
   
 	
 	sys.exit(app.exec_())
 
 
 
 ####################################################################################################################################################
 ########## END
 ####################################################################################################################################################
 
 

anyone has an idea what i am doing wrong?


#5

Hi
Just idea:
how about using QTimer in scriptJob place?

cheers


#6

Yes, using a timer would be plan B :wink:

But I don’t really like that method, so I hope there will be a cleaner solution for this. It seems to have something do to with the maya ui-thread, found some stuff about it but not very clear…

thanks anyway!


#7

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.