Created
November 2, 2014 20:44
-
-
Save RicardoViana/9e0f182332d50df07d10 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
| ############################################# | |
| # | |
| # Custom Set Driven Key | |
| # | |
| # | |
| # | |
| # by Ricardo Viana. www.you-lab.com | |
| # 2 November 2014 | |
| # | |
| # works only in Maya 2014 | |
| # or if you have Pyside installed. | |
| # | |
| # | |
| # | |
| ############################################# | |
| from PySide import QtGui, QtCore | |
| import maya.cmds as cmds | |
| import maya.OpenMayaUI as omui | |
| from shiboken import wrapInstance | |
| def maya_main_window(): | |
| main_window_ptr = omui.MQtUtil.mainWindow() | |
| return wrapInstance (long(main_window_ptr), QtGui.QWidget) | |
| class setDriven(object): | |
| def __init__(self): | |
| self.showUI() | |
| self.driver = "" | |
| self.driven = "" | |
| self.driverAttr = "" | |
| self.drivenAttr = "" | |
| def loadDriverAttrs(self): | |
| sel = cmds.ls(sl=True) | |
| self.driverList.clear() | |
| self.driverList.addItems(cmds.listAttr(sel[0],k = True)) | |
| self.driverLabel.setText("Driver: %s Attributes" %sel[0]) | |
| self.driver = sel[0] | |
| def loadDrivenAttrs(self): | |
| sel = cmds.ls(sl=True) | |
| self.drivenList.clear() | |
| self.drivenList.addItems(cmds.listAttr(sel[0],k = True)) | |
| self.drivenLabel.setText("Driven: %s Attributes" %sel[0]) | |
| self.driven = sel[0] | |
| def setDriverAttr(self): | |
| self.driverAttr = "%s.%s"%(self.driver,self.driverList.selectedItems()[0].text()) | |
| self.driverValue.setValue(cmds.getAttr(self.driverAttr)) | |
| def setDrivenAttr(self): | |
| self.drivenAttr = "%s.%s"%(self.driven,self.drivenList.selectedItems()[0].text()) | |
| self.drivenValue.setValue(cmds.getAttr(self.drivenAttr)) | |
| def changeDriverAttr(self): | |
| if self.driverAttr != "": | |
| value = self.driverValue.value() | |
| cmds.setAttr(self.driverAttr,value) | |
| self.driverValue.setStyleSheet(self.boxStyle) | |
| def changeDrivenAttr(self): | |
| if self.drivenAttr != "": | |
| value = self.drivenValue.value() | |
| cmds.setAttr(self.drivenAttr,value) | |
| self.drivenValue.setStyleSheet(self.boxStyle) | |
| def setKey(self): | |
| if self.drivenAttr != "" and self.driverAttr != "": | |
| cmds.setDrivenKeyframe( self.drivenAttr, cd = self.driverAttr ) | |
| self.driverValue.setStyleSheet("background-color: #FFB4D9 ; color: #000000") | |
| self.drivenValue.setStyleSheet("background-color: #FFB4D9 ; color: #000000") | |
| else: | |
| cmds.warning("please add a driver and driven") | |
| def showUI(self): | |
| self.window = QtGui.QWidget(parent = maya_main_window()) | |
| self.window.setWindowFlags (QtCore.Qt.Window) | |
| self.window.setGeometry(400,400,275,300) | |
| self.window.setWindowTitle("RV Set Driven Keyer") | |
| self.windowStyle = "background-color:#555555; color: #999999" | |
| self.window.setStyleSheet(self.windowStyle) | |
| #widgets | |
| self.driverLabel = QtGui.QLabel("Driver Attributes") | |
| self.driverList = QtGui.QListWidget() | |
| self.boxStyle = "background-color:#444444; color: #999999" | |
| self.driverList.setStyleSheet(self.boxStyle) | |
| self.driverList.itemSelectionChanged.connect(self.setDriverAttr) | |
| self.drivenLabel = QtGui.QLabel("Driven Attributes") | |
| self.drivenList = QtGui.QListWidget() | |
| self.drivenList.setStyleSheet(self.boxStyle) | |
| self.drivenList.itemSelectionChanged.connect(self.setDrivenAttr) | |
| self.buttonsWidget = QtGui.QWidget() | |
| self.buttonLayout = QtGui.QHBoxLayout() | |
| self.buttonsWidget.setLayout(self.buttonLayout) | |
| self.loadDriver = QtGui.QPushButton("Load Driver") | |
| self.loadDriven = QtGui.QPushButton("Load Driven") | |
| self.loadDriver.clicked.connect(self.loadDriverAttrs) | |
| self.loadDriven.clicked.connect(self.loadDrivenAttrs) | |
| self.buttonLayout.addWidget(self.loadDriver) | |
| self.buttonLayout.addWidget(self.loadDriven) | |
| self.driverValueLabel = QtGui.QLabel("Driver Value:") | |
| self.driverValue = QtGui.QDoubleSpinBox() | |
| self.driverValue.setMinimum(-500000000) | |
| self.driverValue.setMaximum(500000000) | |
| self.driverValue.setDecimals(3) | |
| self.driverValue.setStyleSheet(self.boxStyle) | |
| self.driverValue.valueChanged.connect(self.changeDriverAttr) | |
| self.drivenValueLabel = QtGui.QLabel("Driven Value:") | |
| self.drivenValue = QtGui.QDoubleSpinBox() | |
| self.drivenValue.setMinimum(-500000000) | |
| self.drivenValue.setMaximum(500000000) | |
| self.drivenValue.setDecimals(3) | |
| self.drivenValue.setStyleSheet(self.boxStyle) | |
| self.drivenValue.valueChanged.connect(self.changeDrivenAttr) | |
| self.driverValuesWidget = QtGui.QWidget() | |
| self.driverValuesLayout = QtGui.QHBoxLayout() | |
| self.driverValuesWidget.setLayout(self.driverValuesLayout) | |
| self.driverValuesLayout.addWidget(self.driverValueLabel) | |
| self.driverValuesLayout.addWidget(self.driverValue) | |
| self.drivenValuesWidget = QtGui.QWidget() | |
| self.drivenValuesLayout = QtGui.QHBoxLayout() | |
| self.drivenValuesWidget.setLayout(self.drivenValuesLayout) | |
| self.drivenValuesLayout.addWidget(self.drivenValueLabel) | |
| self.drivenValuesLayout.addWidget(self.drivenValue) | |
| self.keyButton = QtGui.QPushButton("Key") | |
| self.keyButton.setStyleSheet("background-color:#111111 ; color: rgb(0,125,0)") | |
| self.keyButton.clicked.connect(self.setKey) | |
| self.mainLayout = QtGui.QVBoxLayout() | |
| self.mainLayout.addWidget(self.driverLabel) | |
| self.mainLayout.addWidget(self.driverList) | |
| self.mainLayout.addWidget(self.drivenLabel) | |
| self.mainLayout.addWidget(self.drivenList) | |
| self.mainLayout.addWidget(self.buttonsWidget) | |
| self.mainLayout.addWidget(self.driverValuesWidget ) | |
| self.mainLayout.addWidget(self.drivenValuesWidget) | |
| self.mainLayout.addWidget(self.keyButton) | |
| self.window.setLayout(self.mainLayout) | |
| self.window.show() | |
| if __name__ == "__main__": | |
| new = setDriven() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment