Python maya.cmds.makeIdentity() Examples
The following are 19
code examples of maya.cmds.makeIdentity().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
maya.cmds
, or try the search function
.
Example #1
Source File: dpBaseControlClass.py From dpAutoRigSystem with GNU General Public License v2.0 | 7 votes |
def setControlDirection(self, cvNode, cvDirection, *args): """ Rotate the node given to have the correct direction orientation. """ if cvDirection == "-X": cmds.setAttr(cvNode+".rotateX", 90) cmds.setAttr(cvNode+".rotateY", -90) elif cvDirection == "+X": cmds.setAttr(cvNode+".rotateX", -90) cmds.setAttr(cvNode+".rotateY", -90) elif cvDirection == "-Y": cmds.setAttr(cvNode+".rotateZ", 180) elif cvDirection == "-Z": cmds.setAttr(cvNode+".rotateX", -90) elif cvDirection == "+Z": cmds.setAttr(cvNode+".rotateX", 90) else: pass #default +Y, just pass cmds.makeIdentity(cvNode, rotate=True, apply=True) # rotate and freezeTransformation from given cvRot vector: cmds.rotate(self.cvRot[0], self.cvRot[1], self.cvRot[2], self.cvCurve) cmds.makeIdentity(self.cvCurve, rotate=True, apply=True)
Example #2
Source File: orientjoints.py From cmt with MIT License | 6 votes |
def align_with_child(joints): """Aligns the up axis of the given joints with their respective child joint. @param joints: List of joints to orient. """ for joint in joints: children = _unparent_children(joint) if children: cmds.delete( cmds.aimConstraint( children[0], joint, aim=(1, 0, 0), upVector=(0, 1, 0), worldUpType="objectrotation", worldUpVector=(0, 1, 0), worldUpObject=children[0], ) ) cmds.makeIdentity(joint, apply=True) _reparent_children(joint, children) if joints: cmds.select(joints)
Example #3
Source File: Modify.py From rush with MIT License | 5 votes |
def freezeAll(): cmds.makeIdentity(apply=True, t=True, r=True, s=True, n=False)
Example #4
Source File: orientjoints.py From cmt with MIT License | 5 votes |
def create_orient_manipulator(joint, material): joint_scale = cmds.jointDisplayScale(query=True) joint_radius = cmds.getAttr("{0}.radius".format(joint)) radius = joint_scale * joint_radius children = cmds.listRelatives(joint, children=True, path=True) if children: p1 = cmds.xform(joint, q=True, ws=True, t=True) p1 = OpenMaya.MPoint(*p1) p2 = cmds.xform(children[0], q=True, ws=True, t=True) p2 = OpenMaya.MPoint(*p2) radius = p1.distanceTo(p2) arrow_cvs = [ [-1, 0, 0], [-1, 2, 0], [-2, 2, 0], [0, 4, 0], [2, 2, 0], [1, 2, 0], [1, 0, 0], [-1, 0, 0], ] arrow_cvs = [[x[0] * radius, x[1] * radius, x[2] * radius] for x in arrow_cvs] shape = cmds.curve(name="{0}_zForward".format(joint), degree=1, point=arrow_cvs) # shape = cmds.sphere(n='{0}_zForward'.format(joint), p=(0, 0, 0), ax=(0, 0, -1), ssw=0, esw=180, r=radius, d=3, ut=0, tol=0.01, s=8, nsp=4, ch=0)[0] # cmds.setAttr('{0}.sz'.format(shape), 0) # cmds.select(shape) # cmds.hyperShade(assign=material) group = cmds.createNode("transform", name="{0}_grp".format(shape)) cmds.parent(shape, group) cmds.makeIdentity(shape, apply=True) cmds.addAttr(shape, longName=MESSAGE_ATTRIBUTE, attributeType="message") cmds.connectAttr( "{0}.message".format(joint), "{0}.{1}".format(shape, MESSAGE_ATTRIBUTE) ) for attr in ["tx", "ty", "tz", "ry", "rz", "v"]: cmds.setAttr("{0}.{1}".format(shape, attr), lock=True, keyable=False) return group, shape
Example #5
Source File: orientjoints.py From cmt with MIT License | 5 votes |
def template_joints(joints=None, reorient_children=True, reset_orientation=True): if joints is None: joints = cmds.ls(sl=True, type="joint") if not joints: raise RuntimeError("No joint selected to orient.") if reorient_children: children = cmds.listRelatives(fullPath=True, allDescendents=True, type="joint") joints.extend(children) red, green, blue = create_shaders() orient_group = cmds.createNode("transform", name=ORIENT_GROUP) manips = [] for joint in joints: if reset_orientation: cmds.makeIdentity(joint, apply=True) cmds.joint( joint, edit=True, orientJoint="xyz", secondaryAxisOrient="yup", children=False, zeroScaleOrient=True, ) if not cmds.listRelatives(joint, children=True): zero_orient([joint]) continue group, manip = create_orient_manipulator(joint, blue) manips.append(manip) cmds.parent(group, orient_group) cmds.parentConstraint(joint, group) cmds.setAttr(joint + ".template", 1) cmds.select(manips)
Example #6
Source File: orientjoints.py From cmt with MIT License | 5 votes |
def make_planar(joints): for joint in joints: parent = cmds.listRelatives(joint, parent=True, path=True) if not parent: log.warning( "Cannot make %s planar because it does not have a parent.", joint ) continue children = _unparent_children(joint) if not children: log.warning( "Cannot make %s planar because it does not have any children.", joint ) continue cmds.delete( cmds.aimConstraint( children[0], joint, aim=(1, 0, 0), u=(0, 1, 0), worldUpType="object", worldUpObject=parent[0], ) ) cmds.makeIdentity(joint, apply=True) _reparent_children(joint, children) if joints: cmds.select(joints)
Example #7
Source File: Modify.py From rush with MIT License | 5 votes |
def freezeOnlyScale(): cmds.makeIdentity(apply=True, t=False, r=False, s=True, n=False) # Conversions
Example #8
Source File: Modify.py From rush with MIT License | 5 votes |
def freezeOnlyRotation(): cmds.makeIdentity(apply=True, t=False, r=True, s=False, n=False) # Snap align
Example #9
Source File: Modify.py From rush with MIT License | 5 votes |
def freezeOnlyTranslation(): cmds.makeIdentity(apply=True, t=True, r=False, s=False, n=False)
Example #10
Source File: unFrozenTransforms.py From medic with MIT License | 5 votes |
def fix(self, report, params): cmds.makeIdentity(report.node().name(), apply=True, t=True, r=True, s=True) return True
Example #11
Source File: AEsporeNodeTemplate.py From spore with MIT License | 5 votes |
def emit(self, *args): """ run the actual sample command and check if transforms are frozen """ # exit spore context since it looses track of points after sampling if cmds.currentCtx().startswith('spore'): cmds.setToolTo('selectSuperContext') in_mesh = node_utils.get_connected_in_mesh(self._node) transform = cmds.listRelatives(in_mesh, p=True, f=True)[0] if cmds.getAttr(transform + '.translateX') != 0\ or cmds.getAttr(transform + '.translateY') != 0\ or cmds.getAttr(transform + '.translateZ') != 0\ or cmds.getAttr(transform + '.rotateX') != 0\ or cmds.getAttr(transform + '.rotateY') != 0\ or cmds.getAttr(transform + '.rotateZ') != 0\ or cmds.getAttr(transform + '.scaleX') != 1\ or cmds.getAttr(transform + '.scaleY') != 1\ or cmds.getAttr(transform + '.scaleZ') != 1: msg = 'Feeze transformations to sample the geomety!' result = message_utils.IOHandler().confirm_dialog(msg, 'Freeze Transformations') if result: cmds.makeIdentity(transform, a=True, s=True, r=True, t=True, n=0) else: return cmds.setAttr('{}.emit'.format(self._node), 1) cmds.sporeSampleCmd() # ------------------------------------------------------------------------ # # clear button # ------------------------------------------------------------------------ #
Example #12
Source File: create.py From maya-spline-ik with GNU General Public License v3.0 | 5 votes |
def __createSlideControls(self): # variables offsets = [] controls = [] # loop controls for suffix in ["slide", "slide_min", "slide_max"]: ctrlOffset, ctrl = control.createControlShape( "{0}_{1}".format(self.name, suffix), self.slideControlShape, self.slideControlColour ) # scale constraint cmds.scaleConstraint(self.rootControl, ctrlOffset) # append to list offsets.append(ctrlOffset) controls.append(ctrl) # scale controls scale = [0.75, 0.5, 0.5] for ctrl, s in zip(controls, scale): cmds.setAttr("{0}.scale".format(ctrl), s, s, s) cmds.makeIdentity(ctrl, apply=True, scale=True) # parent controls cmds.parent( offsets, self.rootControl ) return controls
Example #13
Source File: dpControls.py From dpAutoRigSystem with GNU General Public License v2.0 | 5 votes |
def setAndFreeze(nodeName="", tx=None, ty=None, tz=None, rx=None, ry=None, rz=None, sx=None, sy=None, sz=None, freeze=True): """This function set attribute values and do a freezeTransfomation. """ if nodeName != "": attrNameList = ['tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz'] attrValueList = [tx, ty, tz, rx, ry, rz, sx, sy, sz] # setting attribute values: for v, attrValue in enumerate(attrValueList): if attrValue: try: cmds.setAttr(nodeName+'.'+attrNameList[v], attrValue) except: pass # looking the need of freeze: if freeze: freezeT = False freezeR = False freezeS = False if tx != None or ty != None or tz != None: freezeT = True if rx != None or ry != None or rz != None: freezeR = True if sx != None or sy != None or sz != None: freezeS = True try: cmds.makeIdentity(nodeName, apply=freeze, translate=freezeT, rotate=freezeR, scale=freezeS) except: pass
Example #14
Source File: dpControls.py From dpAutoRigSystem with GNU General Public License v2.0 | 5 votes |
def cvJointLoc(self, ctrlName, r=0.3, d=1, rot=(0, 0, 0), guide=True, *args): """Create and return a cvJointLocator curve to be usually used in the guideSystem and the clusterHandle to shapeSize. """ # create locator curve: cvLoc = self.cvLocator(ctrlName+"_CvLoc", r, d) # create arrow curves: cvArrow1 = cmds.curve(n=ctrlName+"_CvArrow1", d=3, p=[(-0.1*r, 0.9*r, 0.2*r), (-0.1*r, 0.9*r, 0.23*r), (-0.1*r, 0.9*r, 0.27*r), (-0.1*r, 0.9*r, 0.29*r), (-0.1*r, 0.9*r, 0.3*r), (-0.372*r, 0.9*r, 0.24*r), (-0.45*r, 0.9*r, -0.13*r), (-0.18*r, 0.9*r, -0.345*r), (-0.17*r, 0.9*r, -0.31*r), (-0.26*r, 0.9*r, -0.41*r), (-0.21*r, 0.9*r, -0.41*r), (-0.05*r, 0.9*r, -0.4*r), (0, 0.9*r, -0.4*r), (-0.029*r, 0.9*r, -0.33*r), (-0.048*r, 0.9*r, -0.22*r), (-0.055*r, 0.9*r, -0.16*r), (-0.15*r, 0.9*r, -0.272*r), (-0.12*r, 0.9*r, -0.27*r), (-0.35*r, 0.9*r, -0.1*r), (-0.29*r, 0.9*r, 0.15*r), (-0.16*r, 0.9*r, 0.21*r), (-0.1*r, 0.9*r, 0.2*r)] ) cvArrow2 = cmds.curve(n=ctrlName+"_CvArrow2", d=3, p=[(0.1*r, 0.9*r, -0.2*r), (0.1*r, 0.9*r, -0.23*r), (0.1*r, 0.9*r, -0.27*r), (0.1*r, 0.9*r, -0.29*r), (0.1*r, 0.9*r, -0.3*r), (0.372*r, 0.9*r, -0.24*r), (0.45*r, 0.9*r, 0.13*r), (0.18*r, 0.9*r, 0.345*r), (0.17*r, 0.9*r, 0.31*r), (0.26*r, 0.9*r, 0.41*r), (0.21*r, 0.9*r, 0.41*r), (0.05*r, 0.9*r, 0.4*r), (0, 0.9*r, 0.4*r), (0.029*r, 0.9*r, 0.33*r), (0.048*r, 0.9*r, 0.22*r), (0.055*r, 0.9*r, 0.16*r), (0.15*r, 0.9*r, 0.272*r), (0.12*r, 0.9*r, 0.27*r), (0.35*r, 0.9*r, 0.1*r), (0.29*r, 0.9*r, -0.15*r), (0.16*r, 0.9*r, -0.21*r), (0.1*r, 0.9*r, -0.2*r)] ) cvArrow3 = cmds.curve(n=ctrlName+"_CvArrow3", d=3, p=[(-0.1*r, -0.9*r, 0.2*r), (-0.1*r, -0.9*r, 0.23*r), (-0.1*r, -0.9*r, 0.27*r), (-0.1*r, -0.9*r, 0.29*r), (-0.1*r, -0.9*r, 0.3*r), (-0.372*r, -0.9*r, 0.24*r), (-0.45*r, -0.9*r, -0.13*r), (-0.18*r, -0.9*r, -0.345*r), (-0.17*r, -0.9*r, -0.31*r), (-0.26*r, -0.9*r, -0.41*r), (-0.21*r, -0.9*r, -0.41*r), (-0.05*r, -0.9*r, -0.4*r), (0, -0.9*r, -0.4*r), (-0.029*r, -0.9*r, -0.33*r), (-0.048*r, -0.9*r, -0.22*r), (-0.055*r, -0.9*r, -0.16*r), (-0.15*r, -0.9*r, -0.272*r), (-0.12*r, -0.9*r, -0.27*r), (-0.35*r, -0.9*r, -0.1*r), (-0.29*r, -0.9*r, 0.15*r), (-0.16*r, -0.9*r, 0.21*r), (-0.1*r, -0.9*r, 0.2*r)] ) cvArrow4 = cmds.curve(n=ctrlName+"_CvArrow4", d=3, p=[(0.1*r, -0.9*r, -0.2*r), (0.1*r, -0.9*r, -0.23*r), (0.1*r, -0.9*r, -0.27*r), (0.1*r, -0.9*r, -0.29*r), (0.1*r, -0.9*r, -0.3*r), (0.372*r, -0.9*r, -0.24*r), (0.45*r, -0.9*r, 0.13*r), (0.18*r, -0.9*r, 0.345*r), (0.17*r, -0.9*r, 0.31*r), (0.26*r, -0.9*r, 0.41*r), (0.21*r, -0.9*r, 0.41*r), (0.05*r, -0.9*r, 0.4*r), (0, -0.9*r, 0.4*r), (0.029*r, -0.9*r, 0.33*r), (0.048*r, -0.9*r, 0.22*r), (0.055*r, -0.9*r, 0.16*r), (0.15*r, -0.9*r, 0.272*r), (0.12*r, -0.9*r, 0.27*r), (0.35*r, -0.9*r, 0.1*r), (0.29*r, -0.9*r, -0.15*r), (0.16*r, -0.9*r, -0.21*r), (0.1*r, -0.9*r, -0.2*r)] ) cvArrow5 = cmds.curve(n=ctrlName+"_CvArrow5", d=1, p=[(0, 0, 1.2*r), (0.09*r, 0, 1*r), (-0.09*r, 0, 1*r), (0, 0, 1.2*r)] ) cvArrow6 = cmds.curve(n=ctrlName+"_CvArrow6", d=1, p=[(0, 0, 1.2*r), (0, 0.09*r, 1*r), (0, -0.09*r, 1*r), (0, 0, 1.2*r)] ) # rename curveShape: locArrowList = [cvLoc, cvArrow1, cvArrow2, cvArrow3, cvArrow4, cvArrow5, cvArrow6] self.renameShape(locArrowList) # create ball curve: cvTemplateBall = self.cvControl("Ball", ctrlName+"_CvBall", r=0.7*r, d=3) # parent shapes to transform: locCtrl = cmds.group(name=ctrlName, empty=True) ballChildrenList = cmds.listRelatives(cvTemplateBall, shapes=True, children=True) for ballChildren in ballChildrenList: cmds.setAttr(ballChildren+".template", 1) self.transferShape(True, False, cvTemplateBall, [locCtrl]) for transform in locArrowList: self.transferShape(True, False, transform, [locCtrl]) # set rotation direction: cmds.setAttr(locCtrl+".rotateX", rot[0]) cmds.setAttr(locCtrl+".rotateY", rot[1]) cmds.setAttr(locCtrl+".rotateZ", rot[2]) cmds.makeIdentity(locCtrl, rotate=True, apply=True) # create an attribute to be used as guide by module: cmds.addAttr(locCtrl, longName="nJoint", attributeType='long') cmds.setAttr(locCtrl+".nJoint", 1) # colorize curveShapes: self.colorShape([locCtrl], 'blue') # shapeSize setup: shapeSizeCluster = self.shapeSizeSetup(locCtrl) cmds.select(clear=True) return [locCtrl, shapeSizeCluster]
Example #15
Source File: dpBaseControlClass.py From dpAutoRigSystem with GNU General Public License v2.0 | 4 votes |
def combineCurves(self, curveList, *args): """ Combine all guiven curve to just one main curve and return it. """ mainCurve = curveList[0] cmds.makeIdentity(mainCurve, translate=True, rotate=True, scale=True, apply=True) for item in curveList[1:]: cmds.makeIdentity(item, translate=True, rotate=True, scale=True, apply=True) self.ctrls.transferShape(True, False, item, [mainCurve]) cmds.setAttr(mainCurve+".className", self.guideModuleName, type="string") return mainCurve
Example #16
Source File: transform.py From SISideBar with MIT License | 4 votes |
def freeze_transform(mode='', c_comp=False): from . import sisidebar_sub selections = cmds.ls(sl=True, l=True, tr=True) #下からのマルチ選択でも正しく上からフリーズできるように階層深さでソート sel_depth = [[sel, check_depth(sel)] for sel in selections] sel_depth = sorted(sel_depth, key=lambda a:a[1]) for sel in sel_depth: sel = sel[0] dummy = common.TemporaryReparent().main(mode='create') srt_dummy = common.TemporaryReparent().main(mode='create') #common.TemporaryReparent().main(sel, dummyParent=dummy, mode='cut') if not c_comp: set_maching(nodes=srt_dummy, mode='all', pre_sel=selections) matching_obj=srt_dummy trs_matching(node=sel, sel_org=False) common.TemporaryReparent().main(sel,dummyParent=dummy, srtDummyParent=srt_dummy, mode='custom_cut', preSelection=selections) attr_lock_flag_list = check_attr_locked(sel) try: if mode == 'all': cmds.makeIdentity(sel, n=0, s=1, r=1, jointOrient=1, t=1, apply=True, pn=1) cmds.xform(srt_dummy, t=[0, 0, 0]) cmds.xform(srt_dummy, ro=[0, 0, 0]) cmds.xform(srt_dummy, s=[1, 1, 1]) if mode == 'trans': cmds.makeIdentity(sel, n=0, s=0, r=0, jointOrient=0, t=1, apply=True, pn=1) cmds.xform(srt_dummy, t=[0, 0, 0]) if mode == 'rot': cmds.makeIdentity(sel, n=0, s=0, r=1, jointOrient=0, t=0, apply=True, pn=1) cmds.xform(srt_dummy, ro=[0, 0, 0]) if mode == 'scale': cmds.makeIdentity(sel, n=0, s=1, r=0, jointOrient=0, t=0, apply=True, pn=1) cmds.xform(srt_dummy, s=[1, 1, 1]) if mode == 'joint': if cmds.nodeType(sel) == 'joint': cmds.makeIdentity(sel, n=0, s=0, r=0, jointOrient=1, t=0, apply=True, pn=1) cmds.xform(srt_dummy, ro=[0, 0, 0]) if mode == 'trans' or mode =='all': cmds.xform(sel+'.scalePivot', t=[0, 0, 0], os=True) cmds.xform(sel+'.rotatePivot', t=[0, 0, 0], os=True) except Exception as e: print e.message cmds.inViewMessage( amg=e.message, pos='midCenterTop', fade=True, ta=0.75, a=0.5) set_attr_locked(sel, attr_lock_flag_list) common.TemporaryReparent().main(sel, dummyParent=dummy, mode='parent') common.TemporaryReparent().main(sel, dummyParent=srt_dummy, mode='parent') common.TemporaryReparent().main(dummyParent=dummy, mode='delete')# common.TemporaryReparent().main(dummyParent=srt_dummy, mode='delete')#ダミー親削除 cmds.select(selections, r=True) sisidebar_sub.get_matrix()
Example #17
Source File: dpEye.py From dpAutoRigSystem with GNU General Public License v2.0 | 4 votes |
def createIrisPupilSetup(self, s, side, type, codeName, sec, jointLabelNumber, *args): ''' Predefined function to add Iris or Pupil setup. Returns control. ''' # declare cv guides: cvLoc = side+self.userGuideName+"_Guide_"+type.capitalize()+"Loc" # creating joint: mainJnt = cmds.joint(name=side+self.userGuideName+"_"+self.langDic[self.langName][codeName]+"_1_Jnt", scaleCompensate=False) cmds.addAttr(mainJnt, longName='dpAR_joint', attributeType='float', keyable=False) utils.setJointLabel(mainJnt, jointLabelNumber, 18, self.userGuideName+"_"+self.langDic[self.langName][codeName]+"_1") # joint position: cmds.delete(cmds.parentConstraint(cvLoc, mainJnt, maintainOffset=False)) # create end joint: endJoint = cmds.joint(name=side+self.userGuideName+"_"+self.langDic[self.langName][codeName]+"_JEnd", scaleCompensate=False) cmds.delete(cmds.parentConstraint(mainJnt, endJoint, maintainOffset=False)) cmds.setAttr(endJoint+".translateZ", 1) # creating control: if type == IRIS: ctrlId = "id_012_EyeIris" else: ctrlId = "id_013_EyePupil" ctrl = self.ctrls.cvControl(ctrlId, side+self.userGuideName+"_"+self.langDic[self.langName][codeName]+"_1_Ctrl", r=(self.ctrlRadius*0.3), d=self.curveDegree) utils.originedFrom(objName=ctrl, attrString=self.base+";"+self.guide) cmds.makeIdentity(ctrl, rotate=True, apply=True) # create constraints and arrange hierarchy: ctrlZero = utils.zeroOut([ctrl]) cmds.delete(cmds.parentConstraint(cvLoc, ctrlZero[0], maintainOffset=False)) cmds.parent(ctrlZero[0], self.baseEyeCtrl) # fixing flip mirror: if s == 1: if cmds.getAttr(self.moduleGrp+".flip") == 1: if not "X" == cmds.getAttr(self.moduleGrp+".aimDirectionName"): cmds.setAttr(ctrlZero[0]+".scaleX", -1) else: cmds.setAttr(ctrlZero[0]+".scaleX", 1) if not "Y" == cmds.getAttr(self.moduleGrp+".aimDirectionName"): cmds.setAttr(ctrlZero[0]+".scaleY", -1) else: cmds.setAttr(ctrlZero[0]+".scaleY", 1) if not "Z" == cmds.getAttr(self.moduleGrp+".aimDirectionName"): cmds.setAttr(ctrlZero[0]+".scaleZ", -1) else: cmds.setAttr(ctrlZero[0]+".scaleZ", 1) cmds.parentConstraint(self.fkEyeCtrl, ctrlZero[0], maintainOffset=True, name=ctrlZero[0]+"_ParentConstraint") cmds.scaleConstraint(self.fkEyeCtrl, ctrlZero[0], maintainOffset=True, name=ctrlZero[0]+"_ScaleConstraint") cmds.parent(mainJnt, self.jnt) cmds.parentConstraint(ctrl, mainJnt, maintainOffset=False, name=mainJnt+"_ParentConstraint") cmds.scaleConstraint(ctrl, mainJnt, maintainOffset=True, name=mainJnt+"_ScaleConstraint") return ctrl
Example #18
Source File: ml_parentShape.py From ml_tools with MIT License | 4 votes |
def parentShape(child=None, parent=None, maintainOffset=True): ''' Parent a child shape node to a parent transform. The child node can be a shape, or a transform which has any number of shapes. ''' if not child or not parent: sel = mc.ls(sl=True) if sel and len(sel) > 1: child = sel[:-1] parent = sel[-1] else: OpenMaya.MGlobal.displayWarning('Please make a selection.') return parentNodeType = mc.nodeType(parent) if not parentNodeType in ('transform', 'joint', 'ikHandle'): OpenMaya.MGlobal.displayWarning('Parent must be a transform node.') return if not isinstance(child, (list, tuple)): child = [child] newChild = unparentShape(child) shapes = list() for each in newChild: thisChild = mc.parent(each, parent)[0] mc.makeIdentity(thisChild, apply=True) for s in mc.listRelatives(thisChild, shapes=True, noIntermediate=True, path=True): shape = mc.parent(s, parent, shape=True, relative=True)[0] #move to bottom mc.reorder(shape, back=True) #rename parentName = mc.ls(parent, shortNames=True)[0] shapes.append(mc.rename(shape, parentName+'Shape#')) mc.delete(newChild) for each in child: if not mc.listRelatives(each): #if it doesn't have any kids, delete it mc.delete(each) return shapes
Example #19
Source File: symmetrize.py From SIWeightEditor with MIT License | 4 votes |
def duplycateSymmetry(object): meshNode = cmds.listRelatives(object, s=True, pa=True, type='mesh', fullPath=True) if meshNode is not None: #エラー吐くことがあるのでノンデフォーマヒストリを削除 cmds.bakePartialHistory(object,ppt=True) #ネームスペースから分割 nemeSplit = object.split('|') newName = nemeSplit[-1] #左右リネーム関数呼び出し newName = renameLR(newName) #複製して反転 duplicated = pm.duplicate(object, name=newName) try: parentNode = duplicated[0].firstParent()#Pymelの機能で親の階層を取得しておく。listRelativesと同じような。 parentNode = str(parentNode)#cmdsで使えるように文字列に変換 #左右リネーム関数呼び出し newParent = renameLR(parentNode) except: parentNode = None newParent = None duplicated = str(duplicated[0])#cmdsで使えるように文字列に変換 #子供のオブジェクト取得関数呼び出し children = pm.listRelatives(duplicated, ad=True, type='transform', f=True) #子供のオブジェクトがある場合は重複を避けるため削除 if len(children) != 0: cmds.delete(children) #アトリビュートのロック解除 #全部のロック解除しないと親が変わったときのロカール値が変わらず、ズレることがある。 attr = ['.translate', '.rotate', '.scale'] axis = ['X', 'Y', 'Z'] for varA in range(0, 3): for varB in range(0, 3): cmds.setAttr(duplicated + attr[varA] + axis[varB], lock=False) #ワールドスケール用ダミーロケータ作成 dummy = common.TemporaryReparent().main(mode='create') cmds.parent(duplicated, dummy) #X方向に-1スケーリングしてからスケールフリーズ cmds.scale(-1, 1, 1, dummy, relative=True, pivot=(0,0,0)) #杏仁生成を防ぐためにダミーロケータのスケールをフリーズ、負の値が親に入ってると杏仁が生成されるような。 if cmds.nodeType(duplicated) == 'joint': #ジョイントを正しい回転、位置に修正するため、スケールフリーズ前のグローバル値を取得しておく pos = cmds.xform(duplicated, q=True, t=True, ws=True) rot = cmds.xform(duplicated, q=True, ro=True, ws=True) cmds.makeIdentity(dummy, apply=True, translate=False, rotate=False, scale=True, preserveNormals=True) #元の親名と違い、かつ新しい親名のオブジェクトが存在する場合は付け替え if parentNode is None: cmds.parent(duplicated, w=True) else: if parentNode != newParent and cmds.ls(newParent): cmds.parent(duplicated, newParent) else: cmds.parent(duplicated, parentNode) #ダミーペアレントを削除 common.TemporaryReparent().main(dummyParent=dummy, mode='delete') cmds.makeIdentity(duplicated, apply=True, translate=False, rotate=False, scale=True, preserveNormals=True) if cmds.nodeType(duplicated) == 'joint': cmds.xform(duplicated , t=pos, ro=rot, ws=True) return duplicated