def create_facial_rig(): errmsg = [] msg = ft.create_ctl() errmsg.append(msg) pm.refresh() if not pm.confirmBox(title='Facial Rig Status',message = "Face Control Created\nError:\n%s"%msg, yes='Continue?', no='Stop?'): return msg = ft.create_eye_rig() errmsg.append(msg) pm.refresh() if not pm.confirmBox(title='Facial Rig Status',message = "Eyeballs Rig Created\nError:\n%s"%msg, yes='Continue?', no='Stop?'): return msg = ft.connect_mouth_ctl() errmsg.append(msg) pm.refresh() if not pm.confirmBox(title='Facial Rig Status',message = "Mouth Control to Bone Connected\nError:\n%s"%msg, yes='Continue?', no='Stop?'): return msg = ft.create_facial_bs_ctl() errmsg.append(msg) pm.refresh() if not pm.confirmBox(title='Facial Rig Status',message = "Create BlendShape control and setup BlendShape \nError:\n%s"%msg, yes='Continue?', no='Stop?'): return # ft.parent_ctl_to_head() # pm.refresh() # if not pm.confirmBox(title='Facial Rig Status',message = "Parent Root Group to Head OK", yes='Continue?', no='Stop?'): # return msg = ft.copy_facialskin() pm.refresh() if not pm.confirmBox(title='Facial Rig Status',message = "Facial Copy \nError:\n%s"%msg, yes='Continue?', no='Stop?'): return pm.informBox(title='Riggin Status', message = "Face Rig Complete")
def GetUserConfirmation(title, message): """ Displays an OK/Cancel box to user. Returns True if OK pressed, False if Cancel. :param title: box Title. :param message: box body text. """ return pm.confirmBox(title, message, "OK", "Cancel")
def onRemoveInfluenceClick(self): if self.selectedBones_list: removeBones = self.selectedBones_list elif self.bones_list: removeBones = self.bones_list else: removeBones = [ j for j in pm.selected() if ul.get_type(j) == 'joint' ] if self.objectList and removeBones: if pm.confirmBox( 'Remove Bone', '{} will be remove from {}'.format( [j.name() for j in removeBones], self.objectList[-1])): for bone in removeBones: rul.add_joint_influence(bone, self.objectList[-1], remove=True)
def exportAssetAssembly(name, rigTopNode, meshTopNode, path, postScript=None): if pm.ls(rigTopNode): rigTopNode = pm.PyNode(rigTopNode) else: pm.displayError( "{} doesn't exist or duplicated. Please check your " "scene".format(rigTopNode)) return if pm.ls(meshTopNode): meshTopNode = pm.PyNode(meshTopNode) else: pm.displayError( "{} doesn't exist or duplicated. Please check " "your scene".format(meshTopNode)) return # check the folder and script # if the target name exist abort and request another name deformer_jnts = rigTopNode.rigGroups[3].connections()[0].members() if not deformer_jnts: pm.displayError( "{} is empty. The tool can't find any joint".format(meshTopNode)) # export connections and cut joint connections # cut al possible remaining connection and adjust hierarchy # pot script if postScript: try: execfile(postScript) except Exception as ex: template = "An exception of type {0} occured. Arguments:\n{1!r}" message = template.format(type(ex).__name__, ex.args) pm.displayError(message) cont = pm.confirmBox("FAIL: Script Fail", "Do you want to export anyway?" + "\n\n" + message + "\n\n" + traceback.format_exc(), "Continue", "Cancel") if not cont: pm.undo() return
def ui_createRig(self): ''' Call the build methods ''' if not pm.general.objExists('HairRig_MainCnt'): raise Exception('Please create and place loctors first! "HairRig_MainCnt" not found.') if pm.general.objExists('HairRig'): choice = pm.confirmBox(title='Existing Hair Rig found', message='Delete Existing Hair Rig?') if choice == 'No': return if choice == None: return pm.delete('HairRig') self.ui_storeUiData() grps = self.rig_createGroups() self.rig_createFkChain(topNode=grps[1]) self.rig_createDynamicChain(topNode=grps[2]) self.rig_createShChain() self.rig_connectChains() self.rig_deleteLocators()
def update_scene(refs=None, quiet=False): import pymel.core as pymel if refs is None: refs = get_scene_breakdown() refs_to_update = (ref for ref in refs if ref.needUpdate()) num_refs_to_update = len(refs_to_update) if (num_refs_to_update > 0): anwser = pymel.confirmBox( "Warning: Outdated references", "The scene contain {x} outdated references!\n\nUpdate? ;)".format(num_refs_to_update), ["Yes", "Always", "No"] ) if anwser == "Yes": for ref in refs_to_update: ref.update()
def ui_createRig(self): ''' Call the build methods ''' if not pm.general.objExists('HairRig_MainCnt'): raise Exception( 'Please create and place loctors first! "HairRig_MainCnt" not found.' ) if pm.general.objExists('HairRig'): choice = pm.confirmBox(title='Existing Hair Rig found', message='Delete Existing Hair Rig?') if choice == 'No': return if choice == None: return pm.delete('HairRig') self.ui_storeUiData() grps = self.rig_createGroups() self.rig_createFkChain(topNode=grps[1]) self.rig_createDynamicChain(topNode=grps[2]) self.rig_createShChain() self.rig_connectChains() self.rig_deleteLocators()
def clear_cb(*args): if pm.confirmBox("Clear Selection Set", "Are you sure?"): curr_set.clear() print("Cleared QuickSel.")
def exportAssetAssembly(name, rigTopNode, meshTopNode, path, postScript=None): """Export the asset assembly. Model, rig and connections dict. Args: name (str): Name of the asset rigTopNode (str): Name of the rig top node meshTopNode (str): Name of the model top node path (str): Pestination directory postScript (path, optional): Script to run before export Returns: None: None """ if pm.ls(rigTopNode): rigTopNode = pm.PyNode(rigTopNode) else: pm.displayError( "{} doesn't exist or duplicated. Please check your " "scene".format(rigTopNode)) return if pm.ls(meshTopNode): meshTopNode = pm.PyNode(meshTopNode) else: pm.displayError( "{} doesn't exist or duplicated. Please check " "your scene".format(meshTopNode)) return # check the folder and script # if the target name exist abort and request another name deformer_jnts = rigTopNode.rigGroups[3].connections()[0].members() if not deformer_jnts: pm.displayError( "{} is empty. The tool can't find any joint".format(meshTopNode)) # export connections and cut joint connections file_path = os.path.join(path, name + ".jmm") dm_nodes = exportConnections(source=deformer_jnts, filePath=file_path, disc=True) # cut al possible remaining connection and adjust hierarchy # joint or visibility jnt_org = pm.PyNode("jnt_org") pm.disconnectAttr(rigTopNode.jnt_vis, jnt_org.visibility) # restructure model model = pm.createNode("transform", n="model", p=None, ss=True) pm.addAttr(model, ln="rigGroups", at='message', m=1) pm.parent(meshTopNode, jnt_org, model) # disconnect jnt set sets = rigTopNode.listConnections(type="objectSet") deformersGrp = None for oSet in sets: if "deformers_grp" in oSet.name(): deformersGrp = oSet if deformersGrp: for cnx in deformersGrp.message.listConnections(p=True): pm.disconnectAttr(deformersGrp.message, cnx) pm.connectAttr(deformersGrp.message, model.attr("rigGroups[0]")) # disconnect bindPoses dg_poses = rigTopNode.message.listConnections(type="dagPose", p=True) for dgp in dg_poses: if dgp.node().name().startswith("bindPose"): pm.disconnectAttr(rigTopNode.message, dgp) # post script if postScript: try: execfile(postScript) except Exception as ex: template = "An exception of type {0} occured. Arguments:\n{1!r}" message = template.format(type(ex).__name__, ex.args) pm.displayError(message) cont = pm.confirmBox("FAIL: Script Fail", "Do you want to export anyway?" + "\n\n" + message + "\n\n" + traceback.format_exc(), "Continue", "Cancel") if not cont: pm.undo() return # export rig model pm.select(dm_nodes, r=True) pm.select(rigTopNode, add=True) file_path = os.path.join(path, name + "_rig.ma") exp = pm.exportSelected(file_path, f=True, type="mayaAscii") pm.displayInfo(exp) # export mesh and joints pm.select(model, r=True) file_path = os.path.join(path, name + "_model.ma") exp = pm.exportSelected(file_path, f=True, type="mayaAscii") pm.displayInfo(exp)
def ui_createLocators(self): ''' Create main control and locators for user to place ''' yShift = 3 # Used to space chain locators below root parentJnt = str(self.parentLineEdit.text()) if not parentJnt: raise Exception('Please select a parent joint.') pos = pm.xform(parentJnt, q=1, ws=1, rp=1) if pm.general.objExists('HairRig_MainCnt'): choice = pm.confirmBox(title='Hair Rig: Locators already exist', message='Delete Existing Locators?') if choice == 'No': return if choice == None: return pm.delete('HairRig_MainCnt') # Create root control mainCnt = pm.circle(radius=3, name='HairRig_MainCnt', c=pos, nr=(0, 1, 0), ch=0)[0] pm.mel.eval('CenterPivot;') # Get chain names and number of joints names = [] numJnts = [] for nameFld, numJntsFld in zip(self.nameFields, self.chainNumLcdFields): names.append(str(nameFld.text())) numJnts.append(str(numJntsFld.value())) poci = pm.shadingNode('pointOnCurveInfo', asUtility=True) pm.connectAttr('%s.ws' % mainCnt.getShape(), '%s.inputCurve' % poci, f=1) increment = 1 / len(names) for name, numJnt in zip(names, numJnts): locatorChains = {} loc = pm.spaceLocator(n='%s_rootLoc' % name) locatorChains[loc] = [] pm.mel.eval('CenterPivot;') pm.scale(loc, .5, .5, .5) # Aim in negative x to parent joint to set Up vector pm.select(parentJnt, loc, replace=1) pm.mel.eval( 'doCreateAimConstraintArgList 1 { "0","0","0","0","-1","0","0","0","1","0","0","1","0","1","vector","","0","0","0","","1" };' ) # Get the initial position pm.connectAttr('%s.position' % poci, '%s.translate' % loc, f=1) pm.setAttr('%s.parameter' % poci, increment) pos = pm.xform(loc, q=1, ws=1, t=1) pm.disconnectAttr('%s.position' % poci, '%s.translate' % loc) increment = increment + 1 pm.setAttr('%s.translateX' % loc, pos[0]) pm.setAttr('%s.translateY' % loc, pos[1]) pm.setAttr('%s.translateZ' % loc, pos[2]) pm.parent(loc, mainCnt) # Create the rest of the locators for n in range(int(numJnt)): if n == 0: continue l = pm.spaceLocator(n='%s_loc%s' % (name, n)) pm.delete(pm.parentConstraint(loc, l, mo=False)) pm.scale(l, .5, .5, .5) pm.move(l, 0, -(n * yShift), 0, r=True) locatorChains[loc].append(l) pm.parent(l, loc)
def ui_createLocators(self): ''' Create main control and locators for user to place ''' yShift = 3 # Used to space chain locators below root parentJnt = str(self.parentLineEdit.text()) if not parentJnt: raise Exception('Please select a parent joint.') pos = pm.xform(parentJnt, q=1, ws=1, rp=1) if pm.general.objExists('HairRig_MainCnt'): choice = pm.confirmBox(title='Hair Rig: Locators already exist', message='Delete Existing Locators?') if choice == 'No': return if choice == None: return pm.delete('HairRig_MainCnt') # Create root control mainCnt = pm.circle(radius=3, name='HairRig_MainCnt', c=pos, nr=(0,1,0), ch=0)[0] pm.mel.eval('CenterPivot;') # Get chain names and number of joints names = [] numJnts = [] for nameFld,numJntsFld in zip(self.nameFields,self.chainNumLcdFields): names.append(str(nameFld.text())) numJnts.append(str(numJntsFld.value())) poci = pm.shadingNode('pointOnCurveInfo', asUtility=True) pm.connectAttr('%s.ws'%mainCnt.getShape(),'%s.inputCurve'%poci,f=1) increment = 1/len(names) for name, numJnt in zip(names,numJnts): locatorChains = {} loc = pm.spaceLocator(n='%s_rootLoc'%name) locatorChains[loc] = [] pm.mel.eval('CenterPivot;') pm.scale(loc,.5,.5,.5) # Aim in negative x to parent joint to set Up vector pm.select(parentJnt, loc, replace=1) pm.mel.eval('doCreateAimConstraintArgList 1 { "0","0","0","0","-1","0","0","0","1","0","0","1","0","1","vector","","0","0","0","","1" };') # Get the initial position pm.connectAttr('%s.position'%poci,'%s.translate'%loc,f=1) pm.setAttr('%s.parameter'%poci,increment) pos = pm.xform(loc,q=1,ws=1,t=1) pm.disconnectAttr('%s.position'%poci,'%s.translate'%loc) increment = increment + 1 pm.setAttr('%s.translateX'%loc, pos[0]) pm.setAttr('%s.translateY'%loc, pos[1]) pm.setAttr('%s.translateZ'%loc, pos[2]) pm.parent(loc,mainCnt) # Create the rest of the locators for n in range(int(numJnt)): if n == 0: continue l = pm.spaceLocator(n='%s_loc%s'%(name,n)) pm.delete(pm.parentConstraint(loc,l,mo=False)) pm.scale(l,.5,.5,.5) pm.move(l,0,-(n*yShift),0,r=True) locatorChains[loc].append(l) pm.parent(l,loc)