MStatus blindDoubleDataCmd::redoIt() { MStatus stat; // Status code MObject dependNode; // Selected dependency node // Iterate over all selected dependency nodes // for ( ; !iter->isDone(); iter->next() ) { // Get the selected dependency node and create // a function set for it // if ( MS::kSuccess != iter->getDependNode( dependNode ) ) { cerr << "Error getting the dependency node" << endl; continue; } MFnDependencyNode fnDN( dependNode, &stat ); if ( MS::kSuccess != stat ) { cerr << "Error creating MFnDependencyNode" << endl; continue; } // Create a new attribute for our blind data // // cerr << "Creating attr..." << endl; MFnTypedAttribute fnAttr; const MString fullName( "blindDoubleData" ); const MString briefName( "BDD" ); MObject newAttr = fnAttr.create( fullName, briefName, blindDoubleData::id ); // Now add the new attribute to the current dependency node // // cerr << "Adding attr..." << endl; fnDN.addAttribute( newAttr, MFnDependencyNode::kLocalDynamicAttr ); // Create a plug to set and retrive value off the node. // MPlug plug( dependNode, newAttr ); // Instantiate blindDoubleData and set its value. // blindDoubleData * newData = new blindDoubleData; // cerr << "Setting value of attribute to 3.2" << endl; newData->setValue( 3.2 ); // Set the value for the plug. // stat = plug.setValue( newData ); // Now try to retrieve the value off the plug as an MObject. // MObject sData; stat = plug.getValue( sData ); if ( stat != MS::kSuccess ) { cerr << "error getting value off plug" << endl; continue; } // Convert the data back to MPxData. // MFnPluginData pdFn( sData ); blindDoubleData* data = ( blindDoubleData* ) pdFn.constData( &stat ); // Get the value. // if ( NULL == data ) { cerr << "error: failed to retrieve data." << endl; } } return MS::kSuccess; }
MStatus blindComplexDataCmd::redoIt() { MStatus stat; // Status code MObject dependNode; // Selected dependency node // Iterate over all selected dependency nodes // for ( ; !iter->isDone(); iter->next() ) { // Get the selected dependency node and create // a function set for it // if ( MS::kSuccess != iter->getDependNode( dependNode ) ) { cerr << "Error getting the dependency node" << endl; continue; } MFnDependencyNode fnDN( dependNode, &stat ); if ( MS::kSuccess != stat ) { cerr << "Error creating MFnDependencyNode" << endl; continue; } // Create a new attribute for our blind data // // cout << "Creating attr..." << endl; MFnTypedAttribute fnAttr; const MString fullName( "blindComplexData" ); const MString briefName( "BCD" ); MObject newAttr = fnAttr.create( fullName, briefName, blindComplexData::id ); // Now add the new attribute to the current dependency node // // cout << "Adding attr..." << endl; fnDN.addAttribute( newAttr, MFnDependencyNode::kLocalDynamicAttr ); // // now we will demonstrate setting the value by using a plug. MPlug plug( dependNode, newAttr ); // // create an instance of the blind data with an initial array size of // 5. blindComplexData * newData = new blindComplexData( 5 ); // // initialized // cout << "setting data values..." << endl; unsigned int i; for ( i= 0; i < newData->length(); i++ ) { (*newData)[i]._intData = 10 + i; (*newData)[i]._doubleData = 20.02 + i; } // // setting the value for the plug. stat = plug.setValue( newData ); // // The following code demonstrates the retrieving of data from the // plug. MObject sData; stat = plug.getValue( sData ); if ( stat != MS::kSuccess ) { cerr << "error getting value off plug" << endl; continue; } // // Convert the data from an MObject back to a pointer to MPxData, then // cast it back to a pointer to blindComplexData. MFnPluginData pdFn( sData ); blindComplexData* data = ( blindComplexData* ) pdFn.constData( &stat ); // // read the data, and set the result to the values set. clearResult(); if ( NULL != data ) { // cout << "retrieving data values..." << endl; for ( i = 0; i < data->length(); i++ ) { // cout << "rec #" << i << ": " << (*data)[i]._intData << ", "; // cout << (*data)[i]._doubleData << endl; appendToResult((double) ((*data)[i]._intData)); appendToResult((*data)[i]._doubleData); } } else { // cout << "Null data" << endl; } } return MS::kSuccess; }