Can't find the right function call from Py3DsMax (blur-dev) for selectionSetChanged
Hello everyone.
Using information here:
http://www.scriptspot.com/forums/3ds-max/general-scripting/py3dsmax-glob...
I'm trying to detect any selection change and execute a function in my python script. So far, I have this line:
mxs.callbacks.addScript(mxs.pyhelper.namify("selectionSetChanged"), "python.exec('test = callBack()\ntest.selCallBack()\n')", id = mxs.pyhelper.namify("scene_explorer"))
scene_explorer.py being the name of my script. It does not gives any error, but it does not execute selCallBack().
If anyone could give me any help on how this is supposed to work, it would be great. I can't find any other kind of information about this.
This is my code:
from blurdev.gui import Dialog
from Py3dsMax import mxs
import sys
from PyQt4 import QtGui,QtCore
from PyQt4.QtCore import QSignalMapper, pyqtSignal
from PyQt4.QtGui import QPalette
class callBack:
def selCallBack(self):
print "selCallBack!"
class sceneExplorer(Dialog):
def __init__(self, parent = None):
super(sceneExplorer, self).__init__()
self.initUI()
def initUI(self):
self.last_sel_index = -1
self.setWindowTitle('Scene Explorer')
mxs.callbacks.addScript(mxs.pyhelper.namify("selectionSetChanged"), "python.exec('test = callBack()\ntest.selCallBack()\n')", id = mxs.pyhelper.namify("scene_explorer"))
QtGui.QToolTip.setFont(QtGui.QFont('SansSerif', 10))
self.horizontalLayout = QtGui.QGridLayout(self)
self.scrollArea = QtGui.QScrollArea(self)
self.scrollArea.setWidgetResizable(True)
self.scrollAreaWidgetContents = Dialog()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 380, 280))
self.horizontalLayout_2 = QtGui.QHBoxLayout(self.scrollAreaWidgetContents)
self.gridLayout = QtGui.QGridLayout()
self.gridLayout.setSpacing(0)
self.horizontalLayout_2.addLayout(self.gridLayout)
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.add_button = QtGui.QPushButton("Refresh Explorer")
self.center_button = QtGui.QPushButton("Center Window")
self.horizontalLayout.addWidget(self.scrollArea, 1, 0)
self.horizontalLayout.addWidget(self.add_button, 0, 0)
self.horizontalLayout.addWidget(self.center_button, 0, 1)
self.connect(self.add_button, QtCore.SIGNAL("clicked()"), self.addButtons)
self.connect(self.center_button, QtCore.SIGNAL("clicked()"), self.center)
self.setGeometry(300, 200, 400, 300)
def addChildren (self, button_index, obj, row):
signalMapper = QSignalMapper(self)
for child in obj.Children:
button_index = button_index + 1
if len(child.Children):
self.expand_button = QtGui.QPushButton("-")
else:
self.expand_button = QtGui.QPushButton(" ")
self.expand_button.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed,QtGui.QSizePolicy.Fixed))
self.expand_button.setMaximumSize(10,10)
self.child_button = QtGui.QPushButton(child.name)
self.child_button.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum,QtGui.QSizePolicy.Fixed))
self.child_button.setMaximumSize(10000,16)
self.child_button.setToolTip(child.name)
self.gridLayout.addWidget(self.expand_button, button_index, row)
self.gridLayout.addWidget(self.child_button, button_index, row + 1)
self.child_button.setAutoFillBackground(True)
self.all_buttons.append(self.child_button) # a collection of all buttons
self.all_max_obj.append(child) # a collection of the max objects
signalMapper.setMapping(self.child_button, button_index) # map a value to the button
self.child_button.clicked.connect(signalMapper.map) #connect to signalMapper
button_index = self.addChildren(button_index, child, row + 2)
signalMapper.mapped.connect(self.highlightButton) #connect signalMapper to highlightButton
return button_index
def addButtons(self):
self.all_buttons = []
self.all_max_obj = []
highlightButton = pyqtSignal(int)
signalMapper = QSignalMapper(self)
button_index = 0
for obj in mxs.objects:
if obj.Parent == None:
if len(obj.Children):
self.expand_button = QtGui.QPushButton("-")
else:
self.expand_button = QtGui.QPushButton(" ")
self.expand_button.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed,QtGui.QSizePolicy.Fixed))
self.expand_button.setMaximumSize(10,10)
self.obj_button = QtGui.QPushButton(obj.name)
self.obj_button.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum,QtGui.QSizePolicy.Fixed))
self.obj_button.setMaximumSize(10000,16)
self.obj_button.setToolTip(obj.name)
self.gridLayout.addWidget(self.expand_button, button_index, 0)
self.gridLayout.addWidget(self.obj_button, button_index, 1)
self.obj_button.setAutoFillBackground(True)
self.all_buttons.append(self.obj_button) # a collection of all buttons
self.all_max_obj.append(obj) # a collection of the max objects
signalMapper.setMapping(self.obj_button, button_index) # map a value to the button
self.obj_button.clicked.connect(signalMapper.map) #connect to signalMapper
button_index = self.addChildren(button_index, obj, 2)
button_index = button_index + 1
signalMapper.mapped.connect(self.highlightButton) #connect signalMapper to highlightButton
def highlightButton(self,index):
palette = QPalette()
if self.last_sel_index != -1:
self.color = QtGui.QColor(215, 215, 215)
palette.setColor(QPalette.Button, self.color)
self.all_buttons[self.last_sel_index].setPalette(palette) # remove highlight
actual_color = self.all_buttons[index].palette().color(1) #sample actual_color
if actual_color == QtGui.QColor(255, 127, 127):
self.color = QtGui.QColor(215, 215, 215)
else:
self.color = QtGui.QColor(255, 127, 127)
palette.setColor(QPalette.Button, self.color)
self.all_buttons[index].setPalette(palette) # apply new color
self.selectObject(index)
self.last_sel_index = index
def selectObject(self, index):
try:
mxs.select (self.all_max_obj[index])
except IOError:
mxs.select (None)
def center(self):
qr = self.frameGeometry()
cp = QtGui.QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
def selCallBack(self):
print "selCallBack!"
def main():
import blurdev
blurdev.launch(sceneExplorer)
if __name__ == '__main__':
main() 
Comments
Just in case someone is
Just in case someone is looking for the answer.
Eat well, stay fit and die anyway.