Python pymel.core.listRelatives() Examples
The following are 20
code examples of pymel.core.listRelatives().
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
pymel.core
, or try the search function
.
Example #1
Source File: node.py From mgear_core with MIT License | 6 votes |
def createCurveInfoNode(crv): """Create and connect a curveInfo node. Arguments: crv (dagNode): The curve. Returns: pyNode: the newly created node. >>> crv_node = nod.createCurveInfoNode(self.slv_crv) """ node = pm.createNode("curveInfo") shape = pm.listRelatives(crv, shapes=True)[0] pm.connectAttr(shape + ".local", node + ".inputCurve") return node # TODO: update using plusMinusAverage node
Example #2
Source File: log.py From fossil with BSD 3-Clause "New" or "Revised" License | 6 votes |
def findRotatedBones(joints=None): ''' Checks joints (defaulting to the ) ''' if not joints: obj = core.findNode.getRoot() joints = listRelatives(obj, ad=True, type='joint') rotated = [] for j in joints: if not core.math.isClose( j.r.get(), [0, 0, 0] ): rotated.append( (j, j.r.get()) ) #print '{0} rotated of {1} tested'.format(len(rotated), len(joints) ) return rotated # ----------------------------------------------------------------------------- # SimpleLog is useful for other deeply nested things reporting errors. This might # be the better way to do things in general.
Example #3
Source File: symmetrize.py From SIWeightEditor with MIT License | 6 votes |
def alignmentParentList(parentList): #親子順にリストを整理 alignedList = [] for node in parentList: #子のノードを取得※順序がルート→孫→子の順番なので注意、いったんルートなしで取得 #children = common.get_children(node,type=['transform'], root_includes=False) children = pm.listRelatives(node, ad=True, type='transform', f=True) #末尾にルートを追加 children.append(node) #逆順にして親→子→孫順に整列 children.reverse() #同一ツリー内マルチ選択時の重複回避のためフラグで管理 for child in children: appendedFlag = False for alignedNode in alignedList : if alignedNode == child: appendedFlag = True if appendedFlag is False: alignedList.append(str(child)) return alignedList
Example #4
Source File: rigutils.py From DynRigBuilder with MIT License | 6 votes |
def getJointsInChain(rootJoint): """ get all the joints in the joint chain. sorted by hierarchy. :param rootJoint: `PyNode` root joint of the joint chain :return: `list` list of joint nodes """ joints = [rootJoint] crtJnt = rootJoint while True: childJnt = pm.listRelatives(crtJnt, c=1, typ="joint") if childJnt: joints.append(childJnt[0]) crtJnt = childJnt[0] else: break return joints
Example #5
Source File: picker.py From anima with MIT License | 6 votes |
def create_local_parent(self): """creates local parent and axial correction group of local parent """ # create the localParent group self._local_parent = pm.group( em=True, n=self._object.name() + "_local_parent" ) # move it to the same place where constrainedParent is matrix = pm.xform(self._constrained_parent, q=True, ws=True, m=True) pm.xform(self._local_parent, ws=True, m=matrix) # parent it to the constrained parents parent parents = pm.listRelatives(self._constrained_parent, p=True) if len(parents) != 0: temp = pm.parent(self._local_parent, parents[0], a=True) self._local_parent = temp[0] self._local_parent = pm.nodetypes.DagNode(self._local_parent) index = self._object.attr('pickedData.createdNodes').numElements() self._local_parent.attr('message') >> \ self._object.attr('pickedData.createdNodes[' + str(index) + ']')
Example #6
Source File: rigging.py From anima with MIT License | 6 votes |
def duplicate(self, class_=None, prefix="", suffix=""): """duplicates itself and returns a new joint hierarchy :param class_: The class of the created JointHierarchy. Default value is JointHierarchy :param prefix: Prefix for newly created joints :param suffix: Suffix for newly created joints """ if class_ is None: class_ = self.__class__ new_start_joint = pm.duplicate(self.start_joint)[0] all_hierarchy = list(reversed(new_start_joint.listRelatives(ad=1, type=pm.nt.Joint))) new_end_joint = all_hierarchy[len(self.joints) - 2] # delete anything below pm.delete(new_end_joint.listRelatives(ad=1)) new_hierarchy = class_(start_joint=new_start_joint, end_joint=new_end_joint) for j, nj in zip(self.joints, new_hierarchy.joints): nj.rename("{prefix}{joint}{suffix}".format(prefix=prefix, suffix=suffix, joint=j.name())) return new_hierarchy
Example #7
Source File: rigging.py From anima with MIT License | 6 votes |
def init_hierarchy(self): """Initialize the hierarchy joints from start_joint to the given end_joint :return: """ self.joints = [self.start_joint] found_end_joint = False for j in reversed(self.start_joint.listRelatives(ad=1, type=pm.nt.Joint)): self.joints.append(j) if j == self.end_joint: found_end_joint = True break if not found_end_joint: raise RuntimeError( "Cannot reach end joint (%s) from start joint (%s)" % (self.end_joint, self.start_joint) )
Example #8
Source File: rigging.py From anima with MIT License | 6 votes |
def setup_stretchy_spline_ik_curve(cls): """ """ selection = pm.ls(sl=1) curve = selection[0] curve_info = pm.createNode("curveInfo") mult_div = pm.createNode("multiplyDivide") curve_shape = pm.listRelatives(curve, s=1) curve_shape[0].worldSpace >> curve_info.ic curve_info.arcLength >> mult_div.input1X curve_length = curve_info.arcLength.get() mult_div.input2X.set(curve_length) mult_div.operation.set(2) pm.select(mult_div, curve_info, curve_shape[0], add=True)
Example #9
Source File: rigging.py From anima with MIT License | 5 votes |
def add_controller_shape(cls): selection = pm.ls(sl=1) if len(selection) < 2: return objects = [] for i in range(0, (len(selection) - 1)): objects.append(selection[i]) joints = selection[len(selection) - 1] for i in range(0, len(objects)): parents = pm.listRelatives(objects[i], p=True) if len(parents) > 0: temp_list = pm.parent(objects[i], w=1) objects[i] = temp_list[0] temp_list = pm.parent(objects[i], joints) objects[i] = temp_list[0] pm.makeIdentity(objects[i], apply=True, t=1, r=1, s=1, n=0) temp_list = pm.parent(objects[i], w=True) objects[i] = temp_list[0] shapes = pm.listRelatives(objects, s=True, pa=True) for i in range(0, len(shapes)): temp_list = pm.parent(shapes[i], joints, r=True, s=True) shapes[i] = temp_list[0] joint_shapes = pm.listRelatives(joints, s=True, pa=True) for i in range(0, len(joint_shapes)): name = "%sShape%f" % (joints, (i + 1)) temp = ''.join(name.split('|', 1)) pm.rename(joint_shapes[i], temp) pm.delete(objects) pm.select(joints)
Example #10
Source File: rigging.py From anima with MIT License | 5 votes |
def create_axial_correction_group_for_clusters(cls): selection = pm.ls(sl=1) Rigging.axial_correction_group() pm.select(cl=1) for cluster_handle in selection: cluster_handle_shape = pm.listRelatives(cluster_handle, s=True) cluster_parent = pm.listRelatives(cluster_handle, p=True) trans = cluster_handle_shape[0].origin.get() cluster_parent[0].translate.set(trans[0], trans[1], trans[2]) pm.select(selection)
Example #11
Source File: auxiliary.py From anima with MIT License | 5 votes |
def export_blend_connections(): """Exports the connection commands from selected objects to the blendShape of another object. The resulted text file contains all the MEL scripts to reconnect the objects to the blendShape node. So after exporting the connection commands you can export the blendShape targets as another maya file and delete them from the scene, thus your scene gets lite and loads much more quickly. """ selection_list = pm.ls(tr=1, sl=1, l=1) dialog_return = pm.fileDialog2(cap="Save As", fm=0, ff='Text Files(*.txt)') filename = dialog_return[0] print(filename) print("\n\nFiles written:\n--------------------------------------------\n") with open(filename, 'w') as fileId: for i in range(0, len(selection_list)): shapes = pm.listRelatives(selection_list[i], s=True, f=True) main_shape = "" for j in range(0, len(shapes)): if pm.getAttr(shapes[j] + '.intermediateObject') == 0: main_shape = shapes break if main_shape == "": main_shape = shapes[0] con = pm.listConnections(main_shape, t="blendShape", c=1, s=1, p=1) cmd = "connectAttr -f %s.worldMesh[0] %s;" % ( ''.join(map(str, main_shape)), ''.join(map(str, con[0].name())) ) print("%s\n" % cmd) fileId.write("%s\n" % cmd) print("\n------------------------------------------------------\n") print("filename: %s ...done\n" % filename)
Example #12
Source File: joint.py From anima with MIT License | 5 votes |
def jointUnder(self, joint): jointUnder = pm.listRelatives(joint, c=1, type="joint") if not len(jointUnder): pm.setAttr(joint.jointOrient, (0, 0, 0)) return None return jointUnder
Example #13
Source File: rigutils.py From DynRigBuilder with MIT License | 5 votes |
def duplicateJointChain(rootJoint, replace=None, suffix=None): """ Duplicate the given joint chain. :param rootJoint: `PyNode` root joint of the given joint chain :param replace: `tuple` or `list` (old string, new string) rename the duplicated joint chain by replacing string in given joint name :param suffix: `string` rename the duplicated joint chain by adding suffix to the given joint name :return: `list` list of joints in the duplicated joint chain. ordered by hierarchy """ srcJnts = getJointsInChain(rootJoint) dupJnts = [] if not replace and not suffix: raise ValueError("Please rename the duplicated joint chain.") for i, srcJnt in enumerate(srcJnts): newName = srcJnt.name() if replace: newName = newName.replace(replace[0], replace[1]) if suffix: newName = "{0}_{1}".format(newName, suffix) dupJnt = pm.duplicate(srcJnt, n=newName, po=1)[0] dupJnts.append(dupJnt) for attr in ['t', 'r', 's', 'jointOrient']: pm.setAttr("{0}.{1}".format(dupJnt.name(), attr), pm.getAttr("{0}.{1}".format(srcJnt.name(), attr))) if i>0: dupJnt.setParent(dupJnts[i-1]) # # for i, srcJnt in enumerate(srcJnts): # if i==0: continue # srcPar = pm.listRelatives(srcJnt, p=1) # if srcPar: # dupJnts[i].setParent(srcPar[0].name().replace(replace[0], replace[1])) return dupJnts
Example #14
Source File: skeleton.py From metanode with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_pose(root): data = [] stack = [root] while stack: jnt = stack.pop() translate = pm.xform(jnt, q=True, translation=True, ws=True) rotate = pm.xform(jnt, q=True, rotation=True, ws=True) data.append((jnt.name(), translate, rotate)) stack.extend(pm.listRelatives(jnt, type='joint')) return data
Example #15
Source File: meshNavigation.py From mgear_core with MIT License | 5 votes |
def bBoxData(obj=None, yZero=False, *args): """Get bounding box data of a mesh object Arguments: obj (dagNode): Mesh object yZero (bool): If True, sets the Y axis value to 0 in world space args: Returns: list: center, radio, bounding box full data """ volCenter = False if not obj: obj = pm.selected()[0] shapes = pm.listRelatives(obj, ad=True, s=True) if shapes: bb = pm.polyEvaluate(shapes, b=True) volCenter = [(axis[0] + axis[1]) / 2 for axis in bb] if yZero: volCenter[1] = bb[1][0] radio = max([bb[0][1] - bb[0][0], bb[2][1] - bb[2][0]]) / 1.7 return volCenter, radio, bb ################################################# # CLOSEST LOCATIONS #################################################
Example #16
Source File: anim_utils.py From mgear_core with MIT License | 5 votes |
def getRootNode(): """Returns the root node from a selected node Returns: PyNode: The root top node """ root = None current = pm.ls(sl=True) if not current: raise RuntimeError("You need to select at least one rig node") if pm.objExists("{}.is_rig".format(current[0])): root = current[0] else: holder = current[0] while pm.listRelatives(holder, parent=True) and not root: if pm.objExists("{}.is_rig".format(holder)): root = holder else: holder = pm.listRelatives(holder, parent=True)[0] if not root: raise RuntimeError("Couldn't find root node from your selection") return root
Example #17
Source File: squashStretch.py From fossil with BSD 3-Clause "New" or "Revised" License | 5 votes |
def getSquashers(ctrl): ''' Returns the objs the squasher controls follow, which have the set driven keys. Cheesy at the moment because it's just the list of children (alphabetized). ''' squashers = listRelatives(ctrl, type='transform') return sorted( set(squashers) )
Example #18
Source File: test_fossil.py From fossil with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_basicBiped(): #gui = main.RigTool() # Make the default biped card.bipedSetup(spineCount=5) # Make all the bones and test their existence select(core.findNode.allCards()) main.RigTool.buildBones() for j in jointsToMake: assert objExists(j), 'Joint ' + j + ' was not made' root = core.findNode.getRoot() assert len(listRelatives(root, ad=True, type='joint')) == (len(jointsToMake) - 1), 'Too many bones were made' # Build the rig spine = PyNode('Spine_card') rigData = spine.rigData rigData['rigCmd'] = 'SplineChest' spine.rigData = rigData select(core.findNode.allCards()) main.RigTool.buildRig()
Example #19
Source File: auxiliary.py From anima with MIT License | 4 votes |
def axial_correction_group(obj, to_parents_origin=False, name_prefix="", name_postfix="_ACGroup#"): """creates a new parent to zero out the transformations if to_parents_origin is set to True, it doesn't zero outs the transformations but creates a new parent at the same place of the original parent :returns: pymel.core.nodeTypes.Transform """ obj = get_valid_dag_node(obj) if name_postfix == "": name_postfix = "_ACGroup#" ac_group = pm.group( em=True, n=(name_prefix + obj.name() + name_postfix) ) ac_group = pm.parent(ac_group, obj)[0] pm.setAttr(ac_group + ".t", [0, 0, 0]) pm.setAttr(ac_group + ".r", [0, 0, 0]) pm.setAttr(ac_group + ".s", [1, 1, 1]) parent = pm.listRelatives(obj, p=True) if len(parent) != 0: pm.parent(ac_group, parent[0], a=True) else: pm.parent(ac_group, w=True) if to_parents_origin: pm.setAttr(ac_group + ".t", [0, 0, 0]) pm.setAttr(ac_group + ".r", [0, 0, 0]) pm.setAttr(ac_group + ".s", [1, 1, 1]) pm.parent(obj, ac_group, a=True) # for joints also set the joint orient to zero if isinstance(obj, pm.nodetypes.Joint): # set the joint rotation and joint orient to zero obj.setAttr('r', (0, 0, 0)) obj.setAttr('jo', (0, 0, 0)) return ac_group
Example #20
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