PDA

View Full Version : Understanding the COFFEE API when using the Script Editor


Huesforalice
04-23-2008, 03:53 PM
Hi Guys,

I'm fairly new to cinema but quite excited about the usability of the program (went through maya and max already). I'm trying to get the hang of developing COFFEE Scripts. I'd consider myself a somewhat experienced software developer but I'm finding it pretty hard to get the hang of using the API documentation (when using the script editor inside cinema).

For example the api documentation says, "basedocument" should have the member "BaseObject* GetActiveObject()", so I write

var obj;
obj = doc->GetActiveObject();

that seems to work ok.

Now the API also says there should be a member "void GetActiveObjects(AtomArray& a, Bool children)"

Now the question is, how do I use this memberfunction in the script editor? If I write

var a;
doc->GetActiveObjects(a, false);

I get something like a "Member not found" error. Is there a way of defining pointers in the script editor? I'm just generally confused. Perhaps it would be sufficient to point me towards an introduction to scripting COFFEE inside Cinema as opposed to the API which seems to target C++ developers using proper c++ code.

Many thanks to all who answer, I'll repay in form of useful scripts (as soon as I've understood how things work :) ).

Dave

c-montesano
04-24-2008, 08:20 PM
I think you are looking at the C++ sdk documentation. You need the COFFEE documentation found here (http://www.maxon.net/pages/support/plugincafe_downloads_e.html). It's the last two items in the SDK Documentation section.

Rui Batista (http://www.ruimac.com/) has a very thorough book on COFFEE (http://www.ruimac.com/coffee_book/) as well that might be worth checking out.


-Chris

JDP
04-26-2008, 07:26 AM
You need the Coffee SDK 95.zip, it hasn't been updated for R10.5.

Huesforalice
04-26-2008, 09:49 AM
Hi Chris and JDP,

you're both right, I was actually looking at the C++ API Doc. The fact that the COFFEE SDK had the old Versionnumber got me confused. It looks like achieving the same functionality that the GetActiveObjects() function mentioned above only can be done by iterating over all objects and checking if the active bit is set. Ist that true? Sounds like a lot of overhead for a pretty simple thing to do.

Thanks again

Dave

Darter
04-26-2008, 03:35 PM
The BaseDocument COFFEE class has a GetActiveObject() function.

Huesforalice
04-26-2008, 03:37 PM
The BaseDocument COFFEE class has a GetActiveObject() function.

Yep, but it seems like it doesn't work for multiple selections, that's why I was asking about the GetActiveObjects function.

tcastudios
04-26-2008, 04:02 PM
Yup, you need to search afaik.
Like count how many active objects there is:

---------------------------------------------------------------------------
/////////// Count Active (Selected) Objects ///////////// For Script and Menu Plugins


CountActive();

/*PLUGIN_NAME::*/CountActive()
{
var aobj=GetActiveDocument()->GetFirstObject(), countobj;
if(aobj->GetBit(BIT_AOBJ)) { aobj = aobj; }
else {aobj=aobj->SearchNext(BIT_AOBJ);}

countobj = 0;
while(aobj)
{ countobj++; aobj=aobj->SearchNext(BIT_AOBJ); }

return countobj;
}

----------------------------------------------------------------------------


Cheers
Lennart

JDP
04-26-2008, 04:10 PM
You can also use a recursive function to go through all objects in the document. Here is an example to print out the names of all selected objects.



GetActiveObjects(obj)
{
while(obj)
{
if(obj->GetBit(BIT_AOBJ))
println(obj->GetName());

var next = obj->GetNext();
GetActiveObjects(obj->GetDown());
obj = next;
}
}
main(doc, op)
{
var obj = doc->GetFirstObject();
GetActiveObjects(obj);
}

CGTalk Moderation
04-26-2008, 04:10 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.