maya c++ api: output array of matrices

720 views
Skip to first unread message

Sven Pohle

unread,
Apr 3, 2015, 2:32:38 PM4/3/15
to python_in...@googlegroups.com
hi,

i'm just getting back to some maya api c++ and am hitting my head on the following:

i have an input and output array of matrices. for the number of inputs i want the node to create the number of outputs. but my following code doesn't seem to work. i based it on some devkit nodes who do something similar with other data types as outputs. any help?

// initialize
aInputMatrices = mAttr.create("inputMatrices", "inputMatrices");
mAttr.setStorable(false);
mAttr.setConnectable(true);
mAttr.setArray(true);
mAttr.setHidden(true);
mAttr.setUsesArrayDataBuilder(true);
addAttribute(aInputMatrices);

aOutputMatrices = mAttr.create("outputMatrices", "outputMatrices");
mAttr.setStorable(false);
mAttr.setWritable(false);
mAttr.setStorable(false);
mAttr.setArray(true);
mAttr.setUsesArrayDataBuilder(true);
addAttribute(aOutputMatrices);
attributeAffects(aInputMatrices, aOutputMatrices);


// compute method
MStatus status;

    MArrayDataHandle hInputMatrices = data.inputArrayValue(aInputMatrices, &status);
    CHECK_MSTATUS_AND_RETURN_IT(status);

    cout << "count: " << hInputMatrices.elementCount() << endl;

    MArrayDataHandle hOutputMatrices = data.outputArrayValue(aOutputMatrices, &status);
    CHECK_MSTATUS_AND_RETURN_IT(status);

    MArrayDataBuilder builder(aOutputMatrices, hInputMatrices.elementCount(), &status);
    CHECK_MSTATUS_AND_RETURN_IT(status);

    for (unsigned int listIndex=0; hInputMatrices.elementCount(); listIndex++) {
        cout << listIndex << endl;
        MDataHandle outHandle = builder.addElement(listIndex);

        hInputMatrices.jumpToElement(listIndex);
        MMatrix curMat = hInputMatrices.inputValue(&status).asMatrix();

        outHandle.setMMatrix(curMat);
    }

    status = hOutputMatrices.set(builder);
    CHECK_MSTATUS_AND_RETURN_IT(status);

    status = hOutputMatrices.setAllClean();
    CHECK_MSTATUS_AND_RETURN_IT(status);

    return status;

Justin Israel

unread,
Apr 3, 2015, 5:15:40 PM4/3/15
to python_in...@googlegroups.com

Is this a typo?
Did you really want:

for (unsigned int listIndex=0; i <  hInputMatrices.elementCount(); listIndex++) {


        cout << listIndex << endl;
        MDataHandle outHandle = builder.addElement(listIndex);

        hInputMatrices.jumpToElement(listIndex);
        MMatrix curMat = hInputMatrices.inputValue(&status).asMatrix();

        outHandle.setMMatrix(curMat);
    }

    status = hOutputMatrices.set(builder);
    CHECK_MSTATUS_AND_RETURN_IT(status);

    status = hOutputMatrices.setAllClean();
    CHECK_MSTATUS_AND_RETURN_IT(status);

    return status;

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/172e8560-a221-4539-9ea5-57f1e235d4d1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Sven Pohle

unread,
Apr 3, 2015, 5:48:04 PM4/3/15
to python_in...@googlegroups.com
yes, found that earlier after stripping it all down. thanks justing :)

--sven


--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/IB3BIrAQAaI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0ZLOkGdzY9rUP%2B_XciEOq8z9XaLChcteEX_iHdHOuvgw%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages