本文整理汇总了Python中pymel.core.listRelatives方法的典型用法代码示例。如果您正苦于以下问题:Python core.listRelatives方法的具体用法?Python core.listRelatives怎么用?Python core.listRelatives使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymel.core
的用法示例。
在下文中一共展示了core.listRelatives方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createCurveInfoNode
# 需要导入模块: from pymel import core [as 别名]
# 或者: from pymel.core import listRelatives [as 别名]
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
示例2: setup_stretchy_spline_ik_curve
# 需要导入模块: from pymel import core [as 别名]
# 或者: from pymel.core import listRelatives [as 别名]
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)
示例3: init_hierarchy
# 需要导入模块: from pymel import core [as 别名]
# 或者: from pymel.core import listRelatives [as 别名]
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)
)
示例4: duplicate
# 需要导入模块: from pymel import core [as 别名]
# 或者: from pymel.core import listRelatives [as 别名]
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
示例5: create_local_parent
# 需要导入模块: from pymel import core [as 别名]
# 或者: from pymel.core import listRelatives [as 别名]
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) + ']')
示例6: getJointsInChain
# 需要导入模块: from pymel import core [as 别名]
# 或者: from pymel.core import listRelatives [as 别名]
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
示例7: alignmentParentList
# 需要导入模块: from pymel import core [as 别名]
# 或者: from pymel.core import listRelatives [as 别名]
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
示例8: findRotatedBones
# 需要导入模块: from pymel import core [as 别名]
# 或者: from pymel.core import listRelatives [as 别名]
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.
示例9: getRootNode
# 需要导入模块: from pymel import core [as 别名]
# 或者: from pymel.core import listRelatives [as 别名]
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
示例10: bBoxData
# 需要导入模块: from pymel import core [as 别名]
# 或者: from pymel.core import listRelatives [as 别名]
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
#################################################
示例11: export_blend_connections
# 需要导入模块: from pymel import core [as 别名]
# 或者: from pymel.core import listRelatives [as 别名]
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)
示例12: create_axial_correction_group_for_clusters
# 需要导入模块: from pymel import core [as 别名]
# 或者: from pymel.core import listRelatives [as 别名]
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)
示例13: add_controller_shape
# 需要导入模块: from pymel import core [as 别名]
# 或者: from pymel.core import listRelatives [as 别名]
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)
示例14: jointUnder
# 需要导入模块: from pymel import core [as 别名]
# 或者: from pymel.core import listRelatives [as 别名]
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
示例15: duplicateJointChain
# 需要导入模块: from pymel import core [as 别名]
# 或者: from pymel.core import listRelatives [as 别名]
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