Feedback

What's your question?

By: [ Editor ] Asked from United States of America

Why am I only getting the last item returned?

I'm trying to print back my nurbsSurface selection. But the following code only returns the last one. Not all. What am I doing wrong?

MFnDependencyNode depFn;

MString name;

MSelectionList list;

MGlobal::getActiveSelectionList( list );

MItSelectionList nurbsList( list, MFn::kNurbsSurface );

for ( ; !nurbsList.isDone(); nurbsList.next() )
{

    MDagPath nurbs;

    MObject node;

    MObject component;  

    nurbsList.getDependNode( node );
    depFn.setObject( node );
    name = depFn.name();

    MString fullPath;
    nurbsList.getDagPath( nurbs, component );
    fullPath = nurbs.fullPathName();

    cout << "Name: " << name.asChar() << endl;
    cout << "Path: " << fullPath.asChar() << endl;
}

Add comment viewed 76 times Latest activity 11 months ago

NN comments
manny
-

Hey, why did it post like that? It makes it very difficult to read.

manny
-

I tried my best to make this legible. I don’t know why there’s a colored section.

or Cancel

1 answer

  • 0

julian [ Admin ]

Are you sure all the items are in the list? Check the length of the selection list:

cerr << "Items in list: " << list.length() << endl;

And try std::cerr instead of std::cout, it will be guaranteed to flush every time.

Alternatively, flush cout yourself like this:

cout << "Name: " << name.asChar() << endl << flush;
cout << "Path: " << fullPath.asChar() << endl << flush;
NN comments
manny
-

Thanks Julian. By the time that block of code was run, my active selection had reduced down to one. Still learning the whole plugin thing.

or Cancel