marol
11-12-2010, 01: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
{
public:
CustomData();
virtual ~CustomData();
virtual void copy (const MPxData&);
virtual MTypeId typeId() const;
virtual MString name() const;
static void* creator();
public:
static const MString typeName;
static const MTypeId id;
public:
Data* data;
};
// customData.cpp
#include "customData.h"
const MTypeId CustomData::id(0x00061);
const MString CustomData::typeName("CustomData");
CustomData::CustomData() : data(0)
{
}
CustomData::~CustomData()
{
}
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.)
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
{
public:
CustomData();
virtual ~CustomData();
virtual void copy (const MPxData&);
virtual MTypeId typeId() const;
virtual MString name() const;
static void* creator();
public:
static const MString typeName;
static const MTypeId id;
public:
Data* data;
};
// customData.cpp
#include "customData.h"
const MTypeId CustomData::id(0x00061);
const MString CustomData::typeName("CustomData");
CustomData::CustomData() : data(0)
{
}
CustomData::~CustomData()
{
}
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.)
