本文整理匯總了Python中pymel.core.duplicate方法的典型用法代碼示例。如果您正苦於以下問題:Python core.duplicate方法的具體用法?Python core.duplicate怎麽用?Python core.duplicate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pymel.core
的用法示例。
在下文中一共展示了core.duplicate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: hold_ctrl_shapes
# 需要導入模塊: from pymel import core [as 別名]
# 或者: from pymel.core import duplicate [as 別名]
def hold_ctrl_shapes(ctrl, parent=None):
"""
Make a snapshot of all shapes of a specific ctrls.
"""
shapes = filter(lambda x: isinstance(x, pymel.nodetypes.CurveShape), ctrl.getShapes())
snapshot_transform = pymel.duplicate(ctrl, parentOnly=True, returnRootsOnly=True)[0]
for shape in shapes:
shape_snapshot = _duplicate_shape(shape)
tmp_transform = shape_snapshot.getParent()
shape_snapshot.setParent(snapshot_transform, s=True, r=True)
pymel.delete(tmp_transform)
if parent:
snapshot_transform.setParent(parent)
else:
snapshot_transform.setParent(world=True)
snapshot_transform.rename('{0}Snapshot'.format(ctrl.name()))
return snapshot_transform
示例2: duplicate
# 需要導入模塊: from pymel import core [as 別名]
# 或者: from pymel.core import duplicate [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
示例3: readIkKwargs
# 需要導入模塊: from pymel import core [as 別名]
# 或者: from pymel.core import duplicate [as 別名]
def readIkKwargs(cls, card, isMirroredSide, sideAlteration=lambda **kwargs: kwargs, kinematicType='ik'):
'''
Overriden to handle if a custom curve was given, which then needs to be duplicated, mirrored and
fed directly into the splineTwist.
'''
kwargs = cls.readKwargs(card, isMirroredSide, sideAlteration, kinematicType='ik')
if isMirroredSide:
if 'controlCountOrCrv' in kwargs and not isinstance( kwargs['controlCountOrCrv'], int ):
crv = kwargs['controlCountOrCrv']
crv = duplicate(crv)[0]
kwargs['controlCountOrCrv'] = crv
move( crv.sp, [0, 0, 0], a=True )
move( crv.rp, [0, 0, 0], a=True )
crv.sx.set(-1)
kwargs['duplicateCurve'] = False
return kwargs
示例4: duplicate_with_skin
# 需要導入模塊: from pymel import core [as 別名]
# 或者: from pymel.core import duplicate [as 別名]
def duplicate_with_skin(nodes, parentNode=None):
#親子付けがあってもエラーはかないように修正
print nodes
# リストタイプじゃなかったらリストに変換する
if not isinstance(nodes, list):
nodes = [nodes]
dupObjs = []
for node in nodes:
#子供のノード退避用ダミーペアレントを用意
dummy = common.TemporaryReparent().main(mode='create')
common.TemporaryReparent().main(node,dummyParent=dummy, mode='cut')
#複製
dup = cmds.duplicate(node)[0]
#ウェイト転送メソッドをSimpleWeightコピペに変更
weight.SimpleWeightCopyPaste().main(node, mode='copy', saveName=__name__, weightFile=node)
weight.SimpleWeightCopyPaste().main(dup, mode='paste', saveName=__name__, weightFile=node)
#親子付けを戻す
common.TemporaryReparent().main(node,dummyParent=dummy, mode='parent')
#ダミーペアレントを削除
common.TemporaryReparent().main(dummyParent=dummy, mode='delete')
if parentNode is not None:
cmds.parent(dup, parentNode)
dupObjs.append(dup)
return dupObjs
#シーン內、もしくは入力メッシュ內にゼロポリゴンオブジェクトがあるかどうか調べる関數
示例5: instance
# 需要導入模塊: from pymel import core [as 別名]
# 或者: from pymel.core import duplicate [as 別名]
def instance(self, source_transform_node):
"""instances the given nodes hierarchy
"""
# duplicate the given node
# then replace the instanceable nodes with instances
# find instanceable nodes in the node and dupNode
source_hierarchy = self.walk_hierarchy(source_transform_node)
# if there is no node in the sourceHierarchy just return
# the instance of the given node
if len(source_hierarchy) < 1:
dup_node = pm.duplicate(source_transform_node, ilf=1, rc=True)[0]
pm.select(dup_node)
return
dup_node = pm.duplicate(source_transform_node, rc=True)[0]
dup_hierarchy = self.walk_hierarchy(dup_node)
for i, node in enumerate(dup_hierarchy):
shape = node.getShape()
if shape is not None and isinstance(shape,
tuple(self._instanceables)):
# instance the corresponding sourceNode
source_node = source_hierarchy[i]
new_instance_node = pm.duplicate(source_node, ilf=True)[0]
pm.parent(new_instance_node, node.getParent(), r=False)
pm.delete(node)
pm.select(dup_node)
return dup_node
示例6: create_ik_hierarchy
# 需要導入模塊: from pymel import core [as 別名]
# 或者: from pymel.core import duplicate [as 別名]
def create_ik_hierarchy(self):
"""Creates the ik hierarchy
"""
self.ik_hierarchy = self.base_hierarchy.duplicate(class_=JointHierarchy, suffix="_ik")
示例7: create_fk_hierarchy
# 需要導入模塊: from pymel import core [as 別名]
# 或者: from pymel.core import duplicate [as 別名]
def create_fk_hierarchy(self):
"""Creates the fk hierarchy
"""
self.fk_hierarchy = self.base_hierarchy.duplicate(class_=JointHierarchy, suffix="_fk")
示例8: duplicate_with_connections
# 需要導入模塊: from pymel import core [as 別名]
# 或者: from pymel.core import duplicate [as 別名]
def duplicate_with_connections(cls):
"""duplicates the selected nodes with connections to the network
"""
return pm.duplicate(ic=1, rr=1)
示例9: duplicate_input_graph
# 需要導入模塊: from pymel import core [as 別名]
# 或者: from pymel.core import duplicate [as 別名]
def duplicate_input_graph(cls):
"""duplicates the selected nodes with all their inputs
"""
return pm.duplicate(un=1, rr=1)
示例10: unshape_parent_nodes
# 需要導入模塊: from pymel import core [as 別名]
# 或者: from pymel.core import duplicate [as 別名]
def unshape_parent_nodes(cls):
"""Moves the shape node of a mesh to another transform node as a
children if the mesh node has other meshes under it. Essentially
cleaning the scene.
"""
mesh_nodes_with_transform_children = []
all_meshes = pm.ls(dag=1, type='mesh')
for node in all_meshes:
parent = node.getParent()
tra_under_shape = pm.ls(
parent.listRelatives(),
type='transform'
)
if len(tra_under_shape):
mesh_nodes_with_transform_children.append(parent)
for node in mesh_nodes_with_transform_children:
# duplicate the node
dup = pm.duplicate(node)[0]
# remove all descendents
all_descendents = dup.listRelatives(ad=1)
# remove the shape from the list
all_descendents.remove(dup.getShape())
pm.delete(all_descendents)
# parent under the original node
pm.parent(dup, node)
# remove the shape of the original node
pm.delete(node.getShape())
示例11: split_camera
# 需要導入模塊: from pymel import core [as 別名]
# 或者: from pymel.core import duplicate [as 別名]
def split_camera(cls):
"""splits one camera to multiple cameras
"""
selection = pm.ls(sl=1, type=pm.nt.Transform)
if not selection:
raise RuntimeError("Please select at least one camera")
new_cameras = []
from anima.env.mayaEnv import camera_tools
for cam in selection:
cut_info = camera_tools.find_cut_info(cam)
for cut_in, cut_out in cut_info:
print(cut_in, cut_out)
# duplicate the original camera with input graph
dup_cam = pm.duplicate(cam, un=1)[0]
# remove all keyframes out of the cut range
# remove befor
pm.cutKey(dup_cam, time=(-1000, cut_in - 1))
# # remove after
pm.cutKey(dup_cam, time=(cut_out + 1, 100000))
# rename the new cam
dup_cam.rename("%s_#" % cam.name())
new_cameras.append(dup_cam)
# remove original camera
pm.delete(cam)
# select all new cameras
pm.select(new_cameras)
示例12: duplicateObject
# 需要導入模塊: from pymel import core [as 別名]
# 或者: from pymel.core import duplicate [as 別名]
def duplicateObject(object):
#duplicate the object
dup = pm.duplicate(object)
return dup[0]
示例13: createSurfaceFromJoints
# 需要導入模塊: from pymel import core [as 別名]
# 或者: from pymel.core import duplicate [as 別名]
def createSurfaceFromJoints(joints, name="surface", ibtCVNum=0, degree=3):
"""
Create a nurbs surface along the given joints.
nurbs CV position is defined by joint position.
:param joints: `list` list of joint nodes
:param name: `string` name of the built surface
:param ibtCVNum: `int` number of cv points added inbetween the joint position
:param degree: `int` nurbs surface degree
:return: `PyNode` result surface
"""
# build surface from joints, one span for each joint
auxCrv = createCurveFromJoint(joints, name+"_crv", ibtCVNum, degree)
startPos = joints[0].getTranslation(space="world")
endPos = joints[-1].getTranslation(space="world")
offDir = (om.MVector(*(startPos-endPos))^om.MVector(0,1,0)).normal()
if offDir.length() == 0: offDir = om.MVector(0,0,-1)
print startPos, endPos, offDir[0], offDir[1], offDir[2]
buildCrv1 = pm.duplicate(auxCrv)
pm.move(offDir.x*0.5, offDir.y*0.5, offDir.z*0.5, buildCrv1, r=1)
buildCrv2 = pm.duplicate(auxCrv)
pm.move(offDir.x*-0.5, offDir.y*-0.5, offDir.z*-0.5, buildCrv2, r=1)
auxSurf = pm.loft(buildCrv1, buildCrv2, n=name, ch=0, u=1, d=degree)[0]
pm.rebuildSurface(auxSurf, ch=0, su=1, du=1, dv=degree, sv=0)
pm.delete(auxCrv, buildCrv1, buildCrv2)
# auxSurf.setParent(0)
return auxSurf
示例14: duplicateJointChain
# 需要導入模塊: from pymel import core [as 別名]
# 或者: from pymel.core import duplicate [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
示例15: duplicate_with_skin
# 需要導入模塊: from pymel import core [as 別名]
# 或者: from pymel.core import duplicate [as 別名]
def duplicate_with_skin(nodes, parentNode=None):
#親子付けがあってもエラーはかないように修正
#print nodes
# リストタイプじゃなかったらリストに変換する
if not isinstance(nodes, list):
nodes = [nodes]
dupObjs = []
for node in nodes:
#子供のノード退避用ダミーペアレントを用意
dummy = common.TemporaryReparent().main(mode='create')
common.TemporaryReparent().main(node,dummyParent=dummy, mode='cut')
#複製
dup = cmds.duplicate(node)[0]
#ウェイト転送メソッドをSimpleWeightコピペに変更
weight.SimpleWeightCopyPaste().main(node, mode='copy', saveName=__name__, weightFile=node)
weight.SimpleWeightCopyPaste().main(dup, mode='paste', saveName=__name__, weightFile=node)
#親子付けを戻す
common.TemporaryReparent().main(node,dummyParent=dummy, mode='parent')
#ダミーペアレントを削除
common.TemporaryReparent().main(dummyParent=dummy, mode='delete')
if parentNode is not None:
cmds.parent(dup, parentNode)
dupObjs.append(dup)
return dupObjs
#シーン內、もしくは入力メッシュ內にゼロポリゴンオブジェクトがあるかどうか調べる関數