hohehohe2's OpenMaya tutorial     kotamuraa@yahoo.co.jp



9. Handling DG node(basic)

 
 The example at Chapter 7,

There are two nurbs surface in the scene. How can I change values of
one surface CV positions and not the other, using MFnNurbsSurface class instance.

The first process was,

1) Get an MObject of the nurbs surface which you want to change CV positions.

How it can be done wasn't described yet.

 In this chapter I will describe the general way of getting an MObject of a DG node by
its node name.

 In this chapter I will also describe
    - How to get an MObject of the selected (active) DG nodes
    - How to select (activate) a DG node.

 Here selecting (activating) a node means just the same way as you left click
a scene object or left click a node in the Hypergraph.

 
Selection list

 Let's take a look at a sample program first. It is a program to display every node which
name starts with "hohehohe2".

---------------------------------------------------------------------
#include <maya/MGlobal.h>
#include <maya/MSelectionList.h>
#include <maya/MFnDependencyNode.h>

MStatus displayHohe::doIt( const MArgList& ){

    //Create a selection list, get an MObject of the nodes which name
    //starts from "hohehohe2" in it.
    MSelectionList selList;
    selList.add("hohehohe2*");

    //How many DG nodes are there in the list?
    int numObjs = selList.length();

    for (int i = 0; i < numObjs; ++i){

        //Get the contents of the selection list one by one,
        //set it to "objHohe".
        MObject objHohe;
        selList.getDependNode(i ,objHohe);

        //Create a function set, connect to it,
        MFnDependencyNode fnDepHohe(objHohe);

        //and display its name.
        MGlobal::displayInfo(fnDepHohe.name());
        MGlobal::displayInfo(fnDepHohe.typeName());
        MGlobal::displayInfo(""); //Line feed

    }

    return MS::kSuccess;
}

MStatus displayHohe::redoIt(){return MS::kSuccess;}
MStatus displayHohe::undoIt(){return MS::kSuccess;}
---------------------------------------------------------------------

Here, three classes

    - MGlobal
    - MSelectionList
    - MFnDependencyNode

are used, so three header files are included.

    #include <maya/MGlobal.h>
    #include <maya/MSelectionList.h>
    #include <maya/MFnDependencyNode.h>

Generally when you need to use ****, you need to include

    maya/****.h

file.


 A class MSelectionList has come out.
This class is a container class ( it's like an array ) to contain MObjects.
(API manual says MSelectionList implement a list of MObjects)

When the first MSelectionList class instance is created,

    MSelectionList selList;

nothing is in the list. But just after it has created,

    selList.add("hohehohe2*");

every node which its name start with "hohehohe2" is added to the list.

Next, get the number of MObjects in the list using MSelectionList::length() method.

   int numObjs = selList.length();

Then create a loop and display it one by one.

    for (int i = 0; i < numObjs; ++i){

In the loop, get the i th MObject of the selection list.

        MObject objHohe;
        selList.getDependNode(i ,objHohe);

Attach a function set to access the node, and
display informations such as node name to the Script Editor.

        MFnDependencyNode fnDepHohe(objHohe);
        MGlobal::displayInfo(fnDepHohe.name());
        MGlobal::displayInfo(fnDepHohe.typeName());
        MGlobal::displayInfo(""); //Line feed

Compile the sample program and execute it.
Name this command plug-in "displayHohe".

First make a nurbs sphere primitive in the scene, rename it to
"hohehohe2Sphere1", and then run "displayHode"

In the Script Editor the following informations will be displayed.

displayHohe;
// hohehohe2Sphere1
// transform
//
// hohehohe2SphereShape1
// nurbsSurface
//

Since the shape node is automatically renamed if you rename an
object (transform node), two node informations are displayed.

P.S.
Note that "selection"(left click and activate a scene object) and "selection list"
are completely different thing.
"selection" can be done within a plug-in code using "selection list", but do not
mix them up.



Global selection list


 I haven't written this yet.
(-_-)


Prev    Contents    Next


Maya is a registered trademark of Autodesk
Copyright
© 2003, Koichi Tamura. All Rights Reserved.


















[PR]衝撃!あなたの本当の裏の顔!:実は貴方はΟΔ県出身?ここで分かる真実