MFn::kFluid and MFn::KFluidData attribute connection and limitation

We can create an attribute(typed attribute) using the following Maya C++ API
MFnTypedAttribute has 2 overload methods for creating attribute.

MObject create (const MString &fullName, const MString &briefName, const MTypeId &id, MObject defaultData=MObject::kNullObj, MStatus *ReturnStatus=NULL)
MObject create (const MString &fullName, const MString &briefName, MFnData::Type type, MObject defaultData=MObject::kNullObj, MStatus *ReturnStatus=NULL)

Here is the sample code

    MObject              fluidType::outGrid;    MStatus              stat;    MFnTypedAttribute    tAttr;        outGrid = tAttr.create("outGrid", "ogd", MFn::kFluid, MObject::kNullObj, NULL);    if (outGrid.isNull()) cerr << "object is null" << endl;    tAttr.setWritable(false);    tAttr.setStorable(false);

If we create an attribute with MFn::kFluid or MFn::kFluidData, because it is an enumerator, the create() function is not able to type cast or map it to MFnData::Type enumerator. Hence, if we try to create an attribute with the above method, you will get MObject as NULL.

In short, the MFn::kFluid and MFn::kFluidData attributes are fluid attributes that can not be created explicitly using either C++ API or using MEL script. But, if you assign any fluid shape to object, you can check whether the object has MFn::kFluidData or MFn::kFluid. For example, node.hasFn(MFn::kFluid) where node is MObject type.
We can connect fluid type of attributes only when if both the attributes are same type. For example, I created “fluid shape” node and “simpleFluidEmitter” node from devkit sample. I am able to connect “fluidShape.outGrid” to “simpleFluidEmitter.geometry” attributes.

Please check the below output:

getAttr -type simpleFluidEmitter.geometry;
// Result: fluid //

getAttr -type fluidShape1.outGrid;
// Result: fluid //

Fluid_outGrid_geometry


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading