1. The command usually gets input from the selection list, calling Mglobal::getactiveselectionlist (Mselectionlist &dest, BOOL Orderedselectionifavailabel=false). Get mselectionlist and mitselectionlist to edit the selection list.
2. An example of printing all DAG nodes:
#include <maya/MSimple.h>#include<maya/MGlobal.h>#include<maya/MString.h>#include<maya/MDagPath.h>#include<maya/MFnDagNode.h>#include<maya/MSelectionList.h>#include<maya/MIOStream.h>mstatus pickexample::d oit (Constmarglist&) {Mdagpath node; Mobject component; Mselectionlist list; Mfndagnode Nodefn; Mglobal::getactiveselectionlist (list); for(unsignedintindex =0; Index < List.length (); index++) {List.getdagpath (Index, node, component); Nodefn.setobject (node); cout<< nodefn.name (). Aschar () <<"Is selected"<<Endl; } returnms::ksuccess;} Declaresimplecommand (Pickexample,"Autodesk","1.0");
If you build the geometry and then select it, this example will print out its name.
The setobject () method on Mfndagnode are inherited by all function sets from mfnbase and are used T o Set the object the function set would operate on. If a function set is to operate on a different object, use this method.
If you choose a lot of component for an object, this object will only output once.
If you select components for two objects, the components of the object will be appear two times in the selection list.
3.mitselectionlist:lets you filter the objects on the selection list to only see objects of a particular type.
mglobal::getactiveselectionlist (list); for (Mitselectionlist listiter (list);! Listiter.isdone (); Listiter.next ()) { Listiter.getdagpath (node, component); Nodefn.setobject (node); " %s is selected "<< Endl;}
The second part of the code can be replaced by this piece of code.
If you only want to iterator to see a specific object:
mitselectionlist listiter( list, MFn::knurbssurface )
4. the Mfn::type enumeration is used throughout the API to indicate item types.
5. Another-to-use mglobal::selectbyname (). This finds all objects matching a pattern and adds them to the active selection list. For example:
mglobal::selectbyname ("*sphere*");
V. Selecting with the API