extract object from c4d-file



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 15/02/2009 at 06:35, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   10.5 
    Platform:      
    Language(s) :   C.O.F.F.E.E  ;

    ---------
    Hi,

    Is there any way to extract the first object of a c4d-file into the current file with COFFEE?
    I tried it using LoadDocument, getFirstObject, copying it to the current file and closing the opened file, but this just led to crashes:

    var nDoc = LoadDocument(fn);
         var bd = GetActiveDocument();
         var obj = bd->GetFirstObject();
         CallCommand(12664);
         GetActiveDocument();
         doc->InsertObject(obj, NULL, NULL);

    Does anybody have a working solution for this?



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 15/02/2009 at 08:11, xxxxxxxx wrote:

    You need to keep track of what document is actually the active document.
    So basically before opening the new document
    stamp the current one (that you will paste into) as the "target" document.
    I have a more involved setup that works fine, the code below is just out of my head
    but the principe should be ok.

    Cheers
    Lennart

    > \> var targetdoc = doc; // this is the current doc thruout to paste into \> var dummy; // An empty document doesn't accept an insert by copying. \> \> if(!targetdoc->GetFirstObject()) // so if the targetdoc is empty we add a dummy \> { \> dummy = AllocObject(Onull); \> doc->InsertObject(dummy,NULL,NULL); \> } \> \> //Now open your new document ("source document") and clone the first object. \> LoadDocument(fn); // <- Your choice in what way to open it \> var sourcedoc = GetFirstDocument(); // A new doc is the first in the list \> var clone     = sourcedoc->GetFirstObject()->GetClone(CL_NO_TRACKS); \> targetdoc->InsertObject(clone,NULL,NULL); \> targetdoc->Message(MSG_UPDATE); \> KillDocument(sourcedoc); // close the sourcedocument \> \> if(dummy) dummy->Remove(); // Get rid of the dummy if any \>



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 15/02/2009 at 10:23, xxxxxxxx wrote:

    You have to be aware of the fact, that an object can't be in two documents at the same time, Gambetti. Therefore, also make a clone! I think that's what'S causing your crashes.

    By the way, there is an OpenSource Coffee plugin, that I wrote some time ago, that does quite exactly what you are trying to do.

    Look here:
    ExplodeSceneon C4D Wiki

    The article is in German, but all comments in the code are in English, so it should be easy to understand.

    Cheers,
    Jack



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 15/02/2009 at 10:42, xxxxxxxx wrote:

    Just to add further, if you were intending on actually 'removing' the object from the source document and inserting into the destination document, you must obj->Remove() first to remove it from the source document. So either clone as c4dJack mentions to get a copy to insert or remove/insert the original into the destination.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 15/02/2009 at 12:48, xxxxxxxx wrote:

    Will the object still be there to be inserted into a new document, after it has been removed from the old document? If the COFFEE "Remove()" is about the same as "Free()" in C++, it will be gone before you can insert it anywhere else.

    Greetings,
    Jack



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 15/02/2009 at 13:00, xxxxxxxx wrote:

    Remove() simply removes it from the document object list. It must be freed if not inserted into a document afterwards.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 15/02/2009 at 14:34, xxxxxxxx wrote:

    Thanks for your replies everybody!

    I've tried Lennart's solution and it works like a charm! As this didn't get the materials of the object, here's what I did to copy the materials too (as long as equally named materials aren't in the target document already) restoring their assignment to the objects' texure tags. Maybe there's a better solution to get the right tag of the object than to count them, but it works at least.

    > \>      var targetMat;     // object's material in new document \>      var matTag = sourcedoc->GetFirstObject()->GetFirstTag();     // first tag of source-object \>      var matTagNr = 0;     // source-object's tag counter \>      while(matTag){     // iterate through source-object's tags \> \>           matTagNr++; \>           if(instanceof(matTag, TextureTag)){     // copy texture-tags only \> \>                var mat = sourcedoc->FindMaterial(matTag->GetMaterial());     // look up the texture's material name \>                targetMat = targetdoc->FindMaterial(mat->GetName());     // search material with this name in target document \>                if(!targetMat){     // if not found -> copy material to target document \> \>                       targetMat = mat->GetClone(); \>                       targetdoc->InsertMaterial(targetMat,NULL); \>                } \>                var targetTag = clone->GetFirstTag();     // first tag of source-object \>                var targetTagNr = 1; \>                while(targetTagNr < matTagNr){     // iterate through source-object's tags until the tag-counters are equal \> \>                     targetTagNr++; \>                     targetTag = targetTag->GetNext(); \>                } \>                targetTag->SetMaterial(targetMat->GetMarker());     // set texture-tag of copied object to corresponding material \>           } \>           matTag = matTag->GetNext(); \>      } \>

    Cheers,
    Gambetti


Log in to reply