THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 03/06/2008 at 02:05, xxxxxxxx wrote:
User Information:
Cinema 4D Version:
Platform:
Language(s) :
---------
Hallo,
One of the most asked question on the forum is how to get the current state of an object within GetVirtualObjects(), meaning how to get on the polygons. There are some misconceptions floating around so I decided to make this sticky for easy finding.
First of all if you just want to get on the polygons of object primitives you have allocated within GetVirtualObjects() please use the GeneratePrimitive() function. You can simply cast it to a PolygonObject, see example below.
> \> BaseObject \*AtomObject::GetVirtualObjects(PluginObject \*op, HierarchyHelp \*hh) \> { \> BaseContainer bc; \> bc.SetVector(PRIM_CUBE_LEN, 200.0); \> bc.SetBool(PRIM_CUBE_DOFILLET, TRUE); \> bc.SetReal(PRIM_CUBE_FRAD, 40.0); \> bc.SetLong(PRIM_CUBE_SUBF, 5); \> \> PolygonObject \*res = NULL; \> res = (PolygonObject\* )GeneratePrimitive(NULL, Ocube, bc, 1.0, FALSE, hh->GetThread()); \> if(!res) goto Error; \> \> return res; \> \> Error: \> blDelete(res); \> return NULL; \> } \>
If you can not use GeneratePrimitive, for instance if the object has been allocated outside of your plugin, you have to make a clone of it and insert into a temporary document. Then use the Current State To Object command on it, see example below.
> \> BaseObject \*AtomObject::GetVirtualObjects(PluginObject \*op, HierarchyHelp \*hh) \> { \> BaseContainer bc; \> bc.SetVector(PRIM_CUBE_LEN, 200.0); \> bc.SetBool(PRIM_CUBE_DOFILLET, TRUE); \> bc.SetReal(PRIM_CUBE_FRAD, 40.0); \> bc.SetLong(PRIM_CUBE_SUBF, 5); \> \> AutoAlloc<BaseDocument> tdoc; \> if(!tdoc) return NULL; \> \> BaseObject \*res, \*cube = NULL; \> cube = BaseObject::Alloc(Ocube); \> if(!cube) return NULL; \> \> tdoc->InsertObject(cube, NULL, NULL, FALSE); \> \> ModelingCommandData mcd; \> mcd.doc = tdoc; \> mcd.op = cube; \> if(!SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, mcd)) return NULL; \> res = static_cast<BaseObject\*>(mcd.result->GetIndex(0)); \> if(res && (res->GetType() == Opolygon)) return res; \> \> blDelete(res); \> return NULL; \> } \>
cheers,
Matthias