def _closeExistingWindow_(self): """Ensures there is only instance of the PySide GUI""" for qt in QtGui.qApp.topLevelWidgets(): # Check that there is only one instance of the APP try: if qt.__class__.__name__ == self.__class__.__name__: qt.close() except: pyLog.warning('Failed to close an instance of this GUI:%s' % str(self))
def _set_cam_(self): cam_text = self.cameraBox.currentText() if cam_text != "No Custom Camera": camera = pm.PyNode(self.cameraBox.currentText()) camera.renderable.set(1) for otherCamera in get_cam_list(): if camera != otherCamera: otherCamera.renderable.set(0) pyLog.warning("Current Render Camera: %s" % camera)
def mel2pyStr(text): """ Convert a mel command to pymel command and print the result @param text: The mel command """ if not text.endswith(";"): pyLog.warning('Please end the mel code with ";"') else: import pymel.tools.mel2py as py2mel print py2mel.mel2pyStr(text, pymelNamespace="pm")
def melEval(evalStatment, echo=False): '''evaluate mel statement line for line. Print out error message for failed eval states @param evalStatment (string) the mel command which need to be evaluated. Multiple lines of mel commands can also be evaluated. @param echo (bool) print out the mel statement before evaluating. Useful for debugging ''' for statement in evalStatment.split(";"): try: if echo: print statement mel.eval("%s;" % statement) except: pyLog.warning("## ## ## FAILED MEL STATEMENT: %s## ## ## " % ("%s;" % statement))
def setWindowIcon(self, iconPath): """Set the icon for via QIcon""" # Make sure the icon exists if not libFile.exists(iconPath): pyLog.warning("No Icon exists for path:%s" % iconPath) else: # Set the icon icon = QtGui.QIcon(QtGui.QPixmap(iconPath)) try: super(QMainWindow, self).setWindowIcon(icon) except Exception as e: print e pyLog.warning("Failed to set Icon")
def PRINT(msg='', item='', type='info'): printMsg = '|| %s || %s' %(msg.ljust(65), item.ljust(20)) if type == 'debug': pymelLogger.debug('\t\t\t%s'%printMsg) elif type == 'info': pymelLogger.info('\t\t\t%s'%printMsg) elif type == 'warning': pymelLogger.warning('\t%s'%printMsg) elif type == 'error': pymelLogger.error('\t%s'%printMsg) elif type == 'critical': pymelLogger.critical('\t%s'%printMsg) else: pymelLogger.error('Cannot Print Message: Invalid Type') return
def _importRefDeleteNS(self): ''' Given a selected object, import reference and delete the namespace. ''' # only first object selected will be considered pymelLogger.debug('Starting: importRefDeleteNS()...') sel = cmds.ls(sl=1) if sel: sel = sel[0] ns = sel[:sel.rfind(':')] # finding name of the referenced node try: refNode = cmds.referenceQuery(sel, referenceNode=True) except: refNode = None if refNode: # find out if it is a reference of a reference topRef = cmds.referenceQuery(sel, referenceNode=True, tr=True) if refNode != topRef: pymelLogger.debug( 'importRefDeleteNS(): %s is sub-referenced.' % sel) fileNameTN = cmds.referenceQuery(topRef, filename=True) fileNameN = cmds.referenceQuery(refNode, filename=True) cmds.file(fileNameTN, importReference=1) cmds.file(fileNameN, importReference=1) cmds.namespace(mv=[ns, ':'], force=1) pymelLogger.debug( 'importRefDeleteNS(): %s namespace moved to ":" namespace.' % ns) else: fileNameN = cmds.referenceQuery(refNode, filename=True) cmds.file(fileNameN, importReference=1) cmds.namespace(mv=[ns, ':'], force=1) else: cmds.warning('This is Not a reference object!') pymelLogger.warning('%s is not a referenced object.' % sel) else: pymelLogger.warning( 'Nothing selected! Please select a referenced object.') pymelLogger.debug('End: importRefDeleteNS().')
def snapBake(source, target): """ Snap and bake the position of the source to the target. Delete all keys first @param source: Source transform @param target: Target transform """ # Contraint mel.eval('cutKey -t ":" -f ":" -at "tx" -at "ty" -at "tz" -at "rx" -at "ry" -at "rz" %s;' % target) # Contraint con = pm.parentConstraint(source, target) # Bake Animation bakeAnimation(target) # Delete the contraint pm.delete(con) # Get the scale value scale = target.getScale() # Transfer mel.eval('cutKey -t ":" -f ":" -at "sx" -at "sy" -at "sz" %s;' % target) # Scale try: target.setScale(scale) except: pyLog.warning("Unable to set the target scale")
def _importRefDeleteNS(self): ''' Given a selected object, import reference and delete the namespace. ''' # only first object selected will be considered pymelLogger.debug('Starting: importRefDeleteNS()...') sel = cmds.ls(sl=1) if sel: sel = sel[0] ns = sel[:sel.rfind(':')] # finding name of the referenced node try: refNode = cmds.referenceQuery( sel, referenceNode = True ) except: refNode=None if refNode: # find out if it is a reference of a reference topRef = cmds.referenceQuery( sel, referenceNode=True, tr=True ) if refNode != topRef: pymelLogger.debug('importRefDeleteNS(): %s is sub-referenced.'%sel) fileNameTN = cmds.referenceQuery( topRef,filename = True ) fileNameN = cmds.referenceQuery( refNode, filename = True ) cmds.file( fileNameTN , importReference = 1 ) cmds.file( fileNameN, importReference = 1 ) cmds.namespace(mv=[ns,':'], force=1) pymelLogger.debug('importRefDeleteNS(): %s namespace moved to ":" namespace.'%ns) else: fileNameN = cmds.referenceQuery( refNode, filename = True ) cmds.file( fileNameN, importReference = 1 ) cmds.namespace(mv=[ns,':'], force=1) else: cmds.warning('This is Not a reference object!' ) pymelLogger.warning('%s is not a referenced object.'%sel) else: pymelLogger.warning('Nothing selected! Please select a referenced object.') pymelLogger.debug('End: importRefDeleteNS().')
else: msg = 'Rig has no namespace. Make sure it is referenced. Nothing exported.' pymelLogger.error(msg) raise Exception(msg) if result: results.append(result) exportedRig = True pm.delete(root) else: pymelLogger.error('FBX did not export for "%s:%s"'%(ns,root)) if not exportedRig: msg = 'No Rigs in the scene to be exported!' cmds.warning( msg ) pymelLogger.warning( msg ) # Export camera(s) exportedCam = False for c_name in self.camNames: try: # Try to select camera pymelLogger.debug('Trying: "%s" '%c_name) pm.select( c_name, r=1) cameras = pm.ls(sl=1) except Exception,e: # Skip this camera name pymelLogger.debug('Did not find "%s" in scene.'%c_name) pymelLogger.debug(e) continue
msg = 'Rig has no namespace. Make sure it is referenced. Nothing exported.' pymelLogger.error(msg) raise Exception(msg) if result: results.append(result) exportedRig = True pm.delete(root) else: pymelLogger.error('FBX did not export for "%s:%s"' % (ns, root)) if not exportedRig: msg = 'No Rigs in the scene to be exported!' cmds.warning(msg) pymelLogger.warning(msg) # Export camera(s) exportedCam = False for c_name in self.camNames: try: # Try to select camera pymelLogger.debug('Trying: "%s" ' % c_name) pm.select(c_name, r=1) cameras = pm.ls(sl=1) except Exception, e: # Skip this camera name pymelLogger.debug('Did not find "%s" in scene.' % c_name) pymelLogger.debug(e) continue