def parseOldNameByTokens(self, lightNode): objTransform, objShape = tools.getTransformAndShape(lightNode) nameSplit = objTransform.split('_') result = None if len(nameSplit) == len(self.naming.getActiveRule().fields): if mc.nodeType(objShape) in self.lightNodeTypes: result = self.naming.parse(objTransform) return result
def _deleteLight(self): allSel = mc.ls(sl=True) success = False for each in allSel: objTransform, objShape = tools.getTransformAndShape(each) for name, factory in self.factories.iteritems(): if mc.nodeType(objShape) in factory.lightNodeTypes: factory.deleteLight(objTransform, objShape) success = True break if success: tools.resetGlobals()
def duplicateLight(self, lightNode, withInputs=False, withNodes=False, *args, **kwargs): objTransform, objShape = tools.getTransformAndShape(lightNode) transformNode = str() shapeNode = str() if mc.nodeType(objShape) in tools.getLightNodesList(): parsedName = self.parseOldNameByTokens(objTransform) if parsedName is not None: lightName = self.buildName(**parsedName) if withInputs and not withNodes: transformNode = mc.duplicate(objTransform, name=lightName, ic=True)[0] elif withInputs and withNodes: transformNode = mc.duplicate(objTransform, name=lightName, ic=True, un=True)[0] else: transformNode = mc.duplicate(objTransform, name=lightName)[0] else: if withInputs and not withNodes: transformNode = mc.duplicate(objTransform, ic=True)[0] elif withInputs and withNodes: transformNode = mc.duplicate(objTransform, ic=True, un=True)[0] else: transformNode = mc.duplicate(objTransform)[0] shapeNode = mc.listRelatives(transformNode, shapes=True, noIntermediate=True, fullPath=True)[0] else: tools.logger.info('Only lights accepted. {} is {}'.format( lightNode, mc.nodeType(lightNode))) return None try: self.post_fn.postLightDuplicate(transformNode, shapeNode, *args, **kwargs) except: tools.logger.exception( "Post light duplicate function not executed due to exceptions") finally: return transformNode, shapeNode
def _renameLight(self): allSel = mc.ls(sl=True) if len(allSel) > 1: msgBox = QtWidgets.QMessageBox(self) msgBox.setWindowTitle("Warning!") msgBox.setText("Please select one light only.") msgBox.exec_() tools.logger.info('Please select one light only.') else: lightNode = allSel[0] objTransform, objShape = tools.getTransformAndShape(lightNode) dialog = LightRenamer_GUI(objShape, self.factories, self) dialog.show() if dialog == 1: tools.resetGlobals()
def deleteLight(self, lightNode, lightName, *args, **kwargs): objTransform, objShape = tools.getTransformAndShape(lightNode) success = False try: mc.delete(objTransform) success = True except: pass try: self.post_fn.postLightDelete(objTransform, objShape, *args, **kwargs) except: tools.logger.exception( "Post light delete function not executed due to exceptions") finally: return success
def renameLight(self, lightNode, lightName, *args, **kwargs): objTransform, objShape = tools.getTransformAndShape(lightNode) parsedName = self.naming.parse(lightName) finalLightName = self.buildName(**parsedName) result = mc.rename(objTransform, finalLightName) shapeNode = mc.listRelatives(result, shapes=True, noIntermediate=True, fullPath=True)[0] try: self.post_fn.postLightRename(result, shapeNode, *args, **kwargs) except: tools.logger.exception( "Post light rename function not executed due to exceptions") finally: return result
def _duplicate(self): allSel = mc.ls(sl=True) if len(allSel) < 1: msgBox = QtWidgets.QMessageBox(self) msgBox.setWindowTitle("Warning!") msgBox.setText("Please select at least one light to duplicate.") msgBox.exec_() tools.logger.info('Please select at least one light to duplicate.') else: for each in allSel: objTransform, objShape= tools.getTransformAndShape(each) for name, factory in self.factories.iteritems(): if mc.nodeType(objShape) in factory.lightNodeTypes: for i in range(self.howMany_SPINBOX.value()): factory.duplicateLight(objTransform, self.withInputs, self.withNodes, keepAOVSetup=self.keepSetup_CHKBOX.isChecked()) self.done(1)
def _parseOldNameParts(self, lightNode): '''TODO: This could be moved to the factories so the tools enforce good naming when duplicating''' objTransform, objShape = tools.getTransformAndShape(lightNode) if mc.nodeType(objShape) in tools.getLightNodesList(): if '_' in objTransform: nameSplit = objTransform.split('_') number = 1 longestPart = str() for part in nameSplit: if part.isdigit(): number = int(part) continue else: if len(part) > len(longestPart): longestPart = part else: return longestPart, number else: return objTransform, 1