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
    • Recent
    • Tags
    • Users
    • Login
    The Maxon SDK Team is currently short staffed due to the winter holidays. No forum support is being provided between 15/12/2025 and 5/1/2026. For details see Maxon SDK 2025 Winter Holidays.

    Write/Read BaseLinks

    Scheduled Pinned Locked Moved SDK Help
    2 Posts 0 Posters 232 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

      On 04/08/2013 at 02:23, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   R14/R15 
      Platform:      
      Language(s) :     C++  ;

      ---------
      I'm trying to write a BaseLink to a HyperFile

      struct ProxyItem {
              Matrix mg;
              Vector size;
              AutoAlloc<BaseLink> link;

      ProxyItem() { }

      ProxyItem(const ProxyItem& item) {
                  mg = item.mg;
                  size = item.size;
                  link->SetLink(item.link->ForceGetLink());
              }

      Bool Write(HyperFile* hf) {
                  if (!hf->WriteMatrix(mg)) return FALSE;
                  if (!hf->WriteVector(size)) return FALSE;
                  if (!link->Write(hf)) return FALSE;
                  return TRUE;
              }

      Bool Read(HyperFile* hf, LONG level) {
                  if (!hf->ReadMatrix(&mg)) return FALSE;
                  if (!hf->ReadVector(&size)) return FALSE;
                  if (!link->Read(hf)) return FALSE;
                  return TRUE;
              }

      BaseObject* GetLink(BaseDocument* doc) const {
                  return (BaseObject* ) link.GetLink(doc, Obase);
              }

      void SetLink(BaseObject* op) {
                  link.SetLink(op);
              }

      };

      But the resulting link always looses its connection (so I always get NULL). I now use a
      BaseContainer as a workaround which works fine. I'd rather use the BaseLink directly, though!

      struct ProxyItem {
              Matrix mg;
              Vector size;
              BaseContainer linkbc;

      ProxyItem() { }

      ProxyItem(const ProxyItem& item) {
                  mg = item.mg;
                  size = item.size;
                  linkbc = item.linkbc;
              }

      Bool Write(HyperFile* hf) {
                  if (!hf->WriteMatrix(mg)) return FALSE;
                  if (!hf->WriteVector(size)) return FALSE;
                  if (!hf->WriteContainer(linkbc)) return FALSE;
                  return TRUE;
              }

      Bool Read(HyperFile* hf, LONG level) {
                  if (!hf->ReadMatrix(&mg)) return FALSE;
                  if (!hf->ReadVector(&size)) return FALSE;
                  if (!hf->ReadContainer(&linkbc, TRUE)) return FALSE;
                  return TRUE;
              }

      BaseObject* GetLink(BaseDocument* doc) const {
                  return (BaseObject* ) linkbc.GetLink(1000, doc, Obase);
              }

      void SetLink(BaseObject* op) {
                  linkbc.SetLink(1000, op);
              }

      };

      Any ideas?

      Thanks

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

        On 06/08/2013 at 07:31, xxxxxxxx wrote:

        Howdy,

        It may be losing the pointer to the link due to not implementing a "CopyTo()" function. If you look at the NodeData class you'll see that it implements Read(), Write() and CopyTo() functions. The CopyTo() function is necessary to make sure you don't lose the data in member variables, when copies are made.

        Remember that when something is added to the Undo stack, it actually replaces the old one with a new copy and puts the old one on the Undo stack. BaseContainers are automatically handled internally for this, but you have to handle member variables yourself.

        I'm not exactly sure how you'd implement a CopyTo() function in your own custom structure, though. You may need to create a MessageData, or SceneHookData plugin specifically to handle your structure's CopyTo() function call.

        Adios,
        Cactus Dan

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