本文整理汇总了Python中maya.api.OpenMaya.MFnNumericAttribute方法的典型用法代码示例。如果您正苦于以下问题:Python OpenMaya.MFnNumericAttribute方法的具体用法?Python OpenMaya.MFnNumericAttribute怎么用?Python OpenMaya.MFnNumericAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类maya.api.OpenMaya
的用法示例。
在下文中一共展示了OpenMaya.MFnNumericAttribute方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initialize
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MFnNumericAttribute [as 别名]
def initialize():
eAttr = om.MFnEnumAttribute()
CustomLocator.shape = eAttr.create('shape', 's')
eAttr.storable = True
# We can simply add shapes from the dictionary above
for i, shape in enumerate(shapeNames):
eAttr.addField(shape, i)
CustomLocator.addAttribute(CustomLocator.shape)
# Now add the color attribute
nAttr = om.MFnNumericAttribute()
CustomLocator.color = nAttr.createColor('color', 'col')
nAttr.default = (0.5, 0.1, 0.1)
nAttr.storable = True
CustomLocator.addAttribute(CustomLocator.color)
# This class is required to let us control how viewport 2 will render our node
示例2: _addOutputControls
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MFnNumericAttribute [as 别名]
def _addOutputControls(obj, side):
'''
Adds attributes to card for tracking the created controls. Used in conjunction
with OutputControls.
:param PyNode obj: The card to add attributes to
:param str side: Either "Left", "Right" or "Center"
'''
if obj.hasAttr('output' + side):
return
mobj = core.capi.asMObject(obj)
cattr = OpenMaya.MFnCompoundAttribute()
mattr = OpenMaya.MFnMessageAttribute()
nattr = OpenMaya.MFnNumericAttribute()
extraNodes = cattr.create('output' + side, 'out' + side[0])
cattr.array = True
link = mattr.create( 'outputLink' + side, 'ol' + side[0] )
type = nattr.create('out' + side + 'Type', 'o' + side[0] + 't', OpenMaya.MFnNumericData.kInt, 0)
cattr.addChild(link)
cattr.addChild(type)
mobj.addAttribute(extraNodes)
示例3: _addSeqAttr
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MFnNumericAttribute [as 别名]
def _addSeqAttr(obj):
'''
Add `.sequence` attribute to a Script node to enable the custom Sequence api.
Safe to run repeatedly since it only adds required attrs.
'''
if not obj:
return
if not obj.hasAttr('sequence'):
mobj = core.capi.asMObject(obj)
cattr = OpenMaya.MFnCompoundAttribute()
nattr = OpenMaya.MFnNumericAttribute()
tattr = OpenMaya.MFnTypedAttribute()
mattr = OpenMaya.MFnMessageAttribute()
sequence = cattr.create("sequence", 'seq')
cattr.array = True
for long, short, type in _dataSequenceAttr:
if type is OpenMaya.MFnStringData.kString:
newAttr = tattr.create(long, short, type)
elif type is OpenMaya.MFnNumericData.kInt:
newAttr = nattr.create(long, short, type, 0)
elif type == 'message':
newAttr = mattr.create(long, short)
cattr.addChild(newAttr)
mobj.addAttribute(sequence)
if not obj.hasAttr( 'animNotes' ):
obj.addAttr( 'animNotes', dt='string' )
obj.animNotes.set('')
示例4: _attribute_changed
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MFnNumericAttribute [as 别名]
def _attribute_changed(self, attribute_message, plug_dst, plug_scr, *args):
# Message attribute edits
if attribute_message & om2.MNodeMessage.kOtherPlugSet:
input_uuid = om2.MFnDependencyNode(plug_scr.node()).uuid()
if plug_dst.isElement:
plug_dst = plug_dst.array()
if attribute_message & om2.MNodeMessage.kConnectionMade:
om2.MUserEventMessage.postUserEvent(self.attr_user_event,
(self.uuid, plug_dst.partialName(), input_uuid, True))
elif attribute_message & om2.MNodeMessage.kConnectionBroken:
om2.MUserEventMessage.postUserEvent(self.attr_user_event,
(self.uuid, plug_dst.partialName(), input_uuid, False))
# Data attribute edits
elif attribute_message & om2.MNodeMessage.kAttributeSet:
dst_attribute = plug_dst.attribute()
dst_type = dst_attribute.apiType()
if plug_dst.isElement:
attr_name = plug_dst.array().partialName()
index = plug_dst.logicalIndex()
else:
attr_name = plug_dst.partialName()
index = None
if dst_type == om2.MFn.kTypedAttribute:
attr_type = om2.MFnTypedAttribute(dst_attribute).attrType()
if attr_type == om2.MFnData.kString:
om2.MUserEventMessage.postUserEvent(self.attr_user_event,
(self.uuid, attr_name, plug_dst.asString(), index))
elif attr_type == om2.MFnData.kStringArray:
data_object = plug_dst.asMDataHandle().data()
string_array = om2.MFnStringArrayData(data_object)
om2.MUserEventMessage.postUserEvent(self.attr_user_event,
(self.uuid, attr_name, string_array.array(), index))
elif dst_type == om2.MFn.kNumericAttribute:
dstUnitType = om2.MFnNumericAttribute(dst_attribute).numericType()
if dstUnitType == om2.MFnNumericData.kBoolean:
om2.MUserEventMessage.postUserEvent(self.attr_user_event,
(self.uuid, attr_name, plug_dst.asBool(), index))
elif dstUnitType in {om2.MFnNumericData.kFloat, om2.MFnNumericData.kDouble, om2.MFnNumericData.kAddr}:
om2.MUserEventMessage.postUserEvent(self.attr_user_event,
(self.uuid, attr_name, plug_dst.asDouble(), index))
elif dstUnitType in {om2.MFnNumericData.kShort, om2.MFnNumericData.kInt,
om2.MFnNumericData.kLong, om2.MFnNumericData.kByte}:
om2.MUserEventMessage.postUserEvent(self.attr_user_event,
(self.uuid, attr_name, plug_dst.asShort(), index))
示例5: initialize
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MFnNumericAttribute [as 别名]
def initialize():
# We need to create an instance of the Numeric Attribute Function set
# This lets us in turn create numeric attributes
nAttr = om.MFnNumericAttribute()
# Lets start b defining our two input attributes
# We assign this to an attribute on the class
# The arguments in order are:
# long name, short name, attribute type, default value
# A double is like a float but with **double** the precision
MinMaxNode.inputA = nAttr.create('inputA', 'ia', om.MFnNumericData.kDouble, 0.0)
# After each attribute, we can then configure it
# the nAttr object remembers the last object created
nAttr.storable = True # Allows us to store data on this plug
nAttr.keyable = True # Allows us to key it, but also needed to see in Node Editor
# Finally we can do the same for the next attribute
MinMaxNode.inputB = nAttr.create('inputB', 'ib', om.MFnNumericData.kDouble, 0.0)
nAttr.storable = True
nAttr.keyable = True
# Then lets create our output in the same way
MinMaxNode.output = nAttr.create('output', 'out', om.MFnNumericData.kDouble, 0.0)
nAttr.storable = True
nAttr.writable = True
# We should also create our mode selection
# This is a different type called enum
eAttr = om.MFnEnumAttribute()
MinMaxNode.mode = eAttr.create('mode', 'm')
eAttr.addField('min', 0)
eAttr.addField('max', 1)
eAttr.storable = True
# We then add our attributes to the node
# Otherwise they won't show up
MinMaxNode.addAttribute(MinMaxNode.inputA)
MinMaxNode.addAttribute(MinMaxNode.inputB)
MinMaxNode.addAttribute(MinMaxNode.mode)
MinMaxNode.addAttribute(MinMaxNode.output)
# Finally we need to tell our node which attributes affect the output of other attributes
# If we don't do this then our attributes won't update dynamically
# In this case both our inputs affect the output
# Our mode selection will also affect it
MinMaxNode.attributeAffects(MinMaxNode.inputA, MinMaxNode.output)
MinMaxNode.attributeAffects(MinMaxNode.inputB, MinMaxNode.output)
MinMaxNode.attributeAffects(MinMaxNode.mode, MinMaxNode.output)
# Finally all of our computation will happen in this method here
# We get two inputs, the MPlug being requested, and the MDatablock which stores this nodes data
示例6: initialize
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MFnNumericAttribute [as 别名]
def initialize(cls):
fnUnit = api.MFnUnitAttribute()
fnNumeric = api.MFnNumericAttribute()
fnEnum = api.MFnEnumAttribute()
cls.aMethod = fnEnum.create('method', 'met')
fnEnum.addField('Stereographic Projection', 0)
fnEnum.addField('Exponential Map', 1)
cls.addAttribute(cls.aMethod)
cls.aReverseOrder = fnNumeric.create('reverseOrder', 'ror', api.MFnNumericData.kBoolean, False)
cls.addAttribute(cls.aReverseOrder)
cls.aRotateX = fnUnit.create('rotateX', 'rx', api.MFnUnitAttribute.kAngle, 0.)
cls.aRotateY = fnUnit.create('rotateY', 'ry', api.MFnUnitAttribute.kAngle, 0.)
cls.aRotateZ = fnUnit.create('rotateZ', 'rz', api.MFnUnitAttribute.kAngle, 0.)
cls.aRotate = fnNumeric.create('rotate', 'r', cls.aRotateX, cls.aRotateY, cls.aRotateZ)
cls.addAttribute(cls.aRotate)
cls.aRotateOrder = fnEnum.create('rotateOrder', 'ro')
fnEnum.addField('xyz', 0)
fnEnum.addField('yzx', 1)
fnEnum.addField('zxy', 2)
fnEnum.addField('xzy', 3)
fnEnum.addField('yxz', 4)
fnEnum.addField('zyx', 5)
cls.addAttribute(cls.aRotateOrder)
cls.aAxisOrientX = fnUnit.create('axisOrientX', 'aox', api.MFnUnitAttribute.kAngle, 0.)
cls.aAxisOrientY = fnUnit.create('axisOrientY', 'aoy', api.MFnUnitAttribute.kAngle, 0.)
cls.aAxisOrientZ = fnUnit.create('axisOrientZ', 'aoz', api.MFnUnitAttribute.kAngle, 0.)
cls.aAxisOrient = fnNumeric.create('axisOrient', 'ao', cls.aAxisOrientX, cls.aAxisOrientY, cls.aAxisOrientZ)
cls.addAttribute(cls.aAxisOrient)
cls.aOutRoll = fnUnit.create('outRoll', 'orl', api.MFnUnitAttribute.kAngle, 0.)
cls.aOutBendH = fnUnit.create('outBendH', 'obh', api.MFnUnitAttribute.kAngle, 0.)
cls.aOutBendV = fnUnit.create('outBendV', 'obv', api.MFnUnitAttribute.kAngle, 0.)
cls.aOutDecomposedAngle = fnNumeric.create('outDecomposedAngle', 'oda', cls.aOutRoll, cls.aOutBendH, cls.aOutBendV)
fnNumeric.writable = False
fnNumeric.storable = False
cls.addAttribute(cls.aOutDecomposedAngle)
cls.attributeAffects(cls.aMethod, cls.aOutDecomposedAngle)
cls.attributeAffects(cls.aReverseOrder, cls.aOutDecomposedAngle)
cls.attributeAffects(cls.aRotate, cls.aOutDecomposedAngle)
cls.attributeAffects(cls.aRotateOrder, cls.aOutDecomposedAngle)
cls.attributeAffects(cls.aAxisOrient, cls.aOutDecomposedAngle)