V. Selecting with the API

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.