五、selecting with the API

1. 命令通常从selection list中得到input, 调用MGlobal::getActiveSelectionList(MSelectionList &dest, bool orderedSelectionIfAvailabel=false).得到MSelectionList和MItSelectionList来编辑选择列表。

2. 一个打印所有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::doIt( const MArgList& )
{
    MDagPath node;
    MObject component;
    MSelectionList list;
    MFnDagNode nodeFn;
    MGlobal::getActiveSelectionList( list );
    for ( unsigned int index = 0; index < list.length(); index++ )
    {
        list.getDagPath( index, node, component );
        nodeFn.setObject( node );
        cout << nodeFn.name().asChar() << " is selected" << endl;
    }
    return MS::kSuccess;
}
DeclareSimpleCommand( pickExample, "Autodesk", "1.0" );

如果你建造几何体,然后选中它,这个例子会打印出它的名字。

The setObject() method on MFnDagNode is inherited by all function sets from MFnBase and is used to set the object the function set will operate on. 如果一个function set要操作不同的object,使用这个办法。

如果你选择了一个object的很多component,这个object也只会输出一次。

如果你选择了两个object的components, components多的那个object会在selection list appear两次。

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 );
    cout << nodeFn.name().asChar() << "%s is selected” << endl;
}

第二部分的代码可以被这段代码取代。

如果你只想Iterator查看具体某一种object:

  MItSelectionList listIter( list, MFn::kNurbsSurface )

4. The MFn::Type enumeration is used throughout the API to indicate item types.

5. Another way is to use MGlobal::selectByName(). This finds all objects matching a pattern and adds them to the active selection list. For example:

MGlobal::selectByName( "*Sphere*" );

转载于:https://www.cnblogs.com/bubbler/p/5152817.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值