View Full Version : Problem adding a custom attribute (MPxData)

11 November 2010, 02:20 PM
I have a custom attribute derived from MPxData that I would like to add to my nodes. The customData loads fine and shows up in the plugin manager, I can successfully create the attribute using:
aData = typedAttr.create("customData", "data", CustomData::id, MObject::kNullObj, &status); // status == MS::kSuccess
... but when I add the attribute it claims I have an invalid parameter.
status = addAttribute(aData); // status == MS::kInvalidParameter
Just for the record, the other attributes are all successfully added. It only complains about the custom attribute. How do I go about adding this attribute? The documentation suggests that it should be added (dynamically?) using MFnDependencyNode but the samples adds the custom attribute statically like all the other ones. Any guesses where I might have messed up?

For completeness, here is my source code:
// customData.h
class CustomData : public MPxData
virtual ~CustomData();

virtual void copy (const MPxData&);
virtual MTypeId typeId() const;
virtual MString name() const;

static void* creator();

static const MString typeName;
static const MTypeId id;

Data* data;

// customData.cpp
#include "customData.h"

const MTypeId CustomData::id(0x00061);
const MString CustomData::typeName("CustomData");

CustomData::CustomData() : data(0)


void CustomData::copy (const MPxData& other)
*data = *(((const CustomData&)other).data);

MTypeId CustomData::typeId() const
return CustomData::id;

MString CustomData::name() const
return CustomData::typeName;

void* CustomData::creator()
return new CustomData;
// setupPlugin.cpp
status = plugin.registerData(CustomData::typeName, CustomData::id, CustomData::creator);
status = plugin.deregisterData(CustomData::id);

(Note that in my case I don't actually want my CustomData to contain anything but a pointer. I am using an external framework that will own the actual data structure.)

01 January 2011, 02:51 AM
I met the same problem when i try to add my defined data, i read the maya plugins example(\devkit\plug-ins\apiMeshShape.sln) , so i copy the code , follow the example , maya can add my defined data, it means that

outputData = typedAttr.create("data","da",UserData::id,MObject::kNullObj,&stat);

it worked, but when i add this attribute ,
addAttribute( outputData );
it failed,the same trouble as you!

so i try
outputData = typedAttr.create("data","da",MFnPluginData::kPlugin,MObject::kNullObj);

and addAttribute( outputData );

anything is worked well!

I don't know why this two methods typedAttr.create() can result in the difference, but

outputData = typedAttr.create("data","da",MFnPluginData::kPlugin,MObject::kNullObj);

is already worked .

Wish it will be helpful to you!

02 February 2011, 09:21 AM
Thanks for the heads up! In the end, I chose to go with another solution. Since I'm developing plug-ins for other applications other than Maya as well, I need the plug-in code to be as separated from the framework code as possible. I solved it by letting my framework take responsibility for allocating memory and then request the data in Maya. It turned out pretty well this time but if I bump into the same problem again, I will try your solution.

02 February 2011, 02:25 PM
could be just a naming issue, which is checked only when adding the attribute to a node. try completely new names for atributes, or shortening the short form of attribute name. haven't happened to me with attribute names (though i kinda avoid naming to be too generic, which is the case of "data") - but quite a few times a flag in command was missing because short name form was too long.

CGTalk Moderation
02 February 2011, 02:25 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.