本文整理匯總了Python中pymel.core.getAttr方法的典型用法代碼示例。如果您正苦於以下問題:Python core.getAttr方法的具體用法?Python core.getAttr怎麽用?Python core.getAttr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pymel.core
的用法示例。
在下文中一共展示了core.getAttr方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: getFCurveValues
# 需要導入模塊: from pymel import core [as 別名]
# 或者: from pymel.core import getAttr [as 別名]
def getFCurveValues(fcv_node, division, factor=1):
"""Get X values evenly spaced on the FCurve.
Arguments:
fcv_node (pyNode or str): The FCurve to evaluate.
division (int): The number of division you want to evaluate on
the FCurve.
factor (float): Multiplication factor. Default = 1. (optional)
Returns:
list of float: The values in a list float.
>>> self.st_value = fcu.getFCurveValues(self.settings["st_profile"],
self.divisions)
"""
incr = 1 / (division - 1.0)
values = []
for i in range(division):
pm.setAttr(fcv_node + ".input", i * incr)
values.append(pm.getAttr(fcv_node + ".output") * factor)
return values
示例2: recordNodesMatrices
# 需要導入模塊: from pymel import core [as 別名]
# 或者: from pymel.core import getAttr [as 別名]
def recordNodesMatrices(nodes, desiredTime):
"""get the matrices of the nodes provided and return a dict of
node:matrix
Args:
nodes (list): of nodes
Returns:
dict: node:node matrix
"""
nodeToMat_dict = {}
for fk in nodes:
fk = pm.PyNode(fk)
nodeToMat_dict[fk.name()] = fk.getAttr("worldMatrix", time=desiredTime)
return nodeToMat_dict
示例3: check_sequence_name
# 需要導入模塊: from pymel import core [as 別名]
# 或者: from pymel.core import getAttr [as 別名]
def check_sequence_name(self):
"""checks sequence name and asks the user to set one if maya is in UI
mode and there is no sequence name set
"""
sequencer = pm.ls(type='sequencer')[0]
sequence_name = sequencer.getAttr('sequence_name')
if sequence_name == '' and not pm.general.about(batch=1) \
and not self.batch_mode:
result = pm.promptDialog(
title='Please enter a Sequence Name',
message='Sequence Name:',
button=['OK', 'Cancel'],
defaultButton='OK',
cancelButton='Cancel',
dismissString='Cancel'
)
if result == 'OK':
sequencer.setAttr(
'sequence_name',
pm.promptDialog(query=True, text=True)
)
示例4: make_stretchy
# 需要導入模塊: from pymel import core [as 別名]
# 或者: from pymel.core import getAttr [as 別名]
def make_stretchy(self):
#check joints
"""
"""
self._scaleMD = pm.createNode("multiplyDivide",
n=self.limbName + "_scaleMD")
pm.connectAttr(self.curve.curveInfo.arcLength, self.scaleMD.input1X)
pm.setAttr(self.scaleMD.input2X, self.curve.arclen)
pm.setAttr(self.scaleMD.operation, 2)
for jnt in self.joints.jointChain:
factor = pm.createNode("multiplyDivide", n="factor_" + jnt)
pm.connectAttr(self.scaleMD.outputX, factor.input1X)
pm.setAttr(factor.input2X, (pm.getAttr(jnt.ty)))
pm.connectAttr(factor.outputX, jnt.ty)
示例5: setRotOrder
# 需要導入模塊: from pymel import core [as 別名]
# 或者: from pymel.core import getAttr [as 別名]
def setRotOrder(node, s="XYZ"):
"""Set the rotorder of the object.
Arguments:
node (dagNode): The object to set the rot order on.
s (str): Value of the rotorder.
Possible values : ("XYZ", "XZY", "YXZ", "YZX", "ZXY", "ZYX")
"""
a = ["XYZ", "YZX", "ZXY", "XZY", "YXZ", "ZYX"]
if s not in a:
mgear.log("Invalid Rotorder : " + s, mgear.sev_error)
return False
# Unless Softimage there is no event on the rotorder parameter to
# automatically adapt the angle values
# So let's do it manually using the EulerRotation class
er = datatypes.EulerRotation([pm.getAttr(node + ".rx"),
pm.getAttr(node + ".ry"),
pm.getAttr(node + ".rz")],
unit="degrees")
er.reorderIt(s)
node.setAttr("ro", a.index(s))
node.setAttr("rotate", er.x, er.y, er.z)
示例6: get_ik_fk_controls
# 需要導入模塊: from pymel import core [as 別名]
# 或者: from pymel.core import getAttr [as 別名]
def get_ik_fk_controls(control, blend_attr):
""" Returns the ik and fk controls related to the given control blend attr
Args:
control (str): uihost control to interact with
blend_attr (str): attribute containing control list
Returns:
dict: fk and ik controls list on a dict
"""
ik_fk_controls = {"fk_controls": [],
"ik_controls": []}
controls_attribute = blend_attr.replace("_blend", "_ctl")
try:
controls = cmds.getAttr("{}.{}".format(control, controls_attribute))
except ValueError:
if control == "world_ctl":
_msg = "New type attributes using world as host are not supported"
raise RuntimeError(_msg)
attr = "{}_{}_ctl".format(blend_attr.split("_")[0],
control.split(":")[-1].split("_")[1])
controls = cmds.getAttr("{}.{}".format(control, attr))
# filters the controls
for ctl in controls.split(","):
if len(ctl) == 0:
continue
ctl_type = ctl.split("_")[2]
# filters ik controls
if "ik" in ctl_type or "upv" in ctl_type:
ik_fk_controls["ik_controls"].append(ctl)
# filters fk controls
elif "fk" in ctl_type:
ik_fk_controls["fk_controls"].append(ctl)
return ik_fk_controls
示例7: get_host_from_node
# 需要導入模塊: from pymel import core [as 別名]
# 或者: from pymel.core import getAttr [as 別名]
def get_host_from_node(control):
"""Returns the host control name from the given control
Args:
control (str): Rig control
Returns:
str: Host UI control name
"""
# get host control
namespace = getNamespace(control).split("|")[-1]
host = cmds.getAttr("{}.uiHost".format(control))
return "{}:{}".format(namespace, host)
示例8: export_blend_connections
# 需要導入模塊: from pymel import core [as 別名]
# 或者: from pymel.core import getAttr [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)
示例9: set_range_from_shot
# 需要導入模塊: from pymel import core [as 別名]
# 或者: from pymel.core import getAttr [as 別名]
def set_range_from_shot(shot):
"""sets the playback range from a shot node in the scene
:param shot: Maya Shot
"""
min_frame = shot.getAttr('startFrame')
max_frame = shot.getAttr('endFrame')
pm.playbackOptions(
ast=min_frame,
aet=max_frame,
min=min_frame,
max=max_frame
)
示例10: store_user_options
# 需要導入模塊: from pymel import core [as 別名]
# 或者: from pymel.core import getAttr [as 別名]
def store_user_options(self):
"""stores user options
"""
# query active model panel
active_panel = self.get_active_panel()
# store show/hide display options for active panel
self.reset_user_view_options_storage()
for flag in self.display_flags:
try:
val = pm.modelEditor(active_panel, **{'q': 1, flag: True})
self.user_view_options['display_flags'][flag] = val
except TypeError:
pass
# store hud display options
hud_names = pm.headsUpDisplay(lh=1)
for hud_name in hud_names:
val = pm.headsUpDisplay(hud_name, q=1, vis=1)
self.user_view_options['huds'][hud_name] = val
for camera in pm.ls(type='camera'):
camera_name = camera.name()
per_camera_attr_dict = {}
for attr in self.cam_attribute_names:
per_camera_attr_dict[attr] = camera.getAttr(attr)
self.user_view_options['camera_flags'][camera_name] = \
per_camera_attr_dict
示例11: get_cacheable_nodes
# 需要導入模塊: from pymel import core [as 別名]
# 或者: from pymel.core import getAttr [as 別名]
def get_cacheable_nodes():
"""returns the cacheable nodes from the current scene
:return:
"""
from anima.ui.progress_dialog import ProgressDialogManager
from anima.env.mayaEnv import MayaMainProgressBarWrapper
wrp = MayaMainProgressBarWrapper()
pdm = ProgressDialogManager(dialog=wrp)
pdm.close()
# list all cacheable nodes
cacheable_nodes = []
tr_list = pm.ls(tr=1, type='transform')
caller = pdm.register(len(tr_list), 'Searching for Cacheable Nodes')
for tr in tr_list:
if tr.hasAttr('cacheable') and tr.getAttr('cacheable'):
# check if any of its parents has a cacheable attribute
has_cacheable_parent = False
for parent in tr.getAllParents():
if parent.hasAttr('cacheable'):
has_cacheable_parent = True
break
if not has_cacheable_parent:
# only include direct references
ref = tr.referenceFile()
if ref is not None and ref.parent() is None:
# skip cacheable nodes coming from layout
if ref.version and ref.version.task.type \
and ref.version.task.type.name.lower() == 'layout':
caller.step()
continue
cacheable_nodes.append(tr)
caller.step()
return cacheable_nodes
示例12: unsetup
# 需要導入模塊: from pymel import core [as 別名]
# 或者: from pymel.core import getAttr [as 別名]
def unsetup(self):
"""deletes the barn door setup
"""
if self.light:
try:
pm.delete(
self.light.attr(self.message_storage_attr_name).inputs()
)
except AttributeError:
pass
pm.scriptJob(
k=int(self.light.getAttr(self.custom_data_storage_attr_name))
)
else:
# try to delete the by using the barndoor group
found_light = False
for node in pm.ls(sl=1, type='transform'):
# list all lights and try to find the light that has this group
for light in pm.ls(type=pm.nt.Light):
light_parent = light.getParent()
if light_parent.hasAttr(self.message_storage_attr_name):
if node in light_parent.attr(
self.message_storage_attr_name).inputs():
self.light = light_parent
found_light = True
self.unsetup()
# if the code comes here than this node is not listed in any
# lights, so delete it if it contains the string
# "barndoor_preview_curves" in its name
if not found_light \
and "barndoor_preview_curves" in node.name():
pm.delete(node)
示例13: create_3dequalizer_points
# 需要導入模塊: from pymel import core [as 別名]
# 或者: from pymel.core import getAttr [as 別名]
def create_3dequalizer_points(width, height):
"""creates 3d equalizer points under the selected camera
:param width: The width of the plate
:param height: The height of the plate
"""
width = float(width)
height = float(height)
# get the text file
path = pm.fileDialog()
# parse the file
from anima import utils
man = utils.C3DEqualizerPointManager()
man.read(path)
# get the camera
cam_shape = get_selected_camera()
pm.getAttr("defaultResolution.deviceAspectRatio")
pm.getAttr("defaultResolution.pixelAspect")
frustum_curve = create_frustum_curve(cam_shape)
for point in man.points:
# create a locator
loc = create_camera_space_locator(frustum_curve)
loc.rename('p%s' % point.name)
# animate the locator
for frame in point.data.keys():
pm.currentTime(frame)
frame_data = point.data[frame]
local_x = frame_data[0] / width - 0.5
local_y = frame_data[1] / width - 0.5 * height / width
loc.tx.set(local_x)
loc.ty.set(local_y)
loc.tx.setKey()
loc.ty.setKey()
示例14: _getPosition
# 需要導入模塊: from pymel import core [as 別名]
# 或者: from pymel.core import getAttr [as 別名]
def _getPosition(self, position):
# Checks the type of the Position and Return Position vector
if isinstance(position, pm.dt.Vector):
self._jointPos = position
elif isinstance(position, pm.dt.Point):
self._jointPos = position
elif isinstance(position, pm.nt.Transform):
self._jointPos = pm.getAttr(position.translate)
elif not isinstance(position, pm.dt.Vector):
self._jointPos = pm.dt.Vector(0, 0, 0)
return self._jointPos
# PROPERTIES
示例15: orient_joint
# 需要導入模塊: from pymel import core [as 別名]
# 或者: from pymel.core import getAttr [as 別名]
def orient_joint(self, joint, aimAxis=[1, 0, 0], upAxis=[0, 0, 1],
worldUpType="vector",
worldUpVector=[0, 1, 0]):
#joint should be pm.nt.Joint type
if not isinstance(joint, pm.nt.Joint):
raise TypeError("%s sholud be an instance of pm.nt.Joint Class"
% joint)
jointUnder = self.jointUnder(joint)
if jointUnder is None:
return 0
temporalGroup = DrawNode(Shape.transform, 'temporalGroup')
pm.parent(jointUnder, temporalGroup.drawnNode)
pm.setAttr(joint.jointOrient, (0, 0, 0))
if worldUpType == "object":
aimConst = pm.aimConstraint(jointUnder, joint, aimVector=aimAxis,
upVector=upAxis,
worldUpType=worldUpType,
worldUpObject=worldUpVector)
elif worldUpType == "vector":
aimConst = pm.aimConstraint(jointUnder, joint, aimVector=aimAxis,
upVector=upAxis,
worldUpType=worldUpType,
worldUpVector=worldUpVector)
pm.delete(aimConst)
pm.parent(jointUnder, joint)
pm.setAttr(joint.jointOrient, (pm.getAttr(joint.rotate)))
pm.setAttr((joint.rotate), [0, 0, 0])
pm.delete(temporalGroup.drawnNode)