Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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

    How to store BaseShader to HyperFile

    Cinema 4D SDK
    windows python 2024
    2
    7
    1.0k
    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.
    • gheyretG
      gheyret
      last edited by

      I'm trying to store the Shaders created in my plugin into Hyperfile for next use.
      I can store the GetDataInstance() of the shader, but when I encounter layer shader, the internal shaders can't be stored.
      So I'm wondering if I can store the shader directly to the hyperfile.

      www.boghma.com

      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @gheyret
        last edited by ferdinand

        Hey @gheyret,

        Thank you for reaching out to us. To store multiple nodes in a HyperFile, you can use HyperFile.WriteData as GeData can wrap a BaseList2D. The alternative would be to just use C4DAtom.Write or .WriteObject. What to use concretely depends a bit on what you are doing.

        In general I would also avoid serializing nodes myself, but in some cases it can be necessary, it again depends on the case.

        Cheers,
        Ferdinand

        MAXON SDK Specialist
        developers.maxon.net

        gheyretG 1 Reply Last reply Reply Quote 0
        • gheyretG
          gheyret @ferdinand
          last edited by

          Hi @ferdinand
          Thank you for your reply.
          I try to use HyperFile.WriteData to store my shader and save it on my local path.
          And when I try to read the hyperfile to get that shader, that return None for me.
          This is my test code:

          import c4d
          
          
          key = 12345
          path = "..."
          
          def store_shader(data):
              hf = c4d.storage.HyperFile()
              if hf.Open(ident=key, filename=path, mode=c4d.FILEOPEN_WRITE, error_dialog=c4d.FILEDIALOG_NONE):
                  hf.WriteData(data)
                  hf.Close()
                  return True
              return False
          
          def read_shader():
              hf = c4d.storage.HyperFile()
              if hf.Open(ident=key, filename=path, mode=c4d.FILEOPEN_READ, error_dialog=c4d.FILEDIALOG_NONE):
                  data = hf.ReadData()
                  hf.Close()
                  return data
              return None
          
          
          def main() -> None:
              shader = doc.GetActiveMaterial()[c4d.MATERIAL_COLOR_SHADER]
          
              # this will print True
              print(store_shader(shader))
          
              # this will print None, the shader is missing?
              print(read_shader())
          
          
          if __name__ == '__main__':
              main()
          

          www.boghma.com

          ferdinandF 1 Reply Last reply Reply Quote 0
          • ferdinandF
            ferdinand @gheyret
            last edited by ferdinand

            Hey @gheyret,

            sorry, today is a bank holiday in Germany, I just answered this on the side. This probably means nodes have not been implemented in the Python wrapper for HyerFile.WriteData. I would try my luck with the C4DAtom methods then.

            Cheers,
            Ferdinand

            MAXON SDK Specialist
            developers.maxon.net

            gheyretG 1 Reply Last reply Reply Quote 0
            • gheyretG
              gheyret @ferdinand
              last edited by

              it's okay, It's not a big rush for me.
              Hope you enjoy your holiday.
              Cheers~🍻

              www.boghma.com

              ferdinandF 1 Reply Last reply Reply Quote 0
              • ferdinandF
                ferdinand @gheyret
                last edited by

                Hey @gheyret,

                okay, I had a brief look, and I could not get the shader deserialization to work either. Not sure why, I think I was passing the wrong disk level. This is too much of a complex problem as that I could answer this on the side, we will have a closer look after our company meeting.

                I would recommend to use c4d files in the mean time to store your shaders as materials in a file. Alternatively, you could also store them as assets if you want to get all fancy.

                Cheers,
                Ferdinand

                MAXON SDK Specialist
                developers.maxon.net

                gheyretG 1 Reply Last reply Reply Quote 0
                • gheyretG
                  gheyret @ferdinand
                  last edited by

                  Hi @ferdinand ,

                  Yeah! I'm actually considering saving the shader to .c4d file as well.
                  But it would be great if posible to store BaseList2D in Hyperfile.

                  Thank you!
                  Cheers!

                  www.boghma.com

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