I’m currently using C#, and this is my first time using Array attributes and Compound attributes within an MPxNode. Essentially I have this node setup:
[MPxNodeInitializer()]
public static void initialize() {
MFnCompoundAttribute cAttr = new MFnCompoundAttribute();
MFnMessageAttribute mAttr = new MFnMessageAttribute();
MFnTypedAttribute tAttr = new MFnTypedAttribute();
MFnMatrixAttribute matrixAttr = new MFnMatrixAttribute();
spacesAttr = cAttr.create( "spaces", "sp" );
cAttr.isArray = true;
cAttr.addChild( mAttr.create( "inTransform", "it" ) );
cAttr.addChild( tAttr.create( "name", "nm", MFnData.Type.kString ) );
cAttr.isStorable = true;
cAttr.usesArrayDataBuilder = true;
addAttribute( spacesAttr );
outMatrix = matrixAttr.create( "outMatrix", "om" );
matrixAttr.isStorable = false;
addAttribute( outMatrix );
outName = tAttr.create( "outName", "on", MFnData.Type.kString );
tAttr.isStorable = false;
addAttribute( outName );
// Attribute Affects
attributeAffects( spacesAttr, outMatrix );
attributeAffects( spacesAttr, outName );
}
What I’m trying to do is - During the compute function, I want to iterate on all inTransform plugs and grab the nodes that are connected. I’m a little stumped on how to deal with Array Compound attributes with the datablock.
This is what I have so far, but I’m not sure if its correct or not. I’ve tried different ways to try and get at the array compound plugs but so far no luck. Any help would be much appreciated!
public override bool compute( MPlug plug, MDataBlock dataBlock ) {
MMatrix final_matrix = new MMatrix();
string final_name = "";
if( plug.attribute.equalEqual( outMatrix ) ) {
MArrayDataHandle array_handle = dataBlock.inputArrayValue( spacesAttr );
uint num_elements = array_handle.elementCount();
for( uint i=0; i<num_elements; i++ ){
array_handle.jumpToElement( i );
MDataHandle element_handle = array_handle.inputValue();
// ???
// ???
// ???
}
MDataHandle outMatrixHandle = dataBlock.outputValue( outMatrix );
outMatrixHandle.asMatrix = final_matrix;
MDataHandle outNameHandle = dataBlock.outputValue( outName );
outNameHandle.asString = final_name;
}
// Set output data
dataBlock.setClean( plug );
return true;
}