PDA

View Full Version : API: read material attributes


beuzel
10-20-2006, 08:55 AM
hello,

if you click on a material you can see the material in the attribute editor. with "add attribute" you can attach user specific data to the node which is displayed under "extra attributes". i want to read out these value in a maya 7.0 plugin.

my code:

// new code: effect parameters
int count = (int)shaderNodeFN.attributeCount(&status);
if (status)
{
String prependStr("effect");
for (int i = 0; i < count; ++i)
{
MObject obj = shaderNodeFN.attribute(i, &status);
if (status)
{
MFnAttribute attr = MFnAttribute(obj);

String name(attr.name().asChar());
//String typeStr(obj.apiTypeStr());
//rNotify("found attribute: type: " + typeStr + " name: " + name);
/* example output from bool, int, float, string and vector
--- Notify, 0: found attribute: type: kNumericAttribute name: effectAttributeBool array:no
--- Notify, 0: found attribute: type: kNumericAttribute name: effectAttributeInt array:no
--- Notify, 0: found attribute: type: kTypedAttribute name: effectAttributeString array:no
--- Notify, 0: found attribute: type: kNumericAttribute name: effectAttributeFloat array:no
--- Notify, 0: found attribute: type: kAttribute3Double name: effectAttributeVector array:no
--- Notify, 0: found attribute: type: kNumericAttribute name: effectAttributeVectorX array:no
--- Notify, 0: found attribute: type: kNumericAttribute name: effectAttributeVectorY array:no
--- Notify, 0: found attribute: type: kNumericAttribute name: effectAttributeVectorZ array:no
*/

if (name.startsWith(prependStr) && (name.getLength() > prependStr.getLength()))
{
plug = shaderNodeFN.findPlug(attr.name(), &status);
if (status)
{
// delete leading "effect"
String nameShort = name.substring(prependStr.getLength());

if (obj.apiType() == MFn::kNumericAttribute)
{
MFnNumericData data = MFnNumericData(obj);
MFnNumericData::Type dataType = data.numericType();
rNotify(String("obj data type: %0").arg(dataType));

// bool, int, float
bool valueBool;
int valueInt;
float valueFloat;
if (plug.getValue(valueBool))
{
material->setBool(nameShort, valueBool);
rNotify(String("found effect parameter bool: %0").arg(valueBool));
}
if (plug.getValue(valueInt))
{
material->setInt(nameShort, valueInt);
rNotify(String("found effect parameter int: %0").arg(valueInt));
}
if (plug.getValue(valueFloat))
{
material->setFloat(nameShort, valueFloat);
rNotify(String("found effect parameter float: %0").arg(valueFloat));
}
// TODO does not work
}
else if (obj.apiType() == MFn::kTypedAttribute)
{
// string
MString valueStr;
if (plug.getValue(valueStr))


The problem is that the all three plug.getValue() funtions are successfull. Only one should success! material is my own class for the export.

greetings chris

Robert Bateman
10-20-2006, 12:37 PM
if (obj.apiType() == MFn::kNumericAttribute)
{
MFnNumericData data = MFnNumericData(obj);
MFnNumericData::Type dataType = data.numericType();
rNotify(String("obj data type: %0").arg(dataType));

MFnNumericAttribute fnAttr(obj);

// bool, int, float
bool valueBool;
int valueInt;
float valueFloat;
if ( (fnAttr.unitType() == MFnNumericData::kBoolean)&& plug.getValue(valueBool))
{
material->setBool(nameShort, valueBool);
rNotify(String("found effect parameter bool: %0").arg(valueBool));
}
if ( (fnAttr.unitType() == MFnNumericData::kInt)&&plug.getValue(valueInt))
{
material->setInt(nameShort, valueInt);
rNotify(String("found effect parameter int: %0").arg(valueInt));
}
if ( (fnAttr.unitType() == MFnNumericData::kFloat)&&plug.getValue(valueFloat))
{
material->setFloat(nameShort, valueFloat);
rNotify(String("found effect parameter float: %0").arg(valueFloat));
}
// TODO does not work
}

beuzel
10-23-2006, 02:09 PM
Helllo,
This is exactly what I was searching for.
Thank you!

CGTalk Moderation
10-23-2006, 02:09 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.