def deleteModule(self, *args): """ Delete the Guide, ModuleLayout and Namespace. """ # delete mirror preview: try: cmds.delete(self.moduleGrp[:self.moduleGrp.find(":")]+"_MirrorGrp") except: pass # delete the guide module: utils.clearNodeGrp(nodeGrpName=self.moduleGrp, attrFind='guideBase', unparent=True) # clear default 'dpAR_GuideMirror_Grp': utils.clearNodeGrp() # remove the namespaces: allNamespaceList = cmds.namespaceInfo(listOnlyNamespaces=True) if self.guideNamespace in allNamespaceList: cmds.namespace(moveNamespace=(self.guideNamespace, ':'), force=True) cmds.namespace(removeNamespace=self.guideNamespace, force=True) try: # delete the moduleFrameLayout from window UI: cmds.deleteUI(self.moduleFrameLayout) self.clearSelectedModuleLayout() # edit the footer A text: self.currentText = cmds.text("footerAText", query=True, label=True) cmds.text("footerAText", edit=True, label=str(int(self.currentText[:self.currentText.find(" ")]) - 1) +" "+ self.langDic[self.langName]['i005_footerA']) except: pass # clear module from instance list (clean dpUI list): delIndex = self.dpUIinst.moduleInstancesList.index(self) self.dpUIinst.moduleInstancesList.pop(delIndex)
def createPreviewMirror(self, *args): # re-declaring guideMirror and previewMirror groups: self.previewMirrorGrpName = self.moduleGrp[:self.moduleGrp.find(":")]+'_MirrorGrp' if cmds.objExists(self.previewMirrorGrpName): cmds.delete(self.previewMirrorGrpName) # verify if there is not any guide module in the guideMirrorGrp and then delete it: self.guideMirrorGrp = 'dpAR_GuideMirror_Grp' utils.clearNodeGrp(nodeGrpName=self.guideMirrorGrp, attrFind='guideBaseMirror', unparent=False) # get children, verifying if there are children guides: guideChildrenList = utils.getGuideChildrenList(self.moduleGrp) self.mirrorAxis = cmds.getAttr(self.moduleGrp+".mirrorAxis") if self.mirrorAxis != 'off': if not cmds.objExists(self.guideMirrorGrp): self.guideMirrorGrp = cmds.group(name=self.guideMirrorGrp, empty=True) cmds.setAttr(self.guideMirrorGrp+".template", 1) cmds.addAttr(self.guideMirrorGrp, longName="selectionChanges", defaultValue=0, attributeType="byte") if not cmds.objExists(self.previewMirrorGrpName): if guideChildrenList: guideFatherNameList = [] for guideChild in guideChildrenList: # get guide father name: guideFatherName = cmds.listRelatives(guideChild, parent=True) guideFatherNameList.append(guideFatherName) # unparent this child guide in order to make the mirror and after return it to the parent: cmds.parent(guideChild, world=True) # set child guide as not mirrorable: cmds.setAttr(guideChild+".mirrorEnable", 0) # get initial values from father guide base: fatherMirrorName = cmds.getAttr(self.moduleGrp+".mirrorName") # set values to guide base: cmds.setAttr(guideChild+".mirrorAxis", self.mirrorAxis, type='string') cmds.setAttr(guideChild+".mirrorName", fatherMirrorName, type='string') # duplicating the moduleGuide duplicated = cmds.duplicate(self.moduleGrp, returnRootsOnly=True)[0] duplicatedList = cmds.listRelatives(duplicated, allDescendents=True, fullPath=True) # renaming and reShaping all its children nodes: if duplicatedList: for dup in duplicatedList: if cmds.objExists(dup): if "_RadiusCtrl" in dup or "_Ant" in dup: cmds.delete(dup) else: if cmds.objectType(dup) == 'transform' or cmds.objectType(dup) == 'joint': # rename duplicated node: dupRenamed = cmds.rename(dup, self.moduleGrp[:self.moduleGrp.find(":")]+'_'+dup[dup.rfind("|")+1:]+'_Mirror') originalGuide = self.moduleGrp[:self.moduleGrp.find(":")+1]+dup[dup.rfind("|")+1:] # unlock and unhide all attributes and connect original guide node transformations to the mirror guide node: attrList = ['translateX', 'translateY', 'translateZ', 'rotateX', 'rotateY', 'rotateZ', 'scaleX', 'scaleY', 'scaleZ'] for attr in attrList: cmds.setAttr(dupRenamed+"."+attr, lock=False, keyable=True) cmds.connectAttr(originalGuide+'.'+attr, dupRenamed+'.'+attr, force=True) # rebuild the shape as a nurbsSphere: if cmds.objectType(dupRenamed) == 'transform': childrenShapeList = cmds.listRelatives(dupRenamed, shapes=True, children=True) if childrenShapeList: cmds.delete(childrenShapeList) newSphere = cmds.sphere(name=dupRenamed+"Sphere", radius=0.1, constructionHistory=False) newSphereShape = cmds.listRelatives(newSphere, shapes=True, children=True)[0] cmds.parent(newSphereShape, dupRenamed, shape=True, relative=True) cmds.delete(newSphere) elif cmds.objectType(dup) != 'nurbsCurve': cmds.delete(dup) # renaming the previewMirrorGuide: self.previewMirrorGuide = cmds.rename(duplicated, self.moduleGrp.replace(":", "_")+'_Mirror') cmds.delete(self.previewMirrorGuide+'Shape') # create a decomposeMatrix node in order to get the worldSpace transformations (like using xform): decomposeMatrix = cmds.createNode('decomposeMatrix', name=self.previewMirrorGuide+"_dm") cmds.connectAttr(self.moduleGrp+'.worldMatrix', decomposeMatrix+'.inputMatrix', force=True) # connect original guide base decomposeMatrix node output transformations to the mirror guide base node: axisList = ['X', 'Y', 'Z'] for axis in axisList: cmds.connectAttr(decomposeMatrix+'.outputTranslate'+axis, self.previewMirrorGuide+'.translate'+axis, force=True) cmds.connectAttr(decomposeMatrix+'.outputRotate'+axis, self.previewMirrorGuide+'.rotate'+axis, force=True) cmds.connectAttr(decomposeMatrix+'.outputScale'+axis, self.previewMirrorGuide+'.scale'+axis, force=True) # analysis if there were children guides for this guide in order to re-parent them: if guideChildrenList: for p, guideChild in enumerate(guideChildrenList): # re-parent this child guide to the correct guideFatherName: cmds.parent(guideChild, guideFatherNameList[p]) # create previewMirror group: self.previewMirrorGrp = cmds.group(name=self.previewMirrorGrpName, empty=True) cmds.parent( self.previewMirrorGuide, self.previewMirrorGrpName, absolute=True ) # parent the previewMirror group to the guideMirror group: cmds.parent(self.previewMirrorGrp, self.guideMirrorGrp, relative=True) # add attributes to be read as mirror guide when re-creating this module: cmds.addAttr(self.previewMirrorGrp, longName='guideBaseMirror', attributeType='bool') cmds.setAttr(self.previewMirrorGrp+".guideBaseMirror", 1) # reset all scale values to 1: cmds.setAttr(self.previewMirrorGrp+'.scaleX', 1) cmds.setAttr(self.previewMirrorGrp+'.scaleY', 1) cmds.setAttr(self.previewMirrorGrp+'.scaleZ', 1) # set a negative value to the scale mirror axis: for axis in self.mirrorAxis: cmds.setAttr(self.previewMirrorGrp+'.scale'+axis, -1) else: if guideChildrenList: for guideChild in guideChildrenList: # get initial values from father guide base: fatherMirrorName = cmds.getAttr(self.moduleGrp+".mirrorName") # set values to guide base: cmds.setAttr(guideChild+".mirrorAxis", "off", type='string') cmds.setAttr(guideChild+".mirrorName", fatherMirrorName, type='string') cmds.select(self.moduleGrp)
def createPreviewMirror(self, *args): # re-declaring guideMirror and previewMirror groups: self.previewMirrorGrpName = self.moduleGrp[:self.moduleGrp. find(":")] + '_MirrorGrp' if cmds.objExists(self.previewMirrorGrpName): cmds.delete(self.previewMirrorGrpName) # verify if there is not any guide module in the guideMirrorGrp and then delete it: self.guideMirrorGrp = 'dpAR_GuideMirror_Grp' utils.clearNodeGrp(nodeGrpName=self.guideMirrorGrp, attrFind='guideBaseMirror', unparent=False) # get children, verifying if there are children guides: guideChildrenList = utils.getGuideChildrenList(self.moduleGrp) self.mirrorAxis = cmds.getAttr(self.moduleGrp + ".mirrorAxis") if self.mirrorAxis != 'off': if not cmds.objExists(self.guideMirrorGrp): self.guideMirrorGrp = cmds.group(name=self.guideMirrorGrp, empty=True) cmds.setAttr(self.guideMirrorGrp + ".template", 1) cmds.addAttr(self.guideMirrorGrp, longName="selectionChanges", defaultValue=0, attributeType="byte") if not cmds.objExists(self.previewMirrorGrpName): if guideChildrenList: guideFatherNameList = [] for guideChild in guideChildrenList: # get guide father name: guideFatherName = cmds.listRelatives(guideChild, parent=True) guideFatherNameList.append(guideFatherName) # unparent this child guide in order to make the mirror and after return it to the parent: cmds.parent(guideChild, world=True) # set child guide as not mirrorable: cmds.setAttr(guideChild + ".mirrorEnable", 0) # get initial values from father guide base: fatherMirrorName = cmds.getAttr(self.moduleGrp + ".mirrorName") # set values to guide base: cmds.setAttr(guideChild + ".mirrorAxis", self.mirrorAxis, type='string') cmds.setAttr(guideChild + ".mirrorName", fatherMirrorName, type='string') # duplicating the moduleGuide duplicated = cmds.duplicate(self.moduleGrp, returnRootsOnly=True)[0] duplicatedList = cmds.listRelatives(duplicated, allDescendents=True, fullPath=True) # renaming and reShaping all its children nodes: if duplicatedList: for dup in duplicatedList: if cmds.objExists(dup): if "_RadiusCtrl" in dup or "_Ant" in dup: cmds.delete(dup) else: if cmds.objectType( dup) == 'transform' or cmds.objectType( dup) == 'joint': # rename duplicated node: dupRenamed = cmds.rename( dup, self.moduleGrp[:self.moduleGrp. find(":")] + '_' + dup[dup.rfind("|") + 1:] + '_Mirror') originalGuide = self.moduleGrp[:self. moduleGrp. find(":") + 1] + dup[ dup. rfind( "|" ) + 1:] # unlock and unhide all attributes and connect original guide node transformations to the mirror guide node: attrList = [ 'translateX', 'translateY', 'translateZ', 'rotateX', 'rotateY', 'rotateZ', 'scaleX', 'scaleY', 'scaleZ' ] for attr in attrList: cmds.setAttr(dupRenamed + "." + attr, lock=False, keyable=True) cmds.connectAttr( originalGuide + '.' + attr, dupRenamed + '.' + attr, force=True) # rebuild the shape as a nurbsSphere: if cmds.objectType( dupRenamed) == 'transform': childrenShapeList = cmds.listRelatives( dupRenamed, shapes=True, children=True) if childrenShapeList: cmds.delete(childrenShapeList) newSphere = cmds.sphere( name=dupRenamed + "Sphere", radius=0.1, constructionHistory=False) newSphereShape = cmds.listRelatives( newSphere, shapes=True, children=True)[0] cmds.parent(newSphereShape, dupRenamed, shape=True, relative=True) cmds.delete(newSphere) elif cmds.objectType(dup) != 'nurbsCurve': cmds.delete(dup) # renaming the previewMirrorGuide: self.previewMirrorGuide = cmds.rename( duplicated, self.moduleGrp.replace(":", "_") + '_Mirror') cmds.delete(self.previewMirrorGuide + 'Shape') # create a decomposeMatrix node in order to get the worldSpace transformations (like using xform): decomposeMatrix = cmds.createNode( 'decomposeMatrix', name=self.previewMirrorGuide + "_dm") cmds.connectAttr(self.moduleGrp + '.worldMatrix', decomposeMatrix + '.inputMatrix', force=True) # connect original guide base decomposeMatrix node output transformations to the mirror guide base node: axisList = ['X', 'Y', 'Z'] for axis in axisList: cmds.connectAttr( decomposeMatrix + '.outputTranslate' + axis, self.previewMirrorGuide + '.translate' + axis, force=True) cmds.connectAttr(decomposeMatrix + '.outputRotate' + axis, self.previewMirrorGuide + '.rotate' + axis, force=True) cmds.connectAttr(decomposeMatrix + '.outputScale' + axis, self.previewMirrorGuide + '.scale' + axis, force=True) # analysis if there were children guides for this guide in order to re-parent them: if guideChildrenList: for p, guideChild in enumerate(guideChildrenList): # re-parent this child guide to the correct guideFatherName: cmds.parent(guideChild, guideFatherNameList[p]) # create previewMirror group: self.previewMirrorGrp = cmds.group( name=self.previewMirrorGrpName, empty=True) cmds.parent(self.previewMirrorGuide, self.previewMirrorGrpName, absolute=True) # parent the previewMirror group to the guideMirror group: cmds.parent(self.previewMirrorGrp, self.guideMirrorGrp, relative=True) # add attributes to be read as mirror guide when re-creating this module: cmds.addAttr(self.previewMirrorGrp, longName='guideBaseMirror', attributeType='bool') cmds.setAttr(self.previewMirrorGrp + ".guideBaseMirror", 1) # reset all scale values to 1: cmds.setAttr(self.previewMirrorGrp + '.scaleX', 1) cmds.setAttr(self.previewMirrorGrp + '.scaleY', 1) cmds.setAttr(self.previewMirrorGrp + '.scaleZ', 1) # set a negative value to the scale mirror axis: for axis in self.mirrorAxis: cmds.setAttr(self.previewMirrorGrp + '.scale' + axis, -1) else: if guideChildrenList: for guideChild in guideChildrenList: # get initial values from father guide base: fatherMirrorName = cmds.getAttr(self.moduleGrp + ".mirrorName") # set values to guide base: cmds.setAttr(guideChild + ".mirrorAxis", "off", type='string') cmds.setAttr(guideChild + ".mirrorName", fatherMirrorName, type='string') cmds.select(self.moduleGrp)