- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I created a node with a float array attribute. Its initialize function is as follows:
MStatus MyTestNode::initialize()
{
MStatus status;
MFnTypedAttribute tAttr;
MFnFloatArrayData fnData;
MObject oData = fnData.create(&status);
CHECK_MSTATUS_AND_RETURN_IT(status);
aPositions = tAttr.create("positions", "pos", MFnData::kFloatArray, oData, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_MSTATUS_AND_RETURN_IT(addAttribute(aPositions));
return MS::kSuccess;
}
However, whenever I try to set to values and read from it using a script, I always read back a single value of 0.0.
But if I add a float array attribute to the node using a script, I am then able to access that new attribute.
Here is an example Python script:
import maya.cmds as mc
mc.createNode('MyTestNode', n='MyTestNode1')
mc.addAttr(ln='fArray', sn='fa', dt='floatArray')
mc.setAttr("MyTestNode1.positions", (0.1, 0.25, 0.5, 0.75), type="floatArray")
mc.setAttr("MyTestNode1.fArray", (0.1, 0.25, 0.5, 0.75), type="floatArray")
print('positions : {0}'.format(mc.getAttr("MyTestNode1.positions")))
print('fArray : {0}'.format(mc.getAttr("MyTestNode1.fArray")))
print("")
print('positions type : {0}'.format(mc.getAttr("MyTestNode1.positions", type=True)))
print('fArray type : {0}'.format(mc.getAttr("MyTestNode1.fArray", type=True)))Reading from positions returns 0.0
Reading from fArray returns [0.10000000149011612, 0.25, 0.5, 0.75]
The types are also different. positions returns a type of "typed" while fArray returns a type of "floatArray".
So I am wondering what is different between the attribute created with the C++ API and the one created with maya.cmds.
And how can I use the C++ API to create a float array attribute that can be accessed with scripts, or alternatively, how can I access the C++ float array attribute using scripts?
Note: My goal is to use a single float array attribute and not an array of float attributes (attribute created with setArray(true)).
Thanks!
Solved! Go to Solution.