Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Read a c4d document

    Scheduled Pinned Locked Moved SDK Help
    4 Posts 0 Posters 335 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

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

      On 02/12/2007 at 08:58, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   R10 
      Platform:   Windows  ; Mac  ;  Mac OSX  ; 
      Language(s) :     C++  ;

      ---------
      Hi,
      I have a c4d document ("doc"), I'm trying to load an other c4d document ("doc2"), retrieve the first object of doc2 insert this in "doc", and then close "doc2".

      the equivalent in coffee :

      > _
      >     var doc = GetActiveDocument();     
      >     var f = GeGetStartupPath();
      >     f->AddLast("plugins");
      >     f->AddLast("scene.c4d");
      >     if(GeFileExist(f,FALSE))
      >      {
      >           LoadDocument(f);
      >           var doc2=GetActiveDocument();
      >           var objet = doc2->GetFirstObject();
      >           var newObject=objet->GetClone(CL_NO_TRACKS);
      >           doc->InsertObject(newObject,NULL,NULL);
      >           KillDocument(doc2);
      >      }     
      >                        
      >
      > _

      The file "scene.c4d" is in the plugin directory of Cinema4D folder.

      I can not reproduce it in C++.
      I hope somebody has the solution, thank a lot and sorry for my english,
      xs_yann

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

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

        On 02/12/2007 at 10:00, xxxxxxxx wrote:

        In C++, LoadDocument() returns the new document so you don't have to get it. Best to allocate and use an AliasTrans:

        > AutoAlloc <AliasTrans> trans;
        > if (!trans) return FALSE;
        > BaseDocument* doc2 = LoadDocument(f);
        > if (!doc2) return FALSE;
        > if (trans->Init(doc2))
        > {
        >      BaseObject* objet =     doc2->GetFirstObject();
        >      if (objet)
        >      {
        >           objet = objet->GetClone(COPY_NO_ANIMATION, trans);
        >           if (objet)
        >           {
        >                doc->InsertObject(objet, NULL, NULL);
        >                trans->Translate(TRUE);
        >           }
        >      }
        > }
        > KillDocument(doc2);
        > EventAdd();

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

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

          On 03/12/2007 at 07:25, xxxxxxxx wrote:

          Thank you kuroyume0161 for your help but when I try your code it generate some errors :

          > _
          >         Filename f = GeGetPluginPath();
          >         f.SetFile("scene.c4d");
          >      AutoAlloc<AliasTrans> trans;
          >      if (!trans) return FALSE;
          >      BaseDocument* doc2 = LoadDocument(f);   //error: at this point in file
          >      if (!doc2) return FALSE;
          >      if (trans->Init(doc2)) {
          >           BaseObject* objet = doc2->GetFirstObject();
          >           if (objet) {
          >                objet = objet->GetClone(COPY_NO_ANIMATION, trans); //error : invalid conversion from 'C4DAtom' to 'BaseObject*'
          >                if (objet) {
          >                          doc->InsertObject(objet, NULL, NULL);
          >                          trans->Translate(TRUE);
          >                }
          >           }
          >      }
          >      KillDocument(doc2);
          >      EventAdd();
          >
          > _

          Sorry I'm a beginner, I still sought in the SDK for a short time but I
          found nothing to solve the problem. Thank you again.

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

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

            On 03/12/2007 at 08:13, xxxxxxxx wrote:

            I didn't fill in the FLAGS since you need to determine which ones to 'OR' together. You do have the SDK Help files, correct? Setting this argument to 0L should do.

            BaseDocument* doc2 = LoadDocument(f, 0L, NULL);

            Unlike COFFEE, C++ is a typed language. To convert from one type to another sometimes requires casting (depending upon the direction and extent of change). Since BaseObject is derived from C4DAtom (as are almost all C4D Base classes), just static cast:

            objet = static_cast<BaseObject*>objet->GetClone(COPY_NO_ANIMATION, trans);

            1 Reply Last reply Reply Quote 0
            • First post
              Last post