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/Write nodes (including hierarchy)

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 292 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 20/10/2016 at 09:39, xxxxxxxx wrote:

      I still can not figure out how to use C4DAtom.Read(). It appaers that writing the node is easy, but how
      do your read it back in? The snippet below doesn't work. Although the Read() method returns True, the
      material doesn't reflect the same properties as the one that I wrote (ie. I changed the name and added
      a shader to the color channel).

      import c4d
      mat = doc.GetActiveMaterial()
        
      # Write the material into the MemoryFileStruct
      mem = c4d.storage.MemoryFileStruct()
      mem.SetMemoryWriteMode()
      hf = c4d.storage.HyperFile()
      hf.Open(0, mem, c4d.FILEOPEN_WRITE, c4d.FILEDIALOG_NONE)
      mat.Write(hf)
        
      # Read the material from the MemoryFileStruct.
      data, size = mem.GetData()
      mem = c4d.storage.MemoryFileStruct()
      mem.SetMemoryReadMode(data, size)
      hf = c4d.storage.HyperFile()
      hf.Open(0, mem, c4d.FILEOPEN_READ, c4d.FILEDIALOG_NONE)
        
      mat = c4d.BaseMaterial(c4d.Mmaterial)
      result = mat.Read(hf, c4d.Mmaterial, 0) # << What to do here?
        
      print(result)
      print(mat)
      print(mat.GetFirstShader())
      

      Any help would be very much appreciated.

      Thanks

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

        On 21/10/2016 at 04:47, xxxxxxxx wrote:

        Hello,

        can you share some information on what you want to achieve? C4DAtom.Read() and Write() are pretty low level function are typically only used internally and are not recommended for third party developers. I'm not sure if these functions can even be utilized properly in plugins.

        You could save a Material by storing it in a BaseDocument and save and load this document with the appropriate SaveDocument() and LoadDocument() functions.

        best wishes,
        Sebastian

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

          On 25/10/2016 at 03:49, xxxxxxxx wrote:

          Hi Sebastian,

          I currently use the workaround with a BaseDocument, but it feels a bit hacky.
          And it also increases filesize. And on top of that I am curious how to use the Read() method(s)
          correctly, anyway. I just want to write a material (and of course all of its shaders) into a file, nothing
          more.  Eventually it would make things easier than using the BaseDocument workaround, assuming
          you can utilize the Read() method properly from a plugin.

          A page in the SDK that describes how to use Read()/Write() or  the BaseDocument workaround would
          be very nice (preferring the former or a description of both).

          Thanks,
          Niklas

          PS: I'm actually using C++ but I get the same behaviour in Python for the above snippet.

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