def create_connections(): selection = cmds.ls(selection=True) bind_jnt_list = selection[:3] ik_jnt_list = selection[3:6] fk_jnt_list = selection[6:] #ctrl get_ctrl_name=[] name_split = selected_list[3].split('_') new_name = name_split[:2] new_name = '_'.join(new_name) get_ctrl_name.append(new_name) switch_ctrl = cmds.circle(r=1.5, nr=(1, 0, 0), n= get_ctrl_name[0] + '_switch_ctrl') cmds.matchTransform(switch_ctrl, ik_jnt_list[2]) cmds.move(0, 5, 0, switch_ctrl, r=True) zro_group = cmds.group(em=True, n=switch_ctrl[0] + '_zro') cmds.matchTransform(zro_group, switch_ctrl) cmds.parent(switch_ctrl, zro_group) cmds.parentConstraint(bind_jnt_list[2], zro_group, mo=True) cmds.setAttr(switch_ctrl[0] + '.translateX', lock=True, keyable=False) cmds.setAttr(switch_ctrl[0] + '.translateY', lock=True, keyable=False) cmds.setAttr(switch_ctrl[0] + '.translateZ', lock=True, keyable=False) cmds.setAttr(switch_ctrl[0] + '.rotateX', lock=True, keyable=False) cmds.setAttr(switch_ctrl[0] + '.rotateY', lock=True, keyable=False) cmds.setAttr(switch_ctrl[0] + '.rotateZ', lock=True, keyable=False) cmds.setAttr(switch_ctrl[0] + '.scaleX', lock=True, keyable=False) cmds.setAttr(switch_ctrl[0] + '.scaleY', lock=True, keyable=False) cmds.setAttr(switch_ctrl[0] + '.scaleZ', lock=True, keyable=False) cmds.setAttr(switch_ctrl[0] + '.visibility', lock=True, keyable=False) cmds.addAttr(longName='ikFkSwitch', defaultValue=0, keyable=True, min=0.0, max=1.0, dv=0.0) #node editor get_name_list=[] for jnt in bind_jnt_list: jnt_split = jnt.split('_') new_name = jnt_split[:2] new_name = '_'.join(new_name) get_name_list.append(new_name) upArm_bc_t = cmds.createNode('blendColors', n=get_name_list[0] + '_blendColor_transl') elbow_bc_t = cmds.createNode('blendColors', n=get_name_list[1] + '_blendColor_transl') wrist_bc_t = cmds.createNode('blendColors', n=get_name_list[2] + '_blendColor_transl') upArm_bc_r = cmds.createNode('blendColors', n=get_name_list[0] + '_blendColor_rot') elbow_bc_r = cmds.createNode('blendColors', n=get_name_list[1] + '_blendColor_rot') wrist_bc_r = cmds.createNode('blendColors', n=get_name_list[2] + '_blendColor_rot') cmds.connectAttr(ik_jnt_list[0] + '.translate', upArm_bc_t + '.color1') cmds.connectAttr(ik_jnt_list[1] + '.translate', elbow_bc_t + '.color1') cmds.connectAttr(ik_jnt_list[2] + '.translate', wrist_bc_t + '.color1') cmds.connectAttr(ik_jnt_list[0] + '.rotate', upArm_bc_r + '.color1') cmds.connectAttr(ik_jnt_list[1] + '.rotate', elbow_bc_r + '.color1') cmds.connectAttr(ik_jnt_list[2] + '.rotate', wrist_bc_r + '.color1') cmds.connectAttr(fk_jnt_list[0] + '.translate', upArm_bc_t + '.color2') cmds.connectAttr(fk_jnt_list[1] + '.translate', elbow_bc_t + '.color2') cmds.connectAttr(fk_jnt_list[2] + '.translate', wrist_bc_t + '.color2') cmds.connectAttr(fk_jnt_list[0] + '.rotate', upArm_bc_r + '.color2') cmds.connectAttr(fk_jnt_list[1] + '.rotate', elbow_bc_r + '.color2') cmds.connectAttr(fk_jnt_list[2] + '.rotate', wrist_bc_r + '.color2') cmds.connectAttr(switch_ctrl[0] + '.ikFkSwitch', upArm_bc_t + '.blender') cmds.connectAttr(switch_ctrl[0] + '.ikFkSwitch', elbow_bc_t + '.blender') cmds.connectAttr(switch_ctrl[0] + '.ikFkSwitch', wrist_bc_t + '.blender') cmds.connectAttr(switch_ctrl[0] + '.ikFkSwitch', upArm_bc_r + '.blender') cmds.connectAttr(switch_ctrl[0] + '.ikFkSwitch', elbow_bc_r + '.blender') cmds.connectAttr(switch_ctrl[0] + '.ikFkSwitch', wrist_bc_r + '.blender') cmds.connectAttr(upArm_bc_t + '.output', bind_jnt_list[0] + '.translate') cmds.connectAttr(elbow_bc_t + '.output', bind_jnt_list[1] + '.translate') cmds.connectAttr(wrist_bc_t + '.output', bind_jnt_list[2] + '.translate') cmds.connectAttr(upArm_bc_r + '.output', bind_jnt_list[0] + '.rotate') cmds.connectAttr(elbow_bc_r + '.output', bind_jnt_list[1] + '.rotate') cmds.connectAttr(wrist_bc_r + '.output', bind_jnt_list[2] + '.rotate')
def capture_plot_frames_for_lookat(self): smart_bake = self.ui.cb_smart_bake.isChecked() startframe, endframe = self.timerange_widget.get_timerange() control_curve_tuple_list = [ ('{0}:{1}'.format(self.namespace, self.au_eyes_main_control_curve), '{0}:{1}'.format(self.namespace, self.look_at_main_control_curve), '{0}:{1}'.format(self.namespace, self.main_lookat_final_translation)), ('{0}:{1}'.format(self.namespace, self.au_eyes_left_control_curve), '{0}:{1}'.format(self.namespace, self.look_at_left_control_curve), '{0}:{1}'.format(self.namespace, self.left_lookat_final_translation)), ('{0}:{1}'.format(self.namespace, self.au_eyes_right_control_curve), '{0}:{1}'.format(self.namespace, self.look_at_right_control_curve), '{0}:{1}'.format(self.namespace, self.right_lookat_final_translation)) ] # Get list of keys for all of the "eyes_au" controls combined_keys_to_plot = [] if not smart_bake: combined_keys_to_plot = range(startframe, endframe + 1) else: for control_curve_tuple in control_curve_tuple_list: # Unpack control_curve_tuples source_control = control_curve_tuple[0] keys_to_plot = self.get_sparse_bake_index(source_control) # Combine control keys into a single list. for key in keys_to_plot: if key not in combined_keys_to_plot: combined_keys_to_plot.append(key) # Record final position of "lookAt" controls control_transform_dict = {} for key in combined_keys_to_plot: cmds.currentTime(key) if self.ui.rb_user_defined_distance.isChecked(): self.align_lookat_position() for control_curve_tuple in control_curve_tuple_list: target_control = control_curve_tuple[1] final_translation = control_curve_tuple[2] cmds.matchTransform(target_control, final_translation, position=True, rotation=False) transform_list = cmds.xform(target_control, query=True, translation=True) key_control_tuple = (key, target_control) control_transform_dict[key_control_tuple] = transform_list # Flatten animation curves that we will be replacing flatten_curve_list = [ '{0}:lookat_ctl.tx'.format(self.namespace), '{0}:lookat_ctl.ty'.format(self.namespace), '{0}:lookat_ctl.tz'.format(self.namespace), '{0}:L_lookat_ctl.tx'.format(self.namespace), '{0}:L_lookat_ctl.ty'.format(self.namespace), '{0}:L_lookat_ctl.tz'.format(self.namespace), '{0}:R_lookat_ctl.tx'.format(self.namespace), '{0}:R_lookat_ctl.ty'.format(self.namespace), '{0}:R_lookat_ctl.tz'.format(self.namespace) ] lookat_utilities.flatten_anim_curve(flatten_curve_list, startframe, endframe) self.control_transform_dict = control_transform_dict
global tempLoc; tempLoc = listFixed[i] + "_temp_loc" # Physical locator name global tempPart; tempPart = listFixed[i] + "_temp_part" # nParticle name global tempNucl; tempNucl = "nucleus1" # Nucleus node name global partAimLoc; partAimLoc = aimLoc + ".translate" # Aim locator position pull global partRtype; partRtype = tempPart + "Shape.particleRenderType" # nParticle render type pull global partRrad; partRrad = tempPart + "Shape.radius" # nParticle shape radius global partRsm; partRsm = tempPart + "Shape.goalSmoothness" # Goal smoothness pull global partRwe; partRwe = tempPart + "Shape.goalWeight[0]" # Goal weight pull global partPos; partPos = tempPart + ".center" # nParticle center position pull global partNucl; partNucl = tempNucl + ".timeScale" # Time scale pull global nuclStart; nuclStart = tempNucl + ".startFrame" # Start frame of simulation nucleus node cmds.spaceLocator( n = tempLoc ) cmds.matchTransform( tempLoc, listObjects[i], pos=True ) objCenter = tempLoc + ".translate" objC = cmds.getAttr( objCenter ) locCenter = tempLoc + ".center" locTr = tempLoc + ".translate" cmds.nParticle( p = objC, n = tempPart , c = 1 ) cmds.goal( tempPart, w=goalW, utr=1, g = tempLoc ) cmds.select( tempLoc, r=True ) cmds.select( listObjects[i], add=True ) cmds.parent( r=True ) cmds.matchTransform( tempLoc, listObjects[i], pos=True )
def rotationStart(): global asT asT = cmds.playbackOptions(query=True, min=True) global aeT aeT = cmds.playbackOptions(query=True, max=True) resetLoopTime() global listObjects listObjects = cmds.ls(sl=True) if (len(listObjects) <= 1): print "\n||| Need to select two or more objects |||\n" else: #|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| global listFixed listFixed = listObjects[:] for i in range(len(listFixed)): listFixed[i] = listFixed[i].replace("|", "_") listFixed[i] = listFixed[i].replace(":", "_") #|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| global mainLayerName mainLayerName = "OVERLAPPY" if (cmds.objExists(mainLayerName)): print "\n||| OVERLAPPY start |||\n" else: cmds.animLayer(mainLayerName) print "\n||| OVERLAPPY start ||| Layer created |||\n" #|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| for i in range(len(listFixed)): if (i + 1 != len(listFixed)): global zeroLoc zeroLoc = listFixed[i] + "_base_loc" global aimLoc aimLoc = listFixed[i] + "_aim_loc" global tempLoc tempLoc = listFixed[i] + "_temp_loc" global tempAimLoc tempAimLoc = listFixed[i] + "_tempAim_loc" global tempPart tempPart = listFixed[i] + "_temp_part" global tempNucl tempNucl = "nucleus1" global partRtype partRtype = tempPart + "Shape.particleRenderType" global partRrad partRrad = tempPart + "Shape.radius" global partRsm partRsm = tempPart + "Shape.goalSmoothness" global partRwe partRwe = tempPart + "Shape.goalWeight[0]" global partNucl partNucl = tempNucl + ".timeScale" global nuclStart nuclStart = tempNucl + ".startFrame" if aimVectorReverse: rotAimVector = -1 else: rotAimVector = 1 #|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| cmds.spaceLocator(n=zeroLoc) cmds.spaceLocator(n=aimLoc) cmds.spaceLocator(n=tempLoc) cmds.matchTransform(zeroLoc, listObjects[i], pos=True) cmds.matchTransform(tempLoc, listObjects[i + 1], pos=True) cmds.select(tempLoc, r=True) cmds.duplicate(n=tempAimLoc) cmds.select(listObjects[0], r=True) cmds.select(zeroLoc, add=True) cmds.parentConstraint(mo=True, w=1) cmds.select(aimLoc, r=True) cmds.select(zeroLoc, add=True) cmds.parent(r=True) cmds.select(listObjects[1], r=True) cmds.select(tempLoc, add=True) cmds.parentConstraint(mo=True, sr=["x", "y", "z"], w=1) aimPosName = tempLoc + ".translate" partCenter = tempPart + ".center" aimLocPos = tempAimLoc + ".translate" aimPos = cmds.getAttr(aimPosName) cmds.nParticle(p=aimPos, n=tempPart, c=1) cmds.goal(tempPart, w=0.5, utr=1, g=tempLoc) cmds.connectAttr(partCenter, aimLocPos, f=True) cmds.select(tempAimLoc, r=True) cmds.select(aimLoc, add=True) cmds.aimConstraint(w=1, aim=(0, rotAimVector, 0), u=(0, 1, 0), wut="vector", wu=(0, 1, 0), sk="y") #|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| cmds.setAttr(partRtype, pShape) cmds.setAttr(partRrad, pRad) cmds.setAttr(partRsm, goalSmoothRot) cmds.setAttr(partRwe, goalWRot) cmds.setAttr(partNucl, timeScaleRot) cmds.setAttr(nuclStart, asT) #|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| global minLoopTime minLoopTime = aeT * -3 global maxLoopTime maxLoopTime = aeT * 4 if (cycle): cmds.setAttr(nuclStart, minLoopTime) cmds.bakeResults(zeroLoc, t=(asT, aeT), sm=True, at=("translate", "rotate")) cmds.bakeResults(aimLoc, t=(minLoopTime, maxLoopTime), sm=True, at="rotate") cmds.delete(tempAimLoc, tempLoc, tempPart, tempNucl) zeroParent = zeroLoc + "_parentConstraint1" cmds.delete(zeroParent) setTimeToMin() cmds.select(aimLoc, r=True) cmds.select(listObjects[i], add=True) #|||||||||||||||||||||||||||||||||||||||||||||||||||||||||| attrX = listObjects[i] + '.rotateX' attrY = listObjects[i] + '.rotateY' attrZ = listObjects[i] + '.rotateZ' lockX = cmds.getAttr(attrX, lock=True) lockY = cmds.getAttr(attrY, lock=True) lockZ = cmds.getAttr(attrZ, lock=True) if (lockX != True): cmds.parentConstraint(mo=True, st=["x", "y", "z"], sr=["y", "z"], w=1) if (lockY != True): cmds.parentConstraint(mo=True, st=["x", "y", "z"], sr=["x", "z"], w=1) if (lockZ != True): cmds.parentConstraint(mo=True, st=["x", "y", "z"], sr=["x", "y"], w=1) resetLoopTime() else: cmds.bakeResults(zeroLoc, t=(asT, aeT), sm=True, at=("translate", "rotate")) cmds.bakeResults(aimLoc, t=(asT, aeT), sm=True, at="rotate") cmds.delete(tempAimLoc, tempLoc, tempPart, tempNucl) zeroParent = zeroLoc + "_parentConstraint1" cmds.delete(zeroParent) resetLoopTime() cmds.select(aimLoc, r=True) cmds.select(listObjects[i], add=True) #|||||||||||||||||||||||||||||||||||||||||||||||||||||||||| attrX = listObjects[i] + '.rotateX' attrY = listObjects[i] + '.rotateY' attrZ = listObjects[i] + '.rotateZ' lockX = cmds.getAttr(attrX, lock=True) lockY = cmds.getAttr(attrY, lock=True) lockZ = cmds.getAttr(attrZ, lock=True) if (lockX != True): cmds.parentConstraint(mo=True, st=["x", "y", "z"], sr=["y", "z"], w=1) if (lockY != True): cmds.parentConstraint(mo=True, st=["x", "y", "z"], sr=["x", "z"], w=1) if (lockZ != True): cmds.parentConstraint(mo=True, st=["x", "y", "z"], sr=["x", "y"], w=1) #|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| layerBase = "rotate_" layerName = layerBase + listFixed[i] layerComp = listFixed[i] + '_layer_{0}'.format("0") if (cmds.objExists(layerName)): cmds.bakeResults(listObjects[i], t=(asT, aeT), sm=True, bol=True, at="rotate") cmds.select(listObjects[i], r=True) if (cycleInfinity): cmds.setInfinity(pri="cycle", poi="cycle") else: cmds.setInfinity(pri="constant", poi="constant") cmds.delete(aimLoc, zeroLoc) cmds.container("BakeResultsContainer", e=True, rc=True) cmds.animLayer("BakeResults", e=True, p=layerName) cmds.rename("BakeResults", layerComp) #cmds.deleteAttr( n=listObjects[i], at="blendParent1" ) resetLoopTime() else: cmds.animLayer(layerName) cmds.animLayer(layerName, e=True, p=mainLayerName) cmds.bakeResults(listObjects[i], t=(asT, aeT), sm=True, bol=True, at="rotate") cmds.select(listObjects[i], r=True) if (cycleInfinity): cmds.setInfinity(pri="cycle", poi="cycle") else: cmds.setInfinity(pri="constant", poi="constant") cmds.delete(aimLoc, zeroLoc) cmds.container("BakeResultsContainer", e=True, rc=True) cmds.animLayer("BakeResults", e=True, p=layerName) cmds.rename("BakeResults", layerComp) #cmds.deleteAttr( n=listObjects[i], at="blendParent1" ) resetLoopTime() cmds.select(d=True) for l in listObjects: cmds.select(l, add=True) print "\n||| OVERLAPPY end |||\n"
def CreateJoint(): sels = cmds.ls(selection=True) cmds.select(cl=True) for sel in sels: cmds.matchTransform(cmds.joint(), sel)
def translationStart(): global asT asT = cmds.playbackOptions(query=True, min=True) # Get min anim range global aeT aeT = cmds.playbackOptions(query=True, max=True) # Get max anim range resetLoopTime() global listObjects listObjects = cmds.ls(sl=True) # Get list of selected objects #|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| global listFixed listFixed = listObjects[:] for i in range(len(listFixed)): listFixed[i] = listFixed[i].replace("|", "_") listFixed[i] = listFixed[i].replace(":", "_") #|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| global mainLayerName mainLayerName = "OVERLAPPY" # Name of main layer if (cmds.objExists(mainLayerName)): print "\n||| OVERLAPPY start |||\n" else: cmds.animLayer(mainLayerName) print "\n||| OVERLAPPY start ||| Layer created |||\n" #|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| for i in range(len(listFixed)): global aimLoc aimLoc = listFixed[i] + "_aim_loc" # Aim locator name global tempLoc tempLoc = listFixed[i] + "_temp_loc" # Physical locator name global tempPart tempPart = listFixed[i] + "_temp_part" # nParticle name global tempNucl tempNucl = "nucleus1" # Nucleus node name global partAimLoc partAimLoc = aimLoc + ".translate" # Aim locator position pull global partRtype partRtype = tempPart + "Shape.particleRenderType" # nParticle render type pull global partRrad partRrad = tempPart + "Shape.radius" # nParticle shape radius global partRsm partRsm = tempPart + "Shape.goalSmoothness" # Goal smoothness pull global partRwe partRwe = tempPart + "Shape.goalWeight[0]" # Goal weight pull global partPos partPos = tempPart + ".center" # nParticle center position pull global partNucl partNucl = tempNucl + ".timeScale" # Time scale pull global nuclStart nuclStart = tempNucl + ".startFrame" # Start frame of simulation nucleus node cmds.spaceLocator(n=tempLoc) cmds.matchTransform(tempLoc, listObjects[i], pos=True) objCenter = tempLoc + ".translate" objC = cmds.getAttr(objCenter) locCenter = tempLoc + ".center" locTr = tempLoc + ".translate" cmds.nParticle(p=objC, n=tempPart, c=1) cmds.goal(tempPart, w=goalW, utr=1, g=tempLoc) cmds.select(tempLoc, r=True) cmds.select(listObjects[i], add=True) cmds.parent(r=True) cmds.matchTransform(tempLoc, listObjects[i], pos=True) #|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| cmds.setAttr(partRtype, pShape) cmds.setAttr(partRrad, pRad) cmds.setAttr(partRsm, goalSmooth) cmds.setAttr(partRwe, goalW) cmds.setAttr(partNucl, timeScale) cmds.setAttr(nuclStart, asT) #|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| cmds.duplicate(tempLoc, rr=True, n=aimLoc) cmds.select(aimLoc, r=True) cmds.parent(w=True) cmds.connectAttr(partPos, partAimLoc, f=True) global minLoopTime minLoopTime = aeT * -3 global maxLoopTime maxLoopTime = aeT * 4 if (cycle): cmds.setAttr(nuclStart, minLoopTime) cmds.bakeResults(aimLoc, t=(minLoopTime, maxLoopTime), sm=True, at="translate") cmds.delete(tempLoc, tempPart, tempNucl) setTimeToMin() cmds.select(aimLoc, r=True) cmds.select(listObjects[i], add=True) cmds.parentConstraint(mo=True, sr=["x", "y", "z"], w=1) resetLoopTime() else: cmds.bakeResults(aimLoc, t=(asT, aeT), sm=True, at="translate") cmds.delete(tempLoc, tempPart, tempNucl) resetLoopTime() cmds.select(aimLoc, r=True) cmds.select(listObjects[i], add=True) #|||||||||||||||||||||||||||||||||||||||||||||||||||||||||| attrX = listObjects[i] + '.translateX' attrY = listObjects[i] + '.translateY' attrZ = listObjects[i] + '.translateZ' lockX = cmds.getAttr(attrX, lock=True) lockY = cmds.getAttr(attrY, lock=True) lockZ = cmds.getAttr(attrZ, lock=True) if (lockX != True): cmds.parentConstraint(mo=True, st=["y", "z"], sr=["x", "y", "z"], w=1) if (lockY != True): cmds.parentConstraint(mo=True, st=["x", "z"], sr=["x", "y", "z"], w=1) if (lockZ != True): cmds.parentConstraint(mo=True, st=["x", "y"], sr=["x", "y", "z"], w=1) #|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| layerBase = "translate_" layerName = layerBase + listFixed[i] layerComp = listFixed[i] + '_layer_{0}'.format("0") if (cmds.objExists(layerName)): cmds.bakeResults(listObjects[i], t=(asT, aeT), sm=True, bol=True, at="translate") cmds.select(listObjects[i], r=True) if (cycleInfinity): cmds.setInfinity(pri="cycle", poi="cycle") else: cmds.setInfinity(pri="constant", poi="constant") cmds.delete(aimLoc) cmds.container("BakeResultsContainer", e=True, rc=True) cmds.animLayer("BakeResults", e=True, p=layerName) cmds.rename("BakeResults", layerComp) #cmds.deleteAttr( n=listObjects[i], at="blendParent1" ) resetLoopTime() else: cmds.animLayer(layerName) cmds.animLayer(layerName, e=True, p=mainLayerName) cmds.bakeResults(listObjects[i], t=(asT, aeT), sm=True, bol=True, at="translate") cmds.select(listObjects[i], r=True) if (cycleInfinity): cmds.setInfinity(pri="cycle", poi="cycle") else: cmds.setInfinity(pri="constant", poi="constant") cmds.delete(aimLoc) cmds.container("BakeResultsContainer", e=True, rc=True) cmds.animLayer("BakeResults", e=True, p=layerName) cmds.rename("BakeResults", layerComp) #cmds.deleteAttr( n=listObjects[i], at="blendParent1" ) resetLoopTime() cmds.select(d=True) for l in listObjects: cmds.select(l, add=True) print "\n||| OVERLAPPY end |||\n"
def spaceSwitchSetup(targets, contained): contained_grp = utility.getPrt(contained) if not contained_grp or utility.getShapes(contained_grp): contained_grp = groupIt([contained])[0] select_list = [] # check if it already parentconstrainted constraint = cmds.listConnections( "%s.translateX" % contained_grp, d=0, s=1) oldLoc = '' loc_name = contained.split("|")[-1].split(":")[-1] + '_loc' if constraint: constraint = constraint[0] loc_weight_name = cmds.listAttr(constraint, st=loc_name+"*", ud=1) print(loc_name) print(loc_weight_name) if loc_weight_name: target_name = cmds.listConnections( constraint+'.'+loc_weight_name[0], d=1, s=0, p=1)[0] target_name = target_name.replace( 'targetWeight', 'targetTranslate') oldLoc = cmds.listConnections(target_name, d=0, s=1)[0] if not oldLoc: loc = cmds.spaceLocator(name=loc_name)[0] cmds.matchTransform(loc, contained_grp) contained_grp_prt = utility.getPrt(contained_grp) if contained_grp_prt: loc = cmds.parent(loc, contained_grp_prt)[0] cmds.setAttr("%s.v"%loc, 0) utility.fixedObj([loc]) oldLoc = loc print(oldLoc) select_list.append(oldLoc) loc_name = oldLoc.split("|")[-1].split(":")[-1] print(loc_name) for target in targets: select_list.append(target) select_list.append(contained_grp) cmds.select(cl=1) for obj in select_list: cmds.select(obj, add=1) constraint = cmds.parentConstraint(mo=1)[0] target_list = cmds.listAttr(constraint, st="*W*", ud=1) print(target_list) # edit enum enumName = '' parentInx = 0 for inx, target in enumerate(target_list): if loc_name == target[0:-2]: parentInx = inx enumName = enumName + ":origin" else: enumName = enumName + ":" + target[0:-2] enumName = enumName[1:] if cmds.attributeQuery('follow', node=contained, ex=1): # edit cmds.addAttr("%s.follow" % contained, k=1, e=1, ln="follow", at="enum", en=enumName) else: # create cmds.addAttr(contained, k=1, ln="follow", at="enum", en=enumName) # set to parent as defualt cmds.setAttr("%s.follow" % contained, parentInx) condition_nodes = cmds.listConnections("%s.follow" % contained, d=1, s=0) # print(condition_nodes) if condition_nodes: for nodes in condition_nodes: cmds.delete(nodes) # connect node for inx, target in enumerate(target_list): condition_node = cmds.shadingNode("condition", au=1) cmds.connectAttr("%s.follow" % contained, "%s.firstTerm" % condition_node, f=1) weight_name = constraint+"."+target cmds.connectAttr("%s.outColorR" % condition_node, weight_name, f=1) cmds.setAttr("%s.secondTerm" % condition_node, inx) cmds.setAttr("%s.operation" % condition_node, 1) cmds.select(contained)
def make_arm_rig(self, side, clavicle, shoulder, elbow, wrist, color): #variables if not cmds.objExists('joints'): cmds.group(em=True, n='joints') cmds.group(em=True, n='controls') cmds.group(em=True, n='IKs') else: pass self.controls = [] # disconnect shoulder joint cmds.disconnectJoint(shoulder) new_joint = cmds.pickWalk(clavicle, d='down') clavicle_end = cmds.rename(new_joint, clavicle + '_end') cmds.disconnectJoint(wrist) new_joint = cmds.pickWalk(elbow, d='down') elbow_end = cmds.rename(new_joint, elbow + '_end') # duplicate arm cmds.duplicate(shoulder, n='shoulder_' + side + '_ik') cmds.duplicate(shoulder, n='shoulder_' + side + '_fk') # variables for fk chain fk_shoulder = 'shoulder_' + side + '_fk' temp = cmds.pickWalk(fk_shoulder, d='down') fk_elbow = cmds.rename(temp, 'elbow_' + side + '_fk') temp = cmds.pickWalk(fk_elbow, d='down') fk_elbow_end = cmds.rename(temp, 'elbow_' + side + '_end_fk') cmds.parent(fk_shoulder, clavicle_end) # variables for ik chain ik_shoulder = 'shoulder_' + side + '_ik' temp = cmds.pickWalk(ik_shoulder, d='down') ik_elbow = cmds.rename(temp, 'elbow_' + side + '_ik') temp = cmds.pickWalk(ik_elbow, d='down') ik_elbow_end = cmds.rename(temp, 'elbow_' + side + '_end_ik') # create ik_fk_switch control legs = leg_rig.create_rig() legs.create_ik_fk_switch(side, 'wrist_' + side + '_bind', 'arm', color, 0, 0, -5, [0, 1, 0]) cmds.matchTransform('ik_fk_arm_' + side + '_Grp', wrist) self.ik_fk_control = 'ik_fk_arm_' + side cmds.parent(wrist, elbow_end) #create ik fk chains self.make_fk_joint_chain(fk_shoulder, fk_elbow, wrist, color) cmds.parent(fk_shoulder, w=True) self.make_ik_joint_chain(side, ik_shoulder, ik_elbow, ik_elbow_end, wrist, color) # create ikfk switch self.ik_fk_switch(fk_shoulder, ik_shoulder, shoulder) self.ik_fk_switch(fk_elbow, ik_elbow, elbow) # make clavicle controls self.make_clavicle_controls(clavicle, side, color) cmds.parentConstraint(cmds.pickWalk(clavicle, d='down'), ik_shoulder) # parent everything to groups cmds.parent(fk_shoulder, ik_shoulder, shoulder, 'joints') self.l.stretchy(ik_shoulder, wrist, 'arm_stretchy_curve_' + side, side, shoulder, elbow, self.stretchy_joint, self.ik_fk_control)
def make_ik_joint_chain(self, side, shoulder, knee, elbow_end, wrist, color): # make ik handle and control cmds.ikHandle(n='ik_arm_' + side, sj=shoulder, ee=elbow_end, sol='ikRPsolver') ik_arm = 'ik_arm_' + side cmds.parent(ik_arm, 'IKs') c = custom_controls.create_custom_controls() arm_control = c.cube_curve('ANIM_arm_' + side) cmds.setAttr(arm_control + '.lineWidth', 2) self.l.override_colors(arm_control, color) cmds.xform(arm_control, cp=True) arm_control_grp = cmds.group(arm_control, n='grp_ANIM_arm_' + side) cmds.matchTransform(arm_control_grp, elbow_end, pos=True, rot=True) self.controls.append(arm_control_grp) cmds.parent(arm_control_grp, 'controls') cmds.parentConstraint(arm_control, 'ik_arm_' + side) #create a pole vector pv = self.l.create_pole_vector(side, shoulder, knee, elbow_end, 'arm', 'ik_arm_' + side, color) orient_constraint_wrist = cmds.orientConstraint(arm_control, wrist)[0] cmds.setDrivenKeyframe(orient_constraint_wrist + '.' + wrist + '_Ctl' + 'W0', cd=self.ik_fk_control + '.ikfk', v=0, dv=0) cmds.setDrivenKeyframe(orient_constraint_wrist + '.' + wrist + '_Ctl' + 'W0', cd=self.ik_fk_control + '.ikfk', v=1, dv=1) cmds.setDrivenKeyframe(orient_constraint_wrist + '.ANIM_arm_' + side + 'W1', cd=self.ik_fk_control + '.ikfk', v=1, dv=0) cmds.setDrivenKeyframe(orient_constraint_wrist + '.ANIM_arm_' + side + 'W1', cd=self.ik_fk_control + '.ikfk', v=0, dv=1) #hide visiblity condition = cmds.shadingNode('condition', asUtility=True, n='condition_node' + arm_control) cmds.connectAttr(self.ik_fk_control + '.ikfk', condition + '.firstTerm') cmds.connectAttr(condition + '.outColorR', arm_control + '.visibility') cmds.connectAttr(condition + '.outColorR', pv + '.visibility') cmds.setAttr(condition + '.colorIfTrueR', 1) cmds.setAttr(condition + '.colorIfFalseR', 0) #make a joint for stretching self.stretchy_joint = cmds.joint() cmds.setAttr(self.stretchy_joint + '.drawStyle', 2) cmds.matchTransform(self.stretchy_joint, arm_control) cmds.parent(self.stretchy_joint, arm_control)
# create Locator(s) at selected object(s) import maya.cmds as cmds targetObjs = cmds.ls(selection=True) for i in targetObjs: cmds.spaceLocator() createdObj = cmds.ls(selection=True, tail=1) cmds.matchTransform(createdObj, i)