
hohehohe2's OpenMaya tutorial
kotamuraa@yahoo.co.jp
8. Handling data(sample program)
This chapter shows a sample program of the previous chapter.
I wanted to make a
more meaningful plug-in, but to focus on the comprehensibility,
this is an absolute
nonsense program as a plug-in.
The all thing this sample says is "MObject is just a handle".
Program
Before, I wrote something like
"When a command plug-in changes a scene, you must make the
command undoable"
But this example beaks the law. I need to use something that is
not explained yet.
So now just "you must make it undoable if you make a plug-in
like this sample",
keep it in mind.
---------------------------------------------------------------------
MStatus detaSousa::doIt( const MArgList& ){
return redoIt();
}
MStatus detaSousa::redoIt(){
MObject obj1, obj2;
MFnTransform fnTform1, fnTform2, fnTform3;
//Preparation. Add a transform node
(=null group) to the scene.
//MFnTransform::create() method returns
an MObject of the
//newly created transform node
obj1 = fnTform1.create();
//Assign obj1 to another MObject(obj2).
Now both obj1 and obj2 is
//connected to the newly created
transform.
obj2 = obj1;
//An example of attaching a function
set to an internal data using MObject
//obj2 indicates the new transform node
fnTform2.setObject(obj2);
//Access to the transform node using
the new function set.
fnTform2.setName("hohehohe");
//An example to show that MObject and
internal data is different.
//Even when no MObject is connected to an internal
data, the internal data is not deleted.
//Here, the internal data is a transform node.
obj1 = fnTform3.create();
obj2 = obj1;
fnTform1.setObject(obj1);
fnTform2.setObject(obj1);
return MS::kSuccess;
}
MStatus detaSousa::undoIt(){
return MS::kSuccess;
}
---------------------------------------------------------------------
About the program
Let's see what the program does. (Don't say it does nothing....)
MObject obj1, obj2;
MFnTransform fnTform1, fnTform2, fnTform3;
Just MObject class instances and MFnTransform class instances
are created.
No internal data is connected.
obj1 = fnTform1.create();
Add a transform node(NULL group) to the scene using MFnTransform::create()
method.
The node name gets "transform1" (if there's not already a node with
the same name).
This method returns an MObject that is connected to the newly created
transform node.
Now obj1 is connected to the transform node "transform1".
fnTform1 is also connected to "transform1" since "transform1" is
created by "fnTform1".
obj2 = obj1;
Now obj2 is connected to obj1 too.
fnTform2.setObject(obj2);
Call setObject() method of fnTform2. Since obj2 is already connected
to the internal
data(transform1 node), now fnTform2 is connected to "transform1".
fnTform2 is connected to "transform1"
fnTform2.setName("hohehohe");
Call MFnTransform::setName() method using fnTform2 instance.
fnTform2 is connected to transform1, so the name of transform1 changes
to
"hohehohe".
obj1 = fnTform3.create();
obj2 = obj1;
One more transform node is created using a new function set fnTform3,
and connect all the MObjects, function sets to the new transform.
Now no MObject is connected to "hohehohe", but hohehohe still exists
in the scene
since MObject is just a handle.
Prev Contents Next
Maya is a registered
trademark of Autodesk
Copyright ©
2003, Koichi Tamura. All Rights Reserved.