THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 12/11/2007 at 05:44, xxxxxxxx wrote:
Cinema 4D Version: 10
Platform: Windows ;
Language(s) : C.O.F.F.E.E ;
I need your help converting any object to a polygon object. I've searched the forum, but haven't found a solution concerning this specific problem.
My current workflow: first i'm using
SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, doc, obj, bc, MODIFY_ALL);
\> pobj = doc- >GetActiveObject();
to convert the object to polygons. Then i joined the resulting object with all it's possible child objects, because the 'currentstatetoobject' from i.e. an ExtrudeNURBS produces childs (i.e. Extrude Nurbs, Cap1, Cap2).
But it's not that easy:
SendModelingCommand(MCOMMAND_JOIN, doc, pobj, bc, MODIFY_ALL);
\> robj = doc- >GetActiveObject();
joints all polygon objects in the document, even below the selected pobj and not only in the hierarchy.
That's why i created a temporary NullObject, moved the polygon object pobj in there and used SendModelingCommand: MCOMMAND_JOIN on that NullObject. This fixed joining other objects in the document, but leads to troubles with the original start object's global matrix. To again, correct this, i first have to set the matrix of the Null-Object ...
... but ... is this an easy and elegant way to solve my task?!
Abstract: while keeping position, orientation etc (global matrix), i'd like to convert any object (cube, ExtrudeNurbs etc.) to a single polygon object...
On 12/11/2007 at 06:50, xxxxxxxx wrote:
If you head over to:
and check out GroupConnect script I think you'll get some pointers.
On 12/11/2007 at 08:07, xxxxxxxx wrote:
thank you very much!
Sadly, i've already tried using the Command-Funktion: but while doing this i'm having trouble with the Undos. Even if i set the undos on my own (StartUndo, AddUndo, EndUndo), C4D remembers the two commands and you need to click the undo button three times to undo ONE plugin execution
Thank's for your time.
On 12/11/2007 at 12:56, xxxxxxxx wrote:
To encapsulate the undos yourself, set doc in the SendModelingCommand() arguments to NULL. Directly from the COFFEE documentation:
If a document is provided, an undo is automatically added. If doc is NULL, no undo is added, so one can collect multiple SendModelingCommand() calls.
pobj = doc->GetActiveObject();
robj = doc->GetActiveObject();
sobj = doc->GetActiveObject();
As for the complexity, unfortunately the cleanup is necessary. In C++, there is a BaseDocument::Polygonize() method which converts the entire document into polygon objects - this would still require the joining to create one polygon object. COFFEE doesn't have a similar method.
On 12/11/2007 at 15:07, xxxxxxxx wrote:
Thanks, yes, i know how to use the undo functions.
But, as mentioned above, they'll don't work with "CallCommand(n)", which is used in Lennart's linked code.
I'm looking for
a) an easy way with SendModelingCommand() or
b) a solution with CallCommand() using a "single" undo-click.
On 12/11/2007 at 15:59, xxxxxxxx wrote:
Ah, I see. It appears that CallCommand() would be exactly the same as the user doing each command in the interface - you get the undos created by each command similarly. No way around that I think.
The best approach here would be to use SendModelingCommand() and do CurrentStateToObject for each root object in the document. As you note, you get a lot of 'junk' (grouping Null objects and multiple polygon objects for particular primitive types). The only way around this is to move the wanted objects (polygon objects) out from the Null objects and remove/delete the Null objects. Once you have everything converted and all of those wanted objects, you can start joining.
The transformation problem is one which I've also had to deal with. Gets even more exciting if you are retaining animation! Can't remember offhand how to rectify this, but it may involve getting the global matrix before unparenting (moving the polygon objects out from nulls and such) and applying the matrix after inserting it back into the document.