PDA

View Full Version : i need your help!! it's about maya api..


EGGer
07-17-2005, 06:13 AM
Thank you for paying attention to my first thread here !

i am learning maya_api for two weeks ...

and i determine to write my first simple plugin.. .

feature specifies : when i pick a curve and an object in sence...then run my command...

it will duplicate a few objects picked first ...

when i creat this *.mll... it showed successful

but it can't work as i want in maya .... when i run this command ... it just display "MGlobal:displayInfo " information ...

please help me ... i know that there are huge difficulty waiting for me when i research this

skills ... i really want to get your help ... appreciatie!


here is my doit code:

{
MStatus stat = MS::kSuccess;
MStatus valueCheck;
MGlobal::displayInfo("egger_DUP_curve tool 1.0 + ");
int nPoint=5;
MString name;
unsigned index;
MVector trans;
MStringArray ObjSelection;


index = args.flagIndex("n","number");
if (MArgList::kInvalidArgIndex !=index)
{
args.get( index+1,nPoint);
}
MSelectionList selection;
MGlobal::getActiveSelectionList( selection);


MDagPath dagPath;
MDagPath objDagPath;
MFnNurbsCurve curveFn;
MFnTransform transformFn;
MItSelectionList objIter(selection,MFn::kTransform);

//---------------------------------------------
for ( ; objIter.isDone();objIter.next())
{
objIter.getDagPath(objDagPath);
if (objDagPath.apiType() != MFn::kNurbsCurve)
{
transformFn.setObject(objDagPath);
}
}

name = transformFn.name(&valueCheck);
if (!valueCheck)
{
MGlobal::displayInfo("can't get value of name ");
}
trans = transformFn.translation(MSpace::kWorld);
MGlobal::displayInfo( transformFn.name());

//---------------------------------------

MItSelectionList iter( selection,MFn::kNurbsCurve);
for ( ; iter.isDone();iter.next())

{
iter.getDagPath( dagPath );
curveFn.setObject( dagPath );
double cStart, cEnd;
curveFn.getKnotDomain(cStart,cEnd);
MPoint pt;
int i;
double t;
double cIncr = (cEnd - cStart)/(nPoint - 1);
for (i=0,t=cStart; i<nPoint;i++,t+=cIncr)

{
curveFn.getPointAtParam( t, pt, MSpace::kWorld );

pt.y+= 0.5 * trans.y;
dgMod.commandToExecute(MString("select -r")+name+";");

dgMod.commandToExecute(MString("duplicate -rr -n ")+name+i+";");

dgMod.commandToExecute(MString("move -r ")+pt.x+" "+pt.y+" "+pt.z+";");

}




}

return redoIt();
}

gga
07-17-2005, 05:36 PM
Well, you have not mentioned what's wrong or what are the messages you get, but...
at first glance, I can see a bunch of problems:

a)

if (objDagPath.apiType() != MFn::kNurbsCurve)
{
transformFn.setObject(objDagPath);
}


is useless, as you are already filtering using MFn::Transform in the iterator. Thus, all objects will be transforms (if there are any selected). If not, transformFn will remain unitialized and all operations on it will fail.

b) You are using transformFn.name() for selection later on. This will fail if you have several nodes with the same name. Use fullPathName() instead and enclose names in quotes.

c) You never call doit() on dgMod, so all mel commands remain unexecuted.

d) You are missing a space between select -r and name, leading to an invalid string.
dgMod.commandToExecute(MString("select -r")+name+";");

e) You are calling redoIt() at the end of the code for no reason. Part of the code you are showing should probably be part of the redoIt() method to support undo properly. Also, see Brian Ewert's web page about undo issues with MDgModifier.

f) for (i=0,t=cStart; i<nPoint;i++,t+=cIncr)

You are incorrectly resetting i to 0 on each iteration. This will lead to objects with repeated names if multiple curves are selected.

g) Other general problems include the fact that you are not using stat (your error check variable) on any function, so if any function fails, you will not find out about it. Use a macro like MCHECK() in the maya demo examples.

EGGer
07-18-2005, 10:50 AM
gga:


wow! i don't know how to express my feeling when i looked around your reply ! i will check every sentence one by one as carefully as i can ... there are seven points showed by you ... yeah ! they are so valuable for me ...a fresh man in maya api! thank you for spending time on my questions ... i will take your suggestion with me ... and do my best ... please wait for my good news! thank you so much ! friend...

Carina
07-25-2005, 07:14 AM
For future reference there's a section especially for Mel and Maya API discussions in the Alias Maya forum

EGGer
07-26-2005, 02:15 AM
For future reference there's a section especially for Mel and Maya API discussions in the Alias Maya forum

Carina: That's very kind of you ! Thank you for your reply ! :)

Robert Bateman
08-02-2005, 10:06 PM
my old lecture notes and a couple of source code samples can be found here http://robthebloke.org/mayaapi.html

CGTalk Moderation
08-02-2005, 10:06 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.