def initialize():
        nAttr = om.MFnMatrixAttribute()
        distanceTerrainNode.terrainMatrix = nAttr.create(
            'terrainMatrix', 'terrainMtrx')
        nAttr.storable = True

        nAttr = om.MFnTypedAttribute()
        distanceTerrainNode.terrain = nAttr.create('terrain', 'terrain',
                                                   om.MFnData.kMesh)
        nAttr.storable = True
        nAttr.writable = True

        nAttr = om.MFnNumericAttribute()
        distanceTerrainNode.jointPos = nAttr.create('jointPosition',
                                                    'jointPos',
                                                    om.MFnNumericData.k3Float,
                                                    0)
        nAttr.storable = True
        nAttr.writable = True
        nAttr = om.MFnNumericAttribute()
        distanceTerrainNode.distance = nAttr.create('distance', 'distance',
                                                    om.MFnNumericData.kFloat,
                                                    0)

        distanceTerrainNode.addAttribute(distanceTerrainNode.terrainMatrix)
        distanceTerrainNode.addAttribute(distanceTerrainNode.terrain)
        distanceTerrainNode.addAttribute(distanceTerrainNode.jointPos)
        distanceTerrainNode.addAttribute(distanceTerrainNode.distance)
        distanceTerrainNode.attributeAffects(distanceTerrainNode.terrainMatrix,
                                             distanceTerrainNode.distance)
        distanceTerrainNode.attributeAffects(distanceTerrainNode.terrain,
                                             distanceTerrainNode.distance)
        distanceTerrainNode.attributeAffects(distanceTerrainNode.jointPos,
                                             distanceTerrainNode.distance)
Exemple #2
0
    def initializer(cls):
        # input
        fn_numeric_attr = om.MFnNumericAttribute()
        cls.input_attr = fn_numeric_attr.create('input', 'in',
                                                om.MFnNumericData.kFloat, 1.0)
        fn_numeric_attr.readable = True
        fn_numeric_attr.writable = True
        fn_numeric_attr.storable = True
        fn_numeric_attr.hidden = False
        cls.addAttribute(cls.input_attr)

        fn_numeric_attr = om.MFnNumericAttribute()
        cls.mod_attr = fn_numeric_attr.create('mod', 'm',
                                              om.MFnNumericData.kFloat, 1.0)
        fn_numeric_attr.readable = True
        fn_numeric_attr.writable = True
        fn_numeric_attr.storable = True
        fn_numeric_attr.hidden = False
        cls.addAttribute(cls.mod_attr)

        # output
        cls.output_attr = fn_numeric_attr.create('output', 'out',
                                                 om.MFnNumericData.kFloat)
        fn_numeric_attr.storable = False
        fn_numeric_attr.writable = False
        fn_numeric_attr.readable = True
        fn_numeric_attr.hidden = False
        cls.addAttribute(cls.output_attr)

        # Affects
        cls.attributeAffects(cls.input_attr, cls.output_attr)
        cls.attributeAffects(cls.mod_attr, cls.output_attr)
Exemple #3
0
    def initialize():
        """Initialise node - execute on plugin initialise."""

        # Add in_mesh attr
        _attr = om.MFnTypedAttribute()
        MeshXRayer.in_mesh = _attr.create('in_mesh', 'in_mesh',
                                          om.MFnNumericData.kMesh)
        _attr.writable = True
        _attr.connectable = True
        _attr.readable = False
        MeshXRayer.addAttribute(MeshXRayer.in_mesh)

        # Add color attr
        _attr = om.MFnNumericAttribute()
        MeshXRayer.color = _attr.createColor("color", "color")
        _attr.keyable = True
        _attr.connectable = True
        _attr.writable = True
        _attr.readable = True
        _attr.usedAsColor = True
        MeshXRayer.addAttribute(MeshXRayer.color)

        # Add hide angle attr
        _attr = om.MFnNumericAttribute()
        MeshXRayer.hide_angle = _attr.create("hide_angle", "hide_angle",
                                             om.MFnNumericData.kFloat)
        _attr.keyable = True
        _attr.connectable = True
        _attr.writable = True
        _attr.readable = True
        _attr.setMin(0)
        _attr.setMax(180)
        _attr.default = 90
        MeshXRayer.addAttribute(MeshXRayer.hide_angle)

        # Add show control attr
        _attr = om.MFnNumericAttribute()
        MeshXRayer.draw_control = _attr.create("draw_control", "draw_control",
                                               om.MFnNumericData.kBoolean)
        _attr.keyable = True
        _attr.connectable = True
        _attr.writable = True
        _attr.readable = True
        _attr.default = True
        MeshXRayer.addAttribute(MeshXRayer.draw_control)

        # Add show control attr
        _attr = om.MFnNumericAttribute()
        MeshXRayer.draw_mesh = _attr.create("draw_mesh", "draw_mesh",
                                            om.MFnNumericData.kBoolean)
        _attr.keyable = True
        _attr.connectable = True
        _attr.writable = True
        _attr.readable = True
        _attr.default = True
        MeshXRayer.addAttribute(MeshXRayer.draw_mesh)
Exemple #4
0
def create_skeleton_compound(classtype, name):
    mComp = OpenMaya.MFnCompoundAttribute()
    compound = mComp.create(name, name)
    setattr(classtype, name, compound)
    mComp.array = True
    mComp.storable = True
    mComp.writable = True

    mAttr = OpenMaya.MFnMatrixAttribute()
    srcMatrix = mAttr.create(name + "SrcMatrix", name + "SrcMatrix")
    setattr(classtype, name + "SrcMatrix", srcMatrix)
    mAttr.array = False
    mAttr.storable = True
    mAttr.writable = True

    nAttr = OpenMaya.MFnNumericAttribute()
    boneParent = nAttr.create(name + "BoneParent", name + "BoneParent",
                              OpenMaya.MFnNumericData.kInt, -1)
    setattr(classtype, name + "BoneParent", boneParent)
    nAttr.array = False
    nAttr.storable = True
    nAttr.writable = True

    nAttr = OpenMaya.MFnNumericAttribute()
    translateScale = nAttr.create(name + "TranslateScale",
                                  name + "TranslateScale",
                                  OpenMaya.MFnNumericData.kFloat, 0)
    setattr(classtype, name + "TranslateScale", translateScale)
    nAttr.array = False
    nAttr.storable = True
    nAttr.writable = True

    nAttr = OpenMaya.MFnNumericAttribute()
    targetTranslate = nAttr.create(name + "TargetTranslate",
                                   name + "TargetTranslate",
                                   OpenMaya.MFnNumericData.k3Float)
    setattr(classtype, name + "TargetTranslate", targetTranslate)
    nAttr.array = False
    nAttr.storable = True
    nAttr.writable = True
    nAttr.keyable = True

    classtype.addAttribute(srcMatrix)
    classtype.addAttribute(boneParent)
    classtype.addAttribute(translateScale)
    classtype.addAttribute(targetTranslate)

    mComp.addChild(srcMatrix)
    mComp.addChild(boneParent)
    mComp.addChild(translateScale)
    mComp.addChild(targetTranslate)

    classtype.addAttribute(compound)

    return compound
    def initialize():
        nAttrAllPoseInfoList = om.MFnCompoundAttribute()
        SampleValueBlender.inAllSampleInfoList = nAttrAllPoseInfoList.create(
            'allSampleInfoList', 'pil')
        nAttrAllPoseInfoList.keyable = True
        nAttrAllPoseInfoList.array = True
        nAttrAllPoseInfoList.storable = True
        nAttrAllPoseInfoList.indexMatters = False

        nAttrPoseName = om.MFnTypedAttribute()
        SampleValueBlender.inPoseName = nAttrPoseName.create(
            'poseName', 'pn', om.MFnData.kString)
        nAttrPoseName.keyable = True

        nAttrSampleValue = om.MFnNumericAttribute()
        SampleValueBlender.inSampleValue = nAttrSampleValue.create(
            'sampleValue', 'sv', om.MFnNumericData.kFloat, 0.0)
        nAttrSampleValue.keyable = True
        nAttrSampleValue.array = True
        nAttrSampleValue.storable = True

        nAttrValueMode = om.MFnEnumAttribute()
        SampleValueBlender.inSampleValueMode = nAttrValueMode.create(
            'sampleValueMode', 'm', 0)
        nAttrValueMode.addField("normal", 0)
        nAttrValueMode.addField("multiply", 1)

        nAttrAllPoseInfoList.addChild(SampleValueBlender.inPoseName)
        nAttrAllPoseInfoList.addChild(SampleValueBlender.inSampleValue)
        nAttrAllPoseInfoList.addChild(SampleValueBlender.inSampleValueMode)

        nAttrNum1 = om.MFnNumericAttribute()
        SampleValueBlender.inOverridingIntensity = nAttrNum1.create(
            "overridingIntensity", "oi", om.MFnNumericData.kFloat, 0.0)
        nAttrNum1.keyable = False

        nAttrNum2 = om.MFnNumericAttribute()
        SampleValueBlender.inOverridingWeight = nAttrNum2.create(
            "overridingWeight", "ow", om.MFnNumericData.kFloat, 1.0)
        nAttrNum2.keyable = False

        nAttrOut = om.MFnNumericAttribute()
        SampleValueBlender.outWeightList = nAttrOut.create(
            'outWeightList', 'owl', om.MFnNumericData.kFloat, 0.0)
        nAttrOut.array = True
        nAttrOut.storable = True
        nAttrOut.usesArrayDataBuilder = True

        # add the attributes
        om.MPxNode.addAttribute(SampleValueBlender.inAllSampleInfoList)
        om.MPxNode.addAttribute(SampleValueBlender.outWeightList)

        om.MPxNode.attributeAffects(SampleValueBlender.inAllSampleInfoList,
                                    SampleValueBlender.outWeightList)
Exemple #6
0
def nodeInitializer():

    numAttr = om.MFnNumericAttribute()
    ligamentNode.output = numAttr.createPoint('output', 'output')
    numAttr.keyable = False
    #numAttr.hidden = True
    numAttr.array = True
    numAttr.storable = True
    numAttr.readable = True
    numAttr.writable = True
    om.MPxNode.addAttribute(ligamentNode.output)

    enumAttr = om.MFnEnumAttribute()
    ligamentNode.initilize = enumAttr.create("initialize", "init")
    enumAttr.addField("off", 0)
    enumAttr.addField("initialize", 1)
    enumAttr.addField("initialized", 2)
    enumAttr.keyable = True
    enumAttr.storable = True
    enumAttr.readable = True
    om.MPxNode.addAttribute(ligamentNode.initilize)
    ligamentNode.attributeAffects(ligamentNode.initilize, ligamentNode.output)

    typedAttr = om.MFnTypedAttribute()
    ligamentNode.inCurve = typedAttr.create("inCurve", "inCurve",
                                            om.MFnData.kNurbsCurve)
    typedAttr.storable = True
    typedAttr.readable = True
    om.MPxNode.addAttribute(ligamentNode.inCurve)
    ligamentNode.attributeAffects(ligamentNode.inCurve, ligamentNode.output)

    typedAttr = om.MFnTypedAttribute()
    ligamentNode.refCurve = typedAttr.create("refCurve", "refCurve",
                                             om.MFnData.kNurbsCurve)
    typedAttr.storable = True
    typedAttr.readable = True
    om.MPxNode.addAttribute(ligamentNode.refCurve)
    ligamentNode.attributeAffects(ligamentNode.refCurve, ligamentNode.output)

    nAttr = om.MFnNumericAttribute()
    ligamentNode.stiffness = nAttr.create("stiffness", "stiff",
                                          om.MFnNumericData.kFloat, 1.0)
    nAttr.setMin(0)
    nAttr.keyable = False
    nAttr.array = True
    nAttr.storable = True
    nAttr.readable = True
    nAttr.writable = True
    om.MPxNode.addAttribute(ligamentNode.stiffness)
    ligamentNode.attributeAffects(ligamentNode.stiffness, ligamentNode.output)
Exemple #7
0
    def _create_max_comp_attr(cls):
        """Create attr.
        """
        comp_attr = OpenMaya.MFnCompoundAttribute()
        cls.barMaxComp = comp_attr.create("barMaxComp", "maxc")

        # has max
        has_max_attr = OpenMaya.MFnNumericAttribute()

        cls.barHasMax = has_max_attr.create("barHasMax", "hMax",
                                            OpenMaya.MFnNumericData.kBoolean,
                                            ValueBarLocatorData.barHasMax)

        # max visibility
        max_vis_attr = OpenMaya.MFnNumericAttribute()

        cls.barMaxVisibility = max_vis_attr.create(
            "barMaxVisibility", "maxV", OpenMaya.MFnNumericData.kBoolean,
            ValueBarLocatorData.barMaxVisibility)

        # max value
        max_val_attr = OpenMaya.MFnNumericAttribute()

        cls.barMaxValue = max_val_attr.create("barMaxValue", "max",
                                              OpenMaya.MFnNumericData.kFloat,
                                              ValueBarLocatorData.barMaxValue)

        # max color
        max_col_attr = OpenMaya.MFnNumericAttribute()

        cls.barMaxColor = max_col_attr.create(
            "barMaxColor",
            "maxC",
            OpenMaya.MFnNumericData.k3Double,
        )

        max_col_attr.usedAsColor = True
        max_col_attr.default = ValueBarLocatorData.barMaxColor

        # create attr hierarchy
        comp_attr.addChild(cls.barHasMax)
        comp_attr.addChild(cls.barMaxVisibility)
        comp_attr.addChild(cls.barMaxValue)
        comp_attr.addChild(cls.barMaxColor)

        # add comp attr
        res = cls.addAttribute(cls.barMaxComp)

        return res
Exemple #8
0
    def _create_min_comp_attr(cls):
        """Create attr.
        """
        comp_attr = OpenMaya.MFnCompoundAttribute()
        cls.barMinComp = comp_attr.create("barMinComp", "minc")

        # has min
        has_min_attr = OpenMaya.MFnNumericAttribute()

        cls.barHasMin = has_min_attr.create("barHasMin", "hMin",
                                            OpenMaya.MFnNumericData.kBoolean,
                                            ValueBarLocatorData.barHasMin)

        # min visibility
        min_vis_attr = OpenMaya.MFnNumericAttribute()

        cls.barMinVisibility = min_vis_attr.create(
            "barMinVisibility", "minV", OpenMaya.MFnNumericData.kBoolean,
            ValueBarLocatorData.barMinVisibility)

        # min value
        min_val_attr = OpenMaya.MFnNumericAttribute()

        cls.barMinValue = min_val_attr.create("barMinValue", "min",
                                              OpenMaya.MFnNumericData.kFloat,
                                              ValueBarLocatorData.barMinValue)

        # min color
        min_col_attr = OpenMaya.MFnNumericAttribute()

        cls.barMinColor = min_col_attr.create(
            "barMinColor",
            "minC",
            OpenMaya.MFnNumericData.k3Double,
        )

        min_col_attr.usedAsColor = True
        min_col_attr.default = ValueBarLocatorData.barMinColor

        # create attr hierarchy
        comp_attr.addChild(cls.barHasMin)
        comp_attr.addChild(cls.barMinVisibility)
        comp_attr.addChild(cls.barMinValue)
        comp_attr.addChild(cls.barMinColor)

        # add comp attr
        res = cls.addAttribute(cls.barMinComp)

        return res
Exemple #9
0
    def initialize():
        # output expmap
        cAttr = OpenMaya.MFnCompoundAttribute()
        mlEulerToExpmap.expmap = cAttr.create(expmapName[0], expmapName[1])
        cAttr.setNiceNameOverride(expmapName[2])
        mlEulerToExpmap.expmapElement = []
        for i in xrange(0, 3):
            nAttr = OpenMaya.MFnNumericAttribute()
            mlEulerToExpmap.expmapElement = mlEulerToExpmap.expmapElement + \
                [nAttr.create(expmapElementName[i][0],
                                expmapElementName[i][1],
                                OpenMaya.MFnNumericData.kDouble,
                                0.0)]
            nAttr.setNiceNameOverride(expmapElementName[i][2])
            nAttr.keyable = False
            nAttr.writable = False
            cAttr.addChild(mlEulerToExpmap.expmapElement[i])
        mlEulerToExpmap.addAttribute(mlEulerToExpmap.expmap)

        # input Euler angles
        cAttr = OpenMaya.MFnCompoundAttribute()
        mlEulerToExpmap.rotate = cAttr.create(rotateName[0], rotateName[1])
        cAttr.setNiceNameOverride(rotateName[2])
        mlEulerToExpmap.eulerAngles = []
        for i in xrange(0, 3):
            uAttr = OpenMaya.MFnUnitAttribute()
            mlEulerToExpmap.eulerAngles = mlEulerToExpmap.eulerAngles + \
                [uAttr.create(eulerAngleName[i][0],
                                eulerAngleName[i][1],
                                OpenMaya.MFnUnitAttribute.kAngle,
                                0.0)]
            uAttr.setNiceNameOverride(eulerAngleName[i][2])
            uAttr.keyable = True
            uAttr.readable = False
            cAttr.addChild(mlEulerToExpmap.eulerAngles[i])
        mlEulerToExpmap.addAttribute(mlEulerToExpmap.rotate)
        mlEulerToExpmap.attributeAffects(mlEulerToExpmap.rotate,
                                         mlEulerToExpmap.expmap)

        # input rotation order
        nAttr = OpenMaya.MFnNumericAttribute()
        mlEulerToExpmap.rotateOrder = nAttr.create(
            rotateOrderName[0], rotateOrderName[1],
            OpenMaya.MFnNumericData.kInt, 0)
        nAttr.setNiceNameOverride(rotateOrderName[2])
        nAttr.readable = False
        mlEulerToExpmap.addAttribute(mlEulerToExpmap.rotateOrder)
        mlEulerToExpmap.attributeAffects(mlEulerToExpmap.rotateOrder,
                                         mlEulerToExpmap.expmap)
Exemple #10
0
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)
Exemple #11
0
def plug_get_impl(mplug):
    # type: (_om2.MPlug) -> Any
    mobj = mplug.attribute()
    api_type = mobj.apiType()

    # array
    if mplug.isArray:
        return [
            plug_get_impl(mplug.elementByLogicalIndex(i))
            for i in range(mplug.numElements())
        ]

    # compound
    if mplug.isCompound:
        return tuple(
            plug_get_impl(mplug.child(i)) for i in range(mplug.numChildren()))

    try:
        # typed
        if api_type == _om2.MFn.kTypedAttribute:
            attr_type = _om2.MFnTypedAttribute(mobj).attrType()
            return _typed_attr_table[attr_type](mplug)

        # numeric
        if api_type == _om2.MFn.kNumericAttribute:
            numeric_type = _om2.MFnNumericAttribute(mobj).numericType()
            return _numeric_attr_table[numeric_type](mplug)

        return _api_type_table[api_type](mplug)

    except KeyError:
        print('not-supported plug data: {}'.format(mplug))
        return _cmds.getAttr(mplug.name())
    def initialize():
        nAttr = om.MFnNumericAttribute()

        BezierPoints.aInput1 = nAttr.create('BPoint1', 'bp1', om.MFnNumericData.k3Double)
        BezierPoints.aInput2 = nAttr.create('BPoint2', 'bp2', om.MFnNumericData.k3Double)
        BezierPoints.aInput3 = nAttr.create('BPoint3', 'bp3', om.MFnNumericData.k3Double)

        BezierPoints.aPercent = nAttr.create('percent', 'per', om.MFnNumericData.kFloat, 0.0)
        nAttr.writable = True
        nAttr.keyable = True
        nAttr.setSoftMin(0.0)
        nAttr.setSoftMax(1.0)

        BezierPoints.aOutput = nAttr.create("outResult", "out", om.MFnNumericData.k3Double)
        nAttr.writable = True

        BezierPoints.addAttribute(BezierPoints.aInput1)
        BezierPoints.addAttribute(BezierPoints.aInput2)
        BezierPoints.addAttribute(BezierPoints.aInput3)

        BezierPoints.addAttribute(BezierPoints.aPercent)
        BezierPoints.addAttribute(BezierPoints.aOutput)


        BezierPoints.attributeAffects(BezierPoints.aPercent, BezierPoints.aOutput)
        BezierPoints.attributeAffects(BezierPoints.aInput1, BezierPoints.aOutput)
        BezierPoints.attributeAffects(BezierPoints.aInput2, BezierPoints.aOutput)
        BezierPoints.attributeAffects(BezierPoints.aInput3, BezierPoints.aOutput)
Exemple #13
0
    def __init__(self):
        super(RollingNode, self).__init__()

        numeric_attr = om.MFnNumericAttribute()

        cls.distance_obj = numeric_attr.create("distance", "dist",
                                               om.MFnNumericData.kDouble, 0.0)
        numeric_attr.readable = False
        numeric_attr.keyable = True

        cls.radius_obj = numeric_attr.create("radius", "rad",
                                             om.MFnNumericData.kDouble, 0.0)
        numeric_attr.readable = False
        numeric_attr.keyable = True

        unit_attr = om.MFnUnitAttribute()

        cls.rotation_obj = unit_attr.create("rotation", "rot",
                                            om.MFnUnitAttribute.kAngle, 0.0)

        cls.addAttribute(cls.distance_obj)
        cls.addAttribute(cls.radius_obj)
        cls.addAttribute(cls.rotation_obj)

        cls.attributeAffects(cls.distance_obj, cls.rotation_obj)
        cls.attributeAffects(cls.radius_obj, cls.rotation_obj)
    def initializer(cls):
        # input
        fn_numeric_attr = om.MFnNumericAttribute()
        cls.base_attr = fn_numeric_attr.create('base', 'b', om.MFnNumericData.kFloat, 1.0)
        fn_numeric_attr.writable = True
        fn_numeric_attr.storable = True
        fn_numeric_attr.hidden = False
        cls.addAttribute(cls.base_attr)

        cls.exponent_attr = fn_numeric_attr.create('exponent', 'exp', om.MFnNumericData.kFloat, 1.0)
        fn_numeric_attr.writable = True
        fn_numeric_attr.storable = True
        fn_numeric_attr.hidden = False
        cls.addAttribute(cls.exponent_attr)

        # output
        cls.output_attr = fn_numeric_attr.create('output', 'out', om.MFnNumericData.kFloat)
        fn_numeric_attr.storable = False
        fn_numeric_attr.writable = False
        fn_numeric_attr.readable = True
        fn_numeric_attr.hidden = False
        cls.addAttribute(cls.output_attr)

        # Affects
        cls.attributeAffects(cls.base_attr, cls.output_attr)
        cls.attributeAffects(cls.exponent_attr, cls.output_attr)
Exemple #15
0
    def initialize():
        numericAttr = om.MFnNumericAttribute()
        compoundAttr = om.MFnCompoundAttribute()
        typedAttr = om.MFnTypedAttribute()

        # output
        prMotionPath.outTranslate = numericAttr.createPoint('outTranslate', 'outTranslate')
        numericAttr.writable = False

        prMotionPath.output = compoundAttr.create('output', 'output')
        compoundAttr.addChild(prMotionPath.outTranslate)
        compoundAttr.array = True
        compoundAttr.usesArrayDataBuilder = True
        prMotionPath.addAttribute(prMotionPath.output)

        # input
        prMotionPath.inputCurve = typedAttr.create('inputCurve', 'inputCurve',
                                                   om.MFnNurbsCurveData.kNurbsCurve)
        prMotionPath.addAttribute(prMotionPath.inputCurve)
        prMotionPath.attributeAffects(prMotionPath.inputCurve, prMotionPath.outTranslate)

        prMotionPath.fractionMode = numericAttr.create('fractionMode', 'fractionMode',
                                                       om.MFnNumericData.kBoolean, True)
        numericAttr.keyable = True
        prMotionPath.addAttribute(prMotionPath.fractionMode)
        prMotionPath.attributeAffects(prMotionPath.fractionMode, prMotionPath.outTranslate)

        prMotionPath.uValue = numericAttr.create('uValue', 'uValue', om.MFnNumericData.kFloat, 0.0)
        numericAttr.keyable = True
        numericAttr.array = True
        numericAttr.usesArrayDataBuilder = True
        prMotionPath.addAttribute(prMotionPath.uValue)
        prMotionPath.attributeAffects(prMotionPath.uValue, prMotionPath.outTranslate)
Exemple #16
0
    def type(self):
        # Lazy evaluate
        if self._type is None:
            plug = self.plug
            attr = plug.attribute()

            if attr.hasFn(OpenMaya.MFn.kMessageAttribute):
                self._type = Plug.kMessage

            elif plug.isArray:
                self._type = Plug.kArray

            elif attr.hasFn(OpenMaya.MFn.kCompoundAttribute):
                self._type = Plug.kColor if OpenMaya.MFnAttribute(attr).usedAsColor else \
                             [ child.type for child in self._children() ]

            elif attr.hasFn(OpenMaya.MFn.kNumericAttribute):
                self._type = Plug._numericToPlugTypes.get(
                    OpenMaya.MFnNumericAttribute(attr).numericType(),
                    Plug.kInvalid)

            elif attr.hasFn(OpenMaya.MFn.kTypedAttribute):
                dataType = OpenMaya.MFnTypedAttribute(attr).attrType()
                if dataType == OpenMaya.MFnData.kString:
                    self._type = Plug.kString
                else:
                    self._type = Plug.kInvalid

            elif attr.hasFn(OpenMaya.MFn.kEnumAttribute):
                self._type = Plug.kEnum

            elif attr.hasFn(OpenMaya.MFn.kUnitAttribute):
                self._type = Plug._unitToPlugTypes.get(
                    OpenMaya.MFnUnitAttribute(attr).unitType(), Plug.kInvalid)

            elif attr.hasFn(OpenMaya.MFn.kGenericAttribute):
                handle = plug.asMDataHandle()
                isGeneric, isGenericNumeric, isGenericNull = handle.isGeneric()
                if isGeneric and isGenericNumeric:
                    # It's a generic simple attribute.
                    # According to docs there is no method to check the type
                    # of a generic simple attribute:
                    # http://help.autodesk.com/view/MAYAUL/2016/ENU/?guid=__cpp_ref_class_m_data_handle_html
                    # So always return as double here
                    self._type = Plug.kDouble
                elif not isGenericNull:
                    obj = handle.data()
                    if obj.hasFn(OpenMaya.MFn.kStringData):
                        self._type = Plug.kString
                    else:
                        # if handle.data() didn't raise an exception,
                        # plug can be read as MObject
                        self._type = Plug.kObject
                else:
                    raise RuntimeError(kUnknownType % self.name)

            else:
                raise RuntimeError(kUnsupportedAttribute % self.name)

        return self._type
Exemple #17
0
    def initialize(cls):
        unitFn = om.MFnUnitAttribute()
        VectorHelperNode.radius = unitFn.create("radius", "r",
                                                om.MFnUnitAttribute.kDistance)
        unitFn.channelBox = True
        unitFn.default = om.MDistance(0.1)
        unitFn.setMin(om.MDistance(0))
        om.MPxNode.addAttribute(VectorHelperNode.radius)

        numericFn = om.MFnNumericAttribute()

        VectorHelperNode.origin = numericFn.createPoint("origin", "o")
        numericFn.channelBox = True
        om.MPxNode.addAttribute(VectorHelperNode.origin)

        VectorHelperNode.target = numericFn.createPoint("target", "t")
        numericFn.channelBox = True
        om.MPxNode.addAttribute(VectorHelperNode.target)

        VectorHelperNode.colorR = numericFn.create("colorR", "cr",
                                                   om.MFnNumericData.kFloat, 1)
        numericFn.channelBox = True
        om.MPxNode.addAttribute(VectorHelperNode.colorR)

        VectorHelperNode.colorG = numericFn.create("colorG", "cg",
                                                   om.MFnNumericData.kFloat, 0)
        numericFn.channelBox = True
        om.MPxNode.addAttribute(VectorHelperNode.colorG)

        VectorHelperNode.colorB = numericFn.create("colorB", "cb",
                                                   om.MFnNumericData.kFloat, 0)
        numericFn.channelBox = True
        om.MPxNode.addAttribute(VectorHelperNode.colorB)
Exemple #18
0
    def initialize(cls):
        numFn = om.MFnNumericAttribute()

        cls.inColor = numFn.createColor('inColor', 'ic')
        numFn.keyable = True
        numFn.storable = True
        numFn.readable = True
        numFn.writable = True
        numFn.default = (0, 0, 0)

        cls.resolution = numFn.create('resolution', 'res', om.MFnNumericData.kInt)
        numFn.keyable = True
        numFn.storable = True
        numFn.readable = True
        numFn.writable = True
        numFn.setMin(32)
        numFn.setMax(1024)
        numFn.default = 32

        cls.sentinel = numFn.create('sentinel', 'sntl', om.MFnNumericData.kBoolean)
        numFn.hidden = True
        numFn.default = True

        om.MPxNode.addAttribute(cls.inColor)
        om.MPxNode.addAttribute(cls.resolution)
        om.MPxNode.addAttribute(cls.sentinel)

        om.MPxNode.attributeAffects(cls.inColor, cls.sentinel)
        om.MPxNode.attributeAffects(cls.resolution, cls.sentinel)
Exemple #19
0
 def initialize():
     nAttr = OpenMaya.MFnNumericAttribute()
     TemplateLocator.inputTime = nAttr.create("rainbowColors", "rc", OpenMaya.MFnNumericData.kTime)
     nAttr.setWritable(1)
     nAttr.setStorable(1)
     nAttr.setKeyable(1)
     TemplateLocator.addAttribute(TemplateLocator.input1VecAttr)
Exemple #20
0
def get_attribute_default_value(plug):
    """ Get the default value for the given plug
    
    :param plug: Plug for the attribute
    :type plug: om.MPlug
    :return: Default value of the attribute found on the plug
    :rtype: float or None
    """
    attr = plug.attribute()
    api = attr.apiType()

    if api == om.MFn.kNumericAttribute:
        typeFn = om.MFnNumericAttribute(attr)
        return float(typeFn.default)

    if api in [om.MFn.kDoubleLinearAttribute, om.MFn.kFloatLinearAttribute]:
        typeFn = om.MFnUnitAttribute(attr)
        default = om.MDistance(typeFn.default)
        return default.value

    if api in [om.MFn.kDoubleAngleAttribute, om.MFn.kFloatAngleAttribute]:
        typeFn = om.MFnUnitAttribute(attr)
        default = om.MAngle(typeFn.default)
        return default.value

    return None
Exemple #21
0
    def initialize():
        typedAttr = om.MFnTypedAttribute()
        matrixAttr = om.MFnMatrixAttribute()
        numericAttr = om.MFnNumericAttribute()

        # OUTPUT
        prCurveFrame.outputMatrix = matrixAttr.create("outputMatrix", "outputMatrix", matrixAttr.kDouble)
        matrixAttr.array = True
        matrixAttr.usesArrayDataBuilder = True
        matrixAttr.readable = True
        matrixAttr.writable = False
        prCurveFrame.addAttribute(prCurveFrame.outputMatrix)

        # INPUT
        prCurveFrame.inputCurve = typedAttr.create('inputCurve', 'inputCurve', om.MFnNurbsCurveData.kNurbsCurve)
        prCurveFrame.addAttribute(prCurveFrame.inputCurve)
        prCurveFrame.attributeAffects(prCurveFrame.inputCurve, prCurveFrame.outputMatrix)

        prCurveFrame.worldUpMatrix = matrixAttr.create("worldUpMatrix", "worldUpMatrix", matrixAttr.kDouble)
        prCurveFrame.addAttribute(prCurveFrame.worldUpMatrix)
        prCurveFrame.attributeAffects(prCurveFrame.worldUpMatrix, prCurveFrame.outputMatrix)

        prCurveFrame.points = numericAttr.create("points", "points", om.MFnNumericData.kInt, 5)
        numericAttr.keyable = True
        prCurveFrame.addAttribute(prCurveFrame.points)
        prCurveFrame.attributeAffects(prCurveFrame.points, prCurveFrame.outputMatrix)
Exemple #22
0
    def initialize(cls):
        numeric_attr = om.MFnNumericAttribute()
        unit_attr = om.MFnUnitAttribute()

        cls.aTime = unit_attr.create('time', 'time', om.MFnUnitAttribute.kTime,
                                     0.0)
        unit_attr.keyable = True
        unit_attr.readable = False

        cls.aPos = numeric_attr.createPoint("translate", "tran")
        numeric_attr.writable = False

        cls.aOutput = numeric_attr.createPoint('output', 'output')
        numeric_attr.array = True
        numeric_attr.writable = True
        numeric_attr.usesArrayDataBuilder = True
        numeric_attr.connectable = True

        cls.aLeadBoid_Index = numeric_attr.create("reset", "reset",
                                                  om.MFnNumericData.kInt, 0)

        cls.aGoal = numeric_attr.createPoint('goal', 'goal')
        numeric_attr.keyable = True

        cls.addAttribute(cls.aPos)
        cls.addAttribute(cls.aTime)
        cls.addAttribute(cls.aOutput)
        cls.addAttribute(cls.aLeadBoid_Index)
        cls.addAttribute(cls.aGoal)

        cls.attributeAffects(cls.aTime, cls.aOutput)
Exemple #23
0
    def initialize(cls):
        numeric_attr = om.MFnNumericAttribute()

        # create distance attr for node (hide the output and make it show in the channel box)
        cls.distance_obj = numeric_attr.create("distance", "dist",
                                               om.MFnNumericData.kDouble, 0.0)
        numeric_attr.readable = False
        numeric_attr.keyable = True

        # create radius attr for node (hide the output and make it show in the channel box)
        cls.radius_obj = numeric_attr.create("radius", "rad",
                                             om.MFnNumericData.kDouble, 0.0)
        numeric_attr.readable = False
        numeric_attr.keyable = True

        unit_attr = om.MFnUnitAttribute()

        # create the rotation atter as type(MAngle)
        cls.rotation_obj = unit_attr.create("rotation", "rot",
                                            om.MFnUnitAttribute.kAngle, 0.0)

        # add the attrs to the node
        cls.addAttribute(cls.distance_obj)
        cls.addAttribute(cls.radius_obj)
        cls.addAttribute(cls.rotation_obj)

        # Connect input and output attr relationships
        cls.attributeAffects(cls.distance_obj, cls.rotation_obj)
        cls.attributeAffects(cls.radius_obj, cls.rotation_obj)
Exemple #24
0
    def initialize():
        numericAttr = om.MFnNumericAttribute()

        # output
        prRange.output = numericAttr.create('output', 'output',
                                            om.MFnNumericData.kFloat)
        numericAttr.array = True
        numericAttr.usesArrayDataBuilder = True
        numericAttr.writable = False
        prRange.addAttribute(prRange.output)

        # input
        prRange.inputMin = numericAttr.create('inputMin', 'inputMin',
                                              om.MFnNumericData.kFloat, 0.0)
        numericAttr.keyable = True
        prRange.addAttribute(prRange.inputMin)
        prRange.attributeAffects(prRange.inputMin, prRange.output)

        prRange.inputMax = numericAttr.create('inputMax', 'inputMax',
                                              om.MFnNumericData.kFloat, 1.0)
        numericAttr.keyable = True
        prRange.addAttribute(prRange.inputMax)
        prRange.attributeAffects(prRange.inputMax, prRange.output)

        prRange.inputSampleCount = numericAttr.create('inputSampleCount',
                                                      'inputSampleCount',
                                                      om.MFnNumericData.kInt)
        numericAttr.keyable = True
        numericAttr.setMin(0)
        numericAttr.setSoftMax(20)
        prRange.addAttribute(prRange.inputSampleCount)
        prRange.attributeAffects(prRange.inputSampleCount, prRange.output)
Exemple #25
0
def _getattr_impl(mplug):
    mobj = mplug.attribute()
    api_type = mobj.apiType()

    # array
    if mplug.isArray:
        return [
            _getattr_impl(mplug.elementByLogicalIndex(i))
            for i in range(mplug.numElements())
        ]

    # compound
    if mplug.isCompound:
        # if om2.MFn.kAttribute2Double <= api_type <= om2.MFn.kAttribute4Double:
        #     return mplug.asMDataHandle().asVector()
        return [
            _getattr_impl(mplug.child(i)) for i in range(mplug.numChildren())
        ]

    # typed
    if api_type == om2.MFn.kTypedAttribute:
        attr_type = om2.MFnTypedAttribute(mobj).attrType()
        return _typed_attr_table[attr_type](mplug)

    # numeric
    if api_type == om2.MFn.kNumericAttribute:
        numeric_type = om2.MFnNumericAttribute(mobj).numericType()
        return _numeric_attr_table[numeric_type](mplug)

    return _api_type_table[api_type](mplug)
Exemple #26
0
def initialize():
    """
    Initializes the node.
    """
    # guide attributes
    fn_num = oMa.MFnNumericAttribute()
    SeamlessFkIk.thigh_len_mobj = fn_num.create("thighLen", "tl",
                                                oMa.MFnNumericData.kFloat)
    SeamlessFkIk.shin_len_mobj = fn_num.create("shinLen", "sl",
                                               oMa.MFnNumericData.kFloat)

    # message attributes
    fn_message = oMa.MFnMessageAttribute()
    SeamlessFkIk.fk_01_mobj = fn_message.create("fk01", "fk01")
    SeamlessFkIk.fk_02_mobj = fn_message.create("fk02", "fk02")
    SeamlessFkIk.fk_03_mobj = fn_message.create("fk03", "fk03")
    SeamlessFkIk.ik_main_mobj = fn_message.create("ikMain", "ikm")
    SeamlessFkIk.ik_pole_mobj = fn_message.create("ikPole", "ikp")

    # add attributes
    SeamlessFkIk.addAttribute(SeamlessFkIk.thigh_len_mobj)
    SeamlessFkIk.addAttribute(SeamlessFkIk.shin_len_mobj)

    SeamlessFkIk.addAttribute(SeamlessFkIk.fk_01_mobj)
    SeamlessFkIk.addAttribute(SeamlessFkIk.fk_02_mobj)
    SeamlessFkIk.addAttribute(SeamlessFkIk.fk_03_mobj)
    SeamlessFkIk.addAttribute(SeamlessFkIk.ik_main_mobj)
    SeamlessFkIk.addAttribute(SeamlessFkIk.ik_pole_mobj)
Exemple #27
0
def init():
    pass
    # (1) Get Maya data types and attributes
    kString = om.MFnData.kString
    kFloat = om.MFnNumericData.kFloat
    tAttr = om.MFnTypedAttribute()
    nAttr = om.MFnNumericAttribute()
    kDoubleArray = om.MFnNumericData.kDoubleArray

    # (2) Setup attributes
    csvToScalarArray.filePath = tAttr.create('filePath', 'fp', kString)
    tAttr.usedAsFilename = True
    csvToScalarArray.frame = nAttr.create('frame', 'fr', kFloat, 0.0)
    nAttr.hidden = False
    nAttr.keyable = True
    csvToScalarArray.result = tAttr.create('result', 'r', kDoubleArray,
                                           om.MFnDoubleArrayData().create())
    tAttr.writable = False
    tAttr.storable = False
    tAttr.readable = True

    # (3) Add the attributes to the node
    csvToScalarArray.addAttribute(csvToScalarArray.filePath)
    csvToScalarArray.addAttribute(csvToScalarArray.frame)
    csvToScalarArray.addAttribute(csvToScalarArray.result)

    # (4) Set the attribute dependencies
    csvToScalarArray.attributeAffects(csvToScalarArray.filePath,
                                      csvToScalarArray.result)
    csvToScalarArray.attributeAffects(csvToScalarArray.frame,
                                      csvToScalarArray.result)
Exemple #28
0
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('')
Exemple #29
0
    def initialize(cls):
        numeric_attr = om.MFnNumericAttribute()

        # create attributes
        cls.multiplier_obj = numeric_attr.create(
            "multiplier", "mul", om.MFnNumericData.kInt,
            2)  # long name, short name, data type, default value
        numeric_attr.keyable = True  # makes the attr visible in the channel box and as an input
        numeric_attr.readable = False  # set attr to "write only"

        cls.multiplicand_obj = numeric_attr.create("multiplicand", "mulc",
                                                   om.MFnNumericData.kDouble,
                                                   0.0)
        numeric_attr.keyable = True  # makes the attr visible in the channel box and as an input
        numeric_attr.readable = False  # set attr to "write only"

        cls.product_obj = numeric_attr.create("product", "prod",
                                              om.MFnNumericData.kDouble, 0.0)
        numeric_attr.writable = False  # set attr to "read only"

        # add attributes to the node
        cls.addAttribute(cls.multiplier_obj)
        cls.addAttribute(cls.multiplicand_obj)
        cls.addAttribute(cls.product_obj)

        # Connect output attributes
        cls.attributeAffects(cls.multiplier_obj, cls.product_obj)
        cls.attributeAffects(cls.multiplicand_obj, cls.product_obj)
    def initialize():
        nAttr1 = om.MFnNumericAttribute()
        PoseWeightSolver.inOverridingWeight = nAttr1.create(
            'overridingWeight', 'iow', om.MFnNumericData.kFloat, 1.0)
        nAttr1.keyable = True

        nAttr1 = om.MFnNumericAttribute()
        PoseWeightSolver.inOverridingInt = nAttr1.create(
            'overridingIntensity', 'ioi', om.MFnNumericData.kFloat, 0.0)
        nAttr1.keyable = True

        nAttr2 = om.MFnNumericAttribute()
        PoseWeightSolver.inWeightList = nAttr2.create('inWeightList', 'iWal',
                                                      om.MFnNumericData.kFloat,
                                                      0.0)
        nAttr2.keyable = True
        nAttr2.array = True

        nAttr3 = om.MFnNumericAttribute()
        PoseWeightSolver.inWeightMulList = nAttr3.create(
            'inWeightMulList', 'iWml', om.MFnNumericData.kFloat, 0.0)
        nAttr3.keyable = True
        nAttr3.array = True

        nAttrOut = om.MFnNumericAttribute()
        PoseWeightSolver.outWeight = nAttrOut.create('outWeight', 'ow',
                                                     om.MFnNumericData.kFloat,
                                                     0.0)
        nAttrOut.keyable = False
        nAttrOut.storable = False

        # add the attributes
        om.MPxNode.addAttribute(PoseWeightSolver.inWeightList)
        om.MPxNode.addAttribute(PoseWeightSolver.inWeightMulList)
        om.MPxNode.addAttribute(PoseWeightSolver.inOverridingWeight)
        om.MPxNode.addAttribute(PoseWeightSolver.inOverridingInt)
        om.MPxNode.addAttribute(PoseWeightSolver.outWeight)

        # establish effects on output
        om.MPxNode.attributeAffects(PoseWeightSolver.inWeightList,
                                    PoseWeightSolver.outWeight)
        om.MPxNode.attributeAffects(PoseWeightSolver.inWeightMulList,
                                    PoseWeightSolver.outWeight)
        om.MPxNode.attributeAffects(PoseWeightSolver.inOverridingWeight,
                                    PoseWeightSolver.outWeight)
        om.MPxNode.attributeAffects(PoseWeightSolver.inOverridingInt,
                                    PoseWeightSolver.outWeight)