Python maya.cmds.listRelatives() Examples
The following are 30
code examples of maya.cmds.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
maya.cmds
, or try the search function
.
Example #1
Source File: dpFacialControl.py From dpAutoRigSystem with GNU General Public License v2.0 | 7 votes |
def dpLoadBSNode(self, *args): """ Load selected object as blendShapeNode """ selectedList = cmds.ls(selection=True) if selectedList: if cmds.objectType(selectedList[0]) == "blendShape": cmds.textField(self.bsNodeTextField, edit=True, text=selectedList[0]) self.dpLoadBSTgtList(selectedList[0]) self.bsNode = selectedList[0] elif cmds.objectType(selectedList[0]) == "transform": meshList = cmds.listRelatives(selectedList[0], children=True, shapes=True, noIntermediate=True, type="mesh") if meshList: bsNodeList = cmds.listConnections(meshList[0], type="blendShape") if bsNodeList: self.dpLoadBSTgtList(bsNodeList[0]) self.bsNode = bsNodeList[0] else: mel.eval("warning \""+self.langDic[self.langName]["e018_selectBlendShape"]+"\";") else: mel.eval("warning \""+self.langDic[self.langName]["e018_selectBlendShape"]+"\";") else: mel.eval("warning \""+self.langDic[self.langName]["e018_selectBlendShape"]+"\";") else: mel.eval("warning \""+self.langDic[self.langName]["e018_selectBlendShape"]+"\";")
Example #2
Source File: dpControls.py From dpAutoRigSystem with GNU General Public License v2.0 | 7 votes |
def renameShape(self, transformList, *args): """Find shapes, rename them to Shapes and return the results. """ resultList = [] for transform in transformList: # list all children shapes: childShapeList = cmds.listRelatives(transform, shapes=True, children=True, fullPath=True) if childShapeList: # verify if there is only one shape and return it renamed: if len(childShapeList) == 1: shape = cmds.rename(childShapeList[0], transform+"Shape") cmds.select(clear=True) resultList.append(shape) # else rename and return one list of renamed shapes: elif len(childShapeList) > 1: for i, child in enumerate(childShapeList): shape = cmds.rename(child, transform+str(i)+"Shape") resultList.append(shape) cmds.select(clear=True) else: print "There are not children shape to rename inside of:", transform return resultList
Example #3
Source File: freeze.py From SISideBar with MIT License | 6 votes |
def freeze(): cmds.selectMode(o=True) selection = cmds.ls(sl=True, type = 'transform') dummy = common.TemporaryReparent().main(mode='create')#モジュールでダミーの親作成 clusterCopy = modeling.ClusterCopy() for sel in selection: allChildren = [sel] + cmds.listRelatives(sel, ad=True)#子供を取得して1つのリストにする polyMesh = common.search_polygon_mesh(allChildren) if polyMesh: for mesh in polyMesh: common.TemporaryReparent().main(mesh, dummyParent=dummy, mode='cut') defCls = clusterCopy.copy(mesh) cmds.bakePartialHistory(mesh,pc=True) if defCls: clusterCopy.paste(mesh) common.TemporaryReparent().main(mesh, dummyParent=dummy, mode='parent')#コピーのおわったメッシュの子供を元に戻す common.TemporaryReparent().main(dummyParent=dummy, mode='delete')#ダミー親削除 cmds.select(selection, r=True)
Example #4
Source File: skeleton.py From cmt with MIT License | 6 votes |
def mirror(joint, search_for, replace_with): joints = [joint] + (cmds.listRelatives(joint, ad=True, path=True) or []) for joint in joints: mirrored_joint = joint.replace(search_for, replace_with) if cmds.objExists(mirrored_joint): translate = list(cmds.getAttr("{0}.t".format(joint))[0]) parent = cmds.listRelatives(joint, parent=True, path=True) if parent and search_for not in parent[0]: translate[2] *= -1.0 else: translate = [x * -1.0 for x in translate] cmds.setAttr("{0}.t".format(mirrored_joint), *translate) rotate = cmds.getAttr("{0}.r".format(joint))[0] cmds.setAttr("{0}.r".format(mirrored_joint), *rotate) scale = cmds.getAttr("{0}.s".format(joint))[0] cmds.setAttr("{0}.s".format(mirrored_joint), *scale)
Example #5
Source File: skeleton.py From cmt with MIT License | 6 votes |
def get_joint_data(node): """Get the serializable data of a node. :param node: Joint or transform name. :return: Data dictionary. """ node_type = cmds.nodeType(node) shapes = cmds.listRelatives(node, children=True, shapes=True) if node_type not in ["joint", "transform"] or (shapes and node_type == "transform"): # Skip nodes that are not joints or transforms or if there are shapes below. return None parent = cmds.listRelatives(node, parent=True) parent = parent[0] if parent else None joint_data = {"nodeType": node_type, "name": node, "parent": parent} for attr in ATTRIBUTES: attribute = "{}.{}".format(node, attr) if not cmds.objExists(attribute): continue value = cmds.getAttr(attribute) if isinstance(value, list): value = list(value[0]) joint_data[attr] = value return joint_data
Example #6
Source File: test_skeleton.py From cmt with MIT License | 6 votes |
def assert_hierarachies_match(self): self.assertEqual(7, len(cmds.ls(type="joint"))) # Make sure the joint orients are the same translates = [cmds.getAttr("{0}.t".format(x))[0] for x in cmds.ls(type="joint")] rotates = [cmds.getAttr("{0}.r".format(x))[0] for x in cmds.ls(type="joint")] orients = [cmds.getAttr("{0}.jo".format(x))[0] for x in cmds.ls(type="joint")] for orient, new_orient in zip(self.orients, orients): self.assertListAlmostEqual(orient, new_orient) for translate, new_translate in zip(self.translates, translates): self.assertListAlmostEqual(translate, new_translate) for rotate, new_rotate in zip(self.rotates, rotates): self.assertListAlmostEqual(rotate, new_rotate) # The geometry should not have been exported self.assertFalse(cmds.objExists(self.cube)) self.assertTrue(cmds.objExists(self.group)) self.assertEqual("joint1", cmds.listRelatives(self.group, children=True)[0])
Example #7
Source File: transformstack.py From cmt with MIT License | 6 votes |
def get_stack(node): """Get the transforms in the transform stack :param node: Stack leaf transform :return: List of transforms """ stack = [node] parent = cmds.listRelatives(node, parent=True, path=True) if parent: parent = parent[0] while _is_transform_stack_node(parent): stack.insert(0, parent) parent = cmds.listRelatives(parent, parent=True, path=True) if parent: parent = parent[0] return stack
Example #8
Source File: dpIsolate.py From dpAutoRigSystem with GNU General Public License v2.0 | 6 votes |
def dpIsolate(self, attrName, nodeList, *args): """ Function to run isolate setup. """ # get father zero out transform node zeroGrp = cmds.listRelatives(nodeList[2], allParents=True, type="transform")[0] # create parent constraint pConst = cmds.parentConstraint(nodeList[0], nodeList[1], zeroGrp, maintainOffset=True, skipTranslate=["x", "y", "z"])[0] # add isolate attribute to selected control cmds.addAttr(nodeList[2], longName=attrName, defaultValue=1.0, minValue=0, maxValue=1, keyable=True) # create reverse node reverseNode = cmds.createNode('reverse', name=nodeList[2]+"_"+attrName.capitalize()+"_Rev") # do isolate connections cmds.connectAttr(nodeList[2]+"."+attrName, pConst+"."+nodeList[0]+"W0", force=True) cmds.connectAttr(nodeList[2]+"."+attrName, reverseNode+".inputX", force=True) cmds.connectAttr(reverseNode+".outputX", pConst+"."+nodeList[1]+"W1", force=True) cmds.select(nodeList[2])
Example #9
Source File: skeleton.py From cmt with MIT License | 6 votes |
def dumps(root): """Get the serializable form of the joint/transform hierarchy. :param root: The root node of the hierarchy to export. :return: A list of transform/joint data in depth first order. """ if isinstance(root, string_types): root = [root] data = [] for node in root: joint_data = get_joint_data(node) if not joint_data: continue data.append(joint_data) # Recurse down to all the children children = cmds.listRelatives(node, children=True, path=True) or [] for child in children: data += dumps(child) return data
Example #10
Source File: dpControls.py From dpAutoRigSystem with GNU General Public License v2.0 | 6 votes |
def setSourceColorOverride(self, sourceItem, destinationList, *args): """ Check if there's a colorOverride for destination shapes and try to set it to source shapes. """ colorList = [] for item in destinationList: childShapeList = cmds.listRelatives(item, shapes=True, type="nurbsCurve", fullPath=True) if childShapeList: for childShape in childShapeList: if cmds.getAttr(childShape+".overrideEnabled") == 1: if cmds.getAttr(childShape+".overrideRGBColors") == 1: colorList.append(cmds.getAttr(childShape+".overrideColorR")) colorList.append(cmds.getAttr(childShape+".overrideColorG")) colorList.append(cmds.getAttr(childShape+".overrideColorB")) self.colorShape([sourceItem], colorList, True) else: colorList.append(cmds.getAttr(childShape+".overrideColor")) self.colorShape([sourceItem], colorList[0]) break
Example #11
Source File: dpControls.py From dpAutoRigSystem with GNU General Public License v2.0 | 6 votes |
def shapeSizeSetup(self, transformNode, *args): """ Find shapes, create a cluster deformer to all and set the pivot to transform pivot. Returns the created cluster. """ clusterHandle = None childShapeList = cmds.listRelatives(transformNode, shapes=True, children=True) # print "Child length {0}".format(len(childShapeList)) if childShapeList: thisNamespace = childShapeList[0].split(":")[0] cmds.namespace(set=thisNamespace, force=True) clusterName = transformNode.split(":")[1]+"_ShapeSizeCH" clusterHandle = cmds.cluster(childShapeList, name=clusterName)[1] cmds.setAttr(clusterHandle+".visibility", 0) cmds.xform(clusterHandle, scalePivot=(0, 0, 0), worldSpace=True) cmds.namespace(set=":") else: print "There are not children shape to create shapeSize setup of:", transformNode return clusterHandle
Example #12
Source File: curve.py From maya-spline-ik with GNU General Public License v3.0 | 6 votes |
def createCurveShape(name, points): """ Create a curve and rename the shapes to be unique. :param str name: Name of curve :param list points: List of points. """ # create curve curve = cmds.curve(p=points, d=1, n=name) # rename shapes shapes = [] for shape in cmds.listRelatives(curve, s=True, f=True) or []: shape = cmds.rename(shape, "{0}Shape".format(name)) shapes.append(shape) return curve, shapes
Example #13
Source File: curve.py From maya-spline-ik with GNU General Public License v3.0 | 6 votes |
def convertToBezierCurve(curve): """ Check if the parsed curve is a bezier curve, if this is not the case convert the curve to a bezier curve. :param str curve: Name of curve """ # get shape curveShape = cmds.listRelatives(curve, s=True)[0] # convert to bezier curve if cmds.nodeType(curveShape) == "bezierCurve": return cmds.select(curve) cmds.nurbsCurveToBezier() # ----------------------------------------------------------------------------
Example #14
Source File: dpUtils.py From dpAutoRigSystem with GNU General Public License v2.0 | 6 votes |
def clearNodeGrp(nodeGrpName='dpAR_GuideMirror_Grp', attrFind='guideBaseMirror', unparent=False): """ Check if there is any node with the attribute attrFind in the nodeGrpName and then unparent its children and delete it. """ if cmds.objExists(nodeGrpName): foundChildrenList = [] childrenList = cmds.listRelatives(nodeGrpName, children=True, type="transform") if childrenList: for child in childrenList: if cmds.objExists(child+"."+attrFind) and cmds.getAttr(child+"."+attrFind) == 1: foundChildrenList.append(child) if len(foundChildrenList) != 0: if unparent: for item in foundChildrenList: cmds.parent(item, world=True) cmds.delete(nodeGrpName) else: cmds.delete(nodeGrpName)
Example #15
Source File: dag.py From mgear_core with MIT License | 6 votes |
def __findChild(node, name): """This find children function will stop search after firs child found.child This is a faster version of __findchildren Arguments: node (dagNode): The input node to search name (str): The name to search Returns: dagNode: Children node """ try: for item in cmds.listRelatives(node.name(), allDescendents=True, type="transform"): if item.split("|")[-1] == name: return pm.PyNode(item) except pm.MayaNodeError: for item in node.listRelatives(allDescendents=True, type="transform"): if item.split("|")[-1] == name: return item return False
Example #16
Source File: dag.py From mgear_core with MIT License | 6 votes |
def __findChildren(node, name, firstOnly=False, partialName=False): if partialName: children = [item for item in node.listRelatives(allDescendents=True, type="transform") if item.name().split("|")[-1].split("_")[-1] == name] else: children = [item for item in node.listRelatives(allDescendents=True, type="transform") if item.name().split("|")[-1] == name] if not children: return False if firstOnly: return children[0] return children
Example #17
Source File: manager.py From spore with MIT License | 6 votes |
def name_changed(self, widget, name): """ triggered by one of the spore widgets when the user requests a name change :param widget: the source of the signal :param name: the new name """ node_name = widget.long_name if cmds.objExists(node_name): if re.match('^[A-Za-z0-9_-]*$', name) and not name[0].isdigit(): # transform = cmds.listRelatives(node_name, p=True, f=True)[0] instancer = node_utils.get_instancer(node_name) cmds.rename(instancer, '{}Instancer'.format(name)) cmds.rename(node_name, '{}Shape'.format(name)) # cmds.rename(transform, name) else: self.io.set_message('Invalid Name: Use only A-Z, a-z, 0-9, -, _', 2) return self.refresh_spore()
Example #18
Source File: manager.py From spore with MIT License | 6 votes |
def context_request(self, widget, action): if action.text() == 'Delete': selection = cmds.ls(sl=1, typ='sporeNode') for geo_wdg, spore_wdgs in self.wdg_tree.iteritems(): for spore_wdg in spore_wdgs: spore_node = spore_wdg.name print spore_node if spore_wdg.is_selected and cmds.objExists(spore_node): instancer = node_utils.get_instancer(spore_node) transform = cmds.listRelatives(spore_node, p=True, f=True) if len(cmds.listRelatives(transform, c=1)) == 1: cmds.delete((spore_node, transform[0], instancer)) else: cmds.delete((spore_node, instancer)) selection.remove(spore_node) cmds.select(selection) self.refresh_spore()
Example #19
Source File: transform.py From SISideBar with MIT License | 6 votes |
def reset_actor(): from . import sisidebar_sub sel = cmds.ls(sl=True, l=True) joints = cmds.ls(sl=True, l=True, type='joint') if not joints: joints = [] for s in sel: if cmds.nodeType(s) == 'KTG_ModelRoot': child_joints = cmds.ls(cmds.listRelatives(s, ad=True, f=True), l=True, type='joint') if child_joints: joints += child_joints if not sel: joints = cmds.ls(l=True, type='joint') for j in joints: con_info = cmds.connectionInfo(j+'.bindPose', dfs=True) if not con_info: continue con_info = con_info[0] bind_info = con_info.replace('world', 'xform') pose = cmds.getAttr(bind_info) cmds.xform(j, m=pose) sisidebar_sub.get_matrix()
Example #20
Source File: common.py From cmt with MIT License | 6 votes |
def local_offset(node): """Get the local matrix relative to the node's parent. This takes in to account the offsetParentMatrix :param node: Node name :return: MMatrix """ offset = OpenMaya.MMatrix(cmds.getAttr("{}.worldMatrix[0]".format(node))) parent = cmds.listRelatives(node, parent=True, path=True) if parent: pinv = OpenMaya.MMatrix( cmds.getAttr("{}.worldInverseMatrix[0]".format(parent[0])) ) offset *= pinv return offset
Example #21
Source File: common.py From cmt with MIT License | 5 votes |
def duplicate_chain(start, end, prefix="", suffix="", search_for="", replace_with=""): """Duplicates the transform chain starting at start and ending at end. :param start: The start transform. :param end: The end transform. :param prefix: Prefix to add to the new chain. :param suffix: Suffix to add to the new chain. :param search_for: Search for token :param replace_with: Replace token :return: A list of the duplicated joints, a list of the original joints that were duplicated. """ joint = end joints = [] original_joints = [] while joint: name = "{0}{1}{2}".format(prefix, joint, suffix) if search_for or replace_with: name = name.replace(search_for, replace_with) original_joints.append(joint) duplicate_joint = cmds.duplicate(joint, name=name, parentOnly=True)[0] if joints: cmds.parent(joints[-1], duplicate_joint) joints.append(duplicate_joint) if joint == start: break joint = cmds.listRelatives(joint, parent=True, path=True) if joint: joint = joint[0] else: raise RuntimeError("{0} is not a descendant of {1}".format(end, start)) joints.reverse() original_joints.reverse() return joints, original_joints
Example #22
Source File: common.py From SISideBar with MIT License | 5 votes |
def cutChildNode(self): # 処理ノードの親子を取得しておく nodeChildren = cmds.listRelatives(self.node, children=True, fullPath=True) or [] for child in nodeChildren: # 子のノードがトランスフォームならダミーに親子付けして退避 if cmds.nodeType(child) in self.node_list: cmds.parent(child, self.dummyParent) #フリーズトランスフォーム用に場合分け親子付け関数を用意 #子を含むマルチ選択状態の場合は別のダミー親につけてフリーズ後のSRT状態を調整する
Example #23
Source File: freeze.py From SISideBar with MIT License | 5 votes |
def deleteZeroShape(node): meshnode = cmds.listRelatives(node, s=True, pa=True, type='mesh', fullPath=True) for mesh in meshnode: triNum = cmds.polyEvaluate(mesh, triangle=True) historyNode = cmds.listHistory(mesh, f=True) if len(historyNode) <= 1: cmds.delete(mesh)
Example #24
Source File: freeze.py From SISideBar with MIT License | 5 votes |
def get_shading_engines(root_node=None): en_list = [] if root_node is None: shapes = pm.ls(type="mesh") else: if isinstance(root_node, (str, unicode)): root_node = pm.PyNode(root_node) shapes = root_node.listRelatives(ad=True, type="mesh") file_nodes = [] for i in shapes: shading_engines = i.shadingGroups() en_list+=shading_engines return list(set(en_list))
Example #25
Source File: weight.py From SISideBar with MIT License | 5 votes |
def symmetry_weight(srcNode=None, dstNode=None, symWeight=True): ''' ウェイトシンメトリする関数 srcNode→反転元 dstNode→反転先 symWeight→ウェイトミラーするかどうか ''' # スキンクラスタを取得 if srcNode is None: return srcShapes = cmds.listRelatives(srcNode, s=True, pa=True, type='mesh') if srcShapes: srcSkinCluster = cmds.ls(cmds.listHistory(srcNode), type='skinCluster') # スキンクラスタがあったらジョイントラベルを設定してウェイトミラー if srcSkinCluster: # バインド状態を転送する関数呼び出し skinJointAll = cmds.skinCluster(srcSkinCluster, q=True, inf=True) #ジョイントを取得 for skinJoint in skinJointAll: # ジョイントラベル設定関数呼び出し joint_label(skinJoint, visibility=False) if symWeight is False or dstNode is None: return transfer_weight(srcNode, dstNode, transferWeight=False, returnInfluences=True) dstShapes = cmds.listRelatives(dstNode, s=True, pa=True, type='mesh') dstSkinCluster = cmds.listConnections(dstShapes[0] + '.inMesh', s=True, d=False) cmds.copySkinWeights(ss=srcSkinCluster[0], ds=dstSkinCluster[0], mirrorMode='YZ', surfaceAssociation='closestComponent', influenceAssociation='label', normalize=True)
Example #26
Source File: uExport.py From uExport with zlib License | 5 votes |
def joints(self): if self.export_root: returnMe = [] children = cmds.listRelatives(self.export_root, type='joint',allDescendents=True) if children: returnMe.extend(children) returnMe.append(self.export_root[0]) return returnMe
Example #27
Source File: common.py From SISideBar with MIT License | 5 votes |
def search_polygon_mesh(object, serchChildeNode=False, fullPath=False, mesh=True, nurbs=False): ''' 選択したものの中からポリゴンメッシュを返す関数 serchChildeNode→子供のノードを探索するかどうか ''' # リストタイプじゃなかったらリストに変換する if not isinstance(object, list): temp = object object = [] object.append(temp) polygonMesh = [] # 子供のノードを加えるフラグが有効な場合は追加 if serchChildeNode is True: parentNodes = object for node in parentNodes: try: nodes = cmds.listRelatives(node, ad=True, c=True, typ='transform', fullPath=fullPath, s=False) except: pass if nodes is not None: object = object + nodes # メッシュノードを探して見つかったらリストに追加して返す for node in object: if mesh: try: meshnode = cmds.listRelatives(node, s=True, pa=True, type='mesh', fullPath=True) if meshnode: polygonMesh.append(node) except: pass if nurbs: try: nurbsnode = cmds.listRelatives(node, s=True, pa=True, type='nurbsSurface', fullPath=True) if nurbsnode: polygonMesh.append(node) except: pass if len(polygonMesh) != 0: return polygonMesh else: return []
Example #28
Source File: common.py From SISideBar with MIT License | 5 votes |
def reparentNode(self): dummyChildren = cmds.listRelatives(self.dummyParent, children=True, fullPath=True) or [] for child in dummyChildren: if cmds.nodeType(child) in self.node_list: cmds.parent(child, self.node) #指定タイプへのコンポーネント変換をまとめて
Example #29
Source File: dag.py From mgear_core with MIT License | 5 votes |
def getShapes(node): """Returns the shape of the dagNode Arguments: node (dagNode): The input node to search the shape Returns: list: The shapes of the node """ return node.listRelatives(shapes=True)
Example #30
Source File: common.py From SISideBar with MIT License | 5 votes |
def customCutChildNode(self): nodeChildren = cmds.listRelatives(self.node, children=True, fullPath=True) or [] for child in nodeChildren: if cmds.nodeType(child) in self.node_list: if child in self.preSelection: #print 'parent to dummy' cmds.parent(child, self.dummyParent) else: #print 'parent to srt dummy' cmds.parent(child, self.srtDummyParent)