Last active
July 7, 2016 18:35
-
-
Save whoiscarlo/217d91c19dec26cb6b58a4f55c908f22 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 sys | |
import shiboken | |
from PySide import QtCore, QtGui | |
import maya.cmds as mc | |
class TestUI(QtGui.QDialog): | |
def __init__(self, *args, **kws): | |
parent = kws.get('parent', None) | |
super(TestUI, self).__init__(parent=parent) | |
## Class variables | |
self.logic = Logic() | |
self.mapper = QtCore.QSignalMapper(self) | |
## Setup GUI | |
self._buildUI() | |
self._setupConnections() | |
def _buildUI(self): | |
''' | |
Purpose: Contains all window elements | |
''' | |
## Window Title | |
self.setWindowTitle('Zero Out') | |
## Main Layout | |
self._mainLayout = QtGui.QVBoxLayout() | |
self._mainLayout.setAlignment(QtCore.Qt.AlignCenter) | |
self.setLayout(self._mainLayout) | |
## Transform button | |
self._transformButton = QtGui.QPushButton('Transform') | |
self._mainLayout.addWidget(self._transformButton) | |
## Rotation | |
self._rotationButton = QtGui.QPushButton('Rotation') | |
self._mainLayout.addWidget(self._rotationButton) | |
## Custom | |
self._customButton = QtGui.QPushButton('Custom Attrs') | |
self._mainLayout.addWidget(self._customButton) | |
def _createPopup(self, widget, func, func2, args): | |
## Enable Right | |
widget.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) | |
widget.customContextMenuRequested.connect(func) | |
## Create Popup Menu | |
thisMenu = QtGui.QMenu(self) | |
for each in args: | |
label = 'Zero Out {0}'.format(each) | |
action = QtGui.QAction(label, self) | |
self.mapper.setMapping(action, each) | |
action.triggered.connect(self.mapper.map) | |
thisMenu.addAction(action) | |
return thisMenu | |
def _setupConnections(self): | |
''' | |
Purpose: Connect all GUI Elemenents to functions | |
''' | |
self._transformButton.clicked.connect(self._transformButton_clicked) | |
self._rotationButton.clicked.connect(self._rotationButton_clicked) | |
self._customButton.clicked.connect(self._customButton_clicked) | |
args = ['TX', 'TY', 'TZ'] | |
self._transformButton_Popup = self._createPopup(self._transformButton, self.show_transformButton_Popup, self.zeroOutSelected, args) | |
args = ['RX', 'RY', 'RZ'] | |
self._rotationButton_Popup = self._createPopup(self._rotationButton, self.show_rotationButton_Popup, self.zeroOutSelected, args) | |
self.mapper.mapped['QString'].connect(self.zeroOutSelected) | |
def show_transformButton_Popup(self, point): | |
''' | |
Show Popup Menu on Transform QPushButton | |
''' | |
self._transformButton_Popup.exec_(self._transformButton.mapToGlobal(point)) | |
def show_rotationButton_Popup(self, point): | |
''' | |
Show Popup Menu on Rotation QPushButton | |
''' | |
self._rotationButton_Popup.exec_(self._rotationButton.mapToGlobal(point)) | |
def zeroOutSelected(self, arg): | |
arg = str(arg) | |
if'T' in arg: | |
self.logic.zero_Trans(arg.lower()) | |
if'R' in arg: | |
self.logic.zero_Rot(arg.lower()) | |
def _transformButton_clicked(self): | |
''' | |
Zero Out all Transforms | |
''' | |
self.logic.zero_Trans('all') | |
def _rotationButton_clicked(self): | |
''' | |
Zero Out All Rotations | |
''' | |
self.logic.zero_Rot('all') | |
def _customButton_clicked(self): | |
self.logic.zero_Custom() | |
class Logic(): | |
def zero_Trans(self, val): | |
''' | |
Zero Out Transform of selected objects | |
''' | |
for each in mc.ls(sl=True, l=True) or []: | |
if val == 'all' or val == 'tx': | |
mc.setAttr(each+'.tx', 0) | |
if val == 'all' or val == 'ty': | |
mc.setAttr(each+'.ty', 0) | |
if val == 'all' or val == 'tz': | |
mc.setAttr(each+'.tz', 0) | |
def zero_Rot(self, val): | |
''' | |
Zero Out Rotation of selected objects | |
''' | |
for each in mc.ls(sl=True, l=True) or []: | |
if val == 'all' or val == 'rx': | |
mc.setAttr(each+'.rx', 0) | |
if val == 'all' or val == 'ry': | |
mc.setAttr(each+'.ry', 0) | |
if val == 'all' or val == 'rz': | |
mc.setAttr(each+'.rz', 0) | |
def zero_Custom(self): | |
for each in mc.ls(sl=True, l=True) or []: | |
for attr in mc.listAttr(each, ud=True, k=True, u=True, v=True, se=True) or []: | |
## Get default value | |
val = mc.attributeQuery(attr, node=each, ld=True)[0] | |
print val | |
## Set value | |
mc.setAttr(each+'.'+attr, val) | |
def main(): | |
global test | |
try: | |
test.deleteLater() | |
except: | |
pass | |
try: | |
app = QtGui.QApplication(sys.argv) | |
test = TestUI() | |
test.show() | |
sys.exit(app.exec_()) | |
except(RuntimeError): | |
test = TestUI() | |
test.show() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment