** UPDATE **
Nevermind; I got it. I can now avoid exporting invisible objects (finally!).
I use pruning, and my isVisible() test does work, but if you see any conceptual errors or gotchas that I missed do feel free to point them out.
I really can not prune invisible objects.
ATTEMPT #1:
I tried prune() using the same visibility test that I showed earlier.
CODE
for (; !idDags.isDone(); idDags.next() ) {
// Attach a function set to the object.
MFnMesh fmNode( idDags.item() );
// Skip history items.
if ( !fmNode.isIntermediateObject() ) {
MDagPath dpPath;
if ( MStatus::kFailure == idDags.getPath( dpPath ) ) {
MGlobal::displayError( "MDagPath::getPath" );
sStatus = MS::kFailure;
break;
}
MFnDagNode dnVisTester( dpPath );
MStatus sVisStatus;
if ( isVisible( dnVisTester, sVisStatus ) && MStatus::kSuccess == sVisStatus ) {
...
}
// ********* NOW I PRUNE *********
else {
idDags.prune();
}
}
}
The result is exactly the same. This means either prune does not work or isVisible() always returns true.
ATTEMPT #2:
So I tried to modify isVisible() (but without using prune()).
CODE
// Is a DAG node visible?
bool MPI_CharExport::isVisible( MFnDagNode &mfnDag, MStatus &msStatus ) const {
if ( mfnDag.isIntermediateObject() ) { return false; }
MPlug visPlug = mfnDag.findPlug( "visibility", &msStatus );
if ( MStatus::kFailure == msStatus ) {
MGlobal::displayError( "MPlug::findPlug" );
return false;
}
else {
bool bVisible;
msStatus = visPlug.getValue( bVisible );
if ( MStatus::kFailure == msStatus ) {
MGlobal::displayError( "MPlug::getValue" );
return false;
}
if ( !bVisible ) { return false; }
if ( mfnDag.parentCount() == 0 ) { return true; }
// If all parents are invisible, we are also invisible.
// If any parents are not, we are not.
unsigned int uiParents = mfnDag.parentCount();
MStatus msThisStatus;
for ( unsigned int I = 0; I < uiParents; ++I ) {
//mfnDag.parent( I, &msThisStatus ).
MFnDagNode dnParent( mfnDag.parent( I, &msThisStatus ), &msStatus );
if ( MStatus::kFailure == msThisStatus || MStatus::kFailure == msStatus ) { return false; }
if ( isVisible( dnParent, msStatus ) ) {
if ( MStatus::kFailure == msStatus ) { return false; }
return true;
}
}
// No visible parent found.
return false;
}
}
Apparently I do not know how to recurse backwards up the nodes, because this always returns false.
Can you point me in the right direction?
L. Spiro
P. S.: Where does MGlobal::displayError print? I have never seen any error messages in any windows in Maya, although I print some before and after my export begins and ends (respectively).