Do people get their selection that way ?

78 views
Skip to first unread message

justin hidair

unread,
Apr 12, 2018, 8:32:01 PM4/12/18
to Python Programming for Autodesk Maya
 I was doing a dummy command for debugging and testing certain funcs , and what I usually do is  use

MGlobal::getSelectionListByName("pSphereShape1" , sel );

now it became redundant af , so I came up with a way to get the actual selected mesh and shiet :

MObjectArray mesh_list;
    MSelectionList sel;
MGlobal::getActiveSelectionList(sel);
if( sel.length() == 0)
{
MGlobal::displayError("no selection");
return MS::kFailure;
}

    MItSelectionList mitsel(sel);

MObject cur_obj;

do
{
     mitsel.getDependNode(cur_obj);
        if (cur_obj.hasFn(MFn::kMesh) )
            mesh_list.append( cur_obj );
        else if ( cur_obj.hasFn(MFn::kTransform) )
{

MFnTransform fntransform( cur_obj );
            for (int i=0 ;i < fntransform.childCount() ;++i )
{

if (fntransform.child(i).hasFn(MFn::kMesh))
mesh_list.append(fntransform.child(i));
}

}
        
        mitsel.next();

}while(!mitsel.isDone());



do you guys , do it similarly or in a different way ?
Reply all
Reply to author
Forward
0 new messages