THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 20/07/2007 at 11:16, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R9-r10
Platform: Windows ; Mac ; Mac OSX ;
Language(s) : C++ ;
---------
Howdy,
OK, this is probably very simple, but I just can't get my head around it.
in a CommandData plugin, I have a function that creates a PolygonObject and inserts it into the document. The function is based on this example code from the SDK docs in the Modeling library:
AutoAlloc<PolygonObject> obj(0,0);
if (!obj) return FALSE;
AutoAlloc<Modeling> mod;
if (!mod || !mod->InitObject(obj)) return FALSE;
LONG a = mod->AddPoint(obj, Vector(0,0,0));
LONG b = mod->AddPoint(obj, Vector(100,0,0));
LONG c = mod->AddPoint(obj, Vector(150,50,0));
LONG d = mod->AddPoint(obj, Vector(100,100,0));
LONG e = mod->AddPoint(obj, Vector(0,100,0));
if (!a || !b || !c || !d || !e) return FALSE;
LONG padr[] = {a,b,c,d,e};
LONG cnt = sizeof(padr)/sizeof(padr[0]);
LONG i = mod->CreateNgon(obj, padr, cnt);
if (!i) return FALSE;
if (!mod->Commit()) return FALSE;
doc->InsertObject(obj.Release(), NULL, NULL);
EventAdd();
The problem is, that the function needs to return a BaseObject pointer to the Execute() function in the CommandData:
BaseObject *polyOp = CreatePolygonObject(doc,op);
if(!polyOp)
{
GePrint("no polyOp");
return TRUE;
}
.... perform other operations on polyOp ...
The function is setup like this:
BaseObject* CreatePolygonObject(BaseDocument *doc,BaseObject *op)
{
AutoAlloc<PolygonObject> obj(0,0);
if (!obj) return NULL;
..... code to create polygon object ....
return static_cast<BaseObject*>(obj);
}
The function creates the object alright and inserts it into the document, but upon returning to the Execute() function, the console prints "no polyOp" and the Execute() function returns without continuing the rest of the operations on the object.
What is the proper way to return a BaseObject pointer?
I've tried several different things on the return. The above example is just the latest thing I tried. :(
Adios,
Cactus Dan