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
    • Register
    • Register
    • Login

    save/keep cache of generator plugin

    Cinema 4D SDK
    2025 python windows
    3
    5
    427
    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.
    • D
      datamilch
      last edited by

      hi there,
      i've built a python generator, where i use its cache unless some parameters are dirty. when close and reopen the scene, the cache is gone and has to be rebuild. in principal, is there (not too complicated) way to keep/save these caches inside the scene?
      would this be possible with a python generator or a proper plugin?
      i'm using python.

      to be a bit more specific: by clicking a checkbox on the python generator, i do a cloth simulation in a temp doc. the result of the sim is convertet to polygons and returned by the python generator. the simulation is not super heavy, but it woud be nice if i could avoid the recalculation. so i'd like to store the point data in the scene/generator. i'd like to avoid external files too, if possible.

      my code is a bit long at the moment, i would post a shorter version, if you say it should be possible ...
      best, sebastian

      1 Reply Last reply Reply Quote 1
      • P
        pyr
        last edited by

        I would also be interested.

        I cache all kinds of things, but not the mesh at the end.

        #         check if any dependency changed
            def CacheCheck(self, op, doc):
        
        
                """
        
                :param op:
                :param doc:
                :return:
                """
        
                if op[res.GRIDDER_CACHE] is not None:
        
                    preOption = op[res.GRIDDER_CACHE].GetString(1001)
                    preNoise = op[res.GRIDDER_CACHE].GetFloat(1002)
                    preField = op[res.GRIDDER_CACHE].GetFloat(1003)
                    preFrame = op[res.GRIDDER_CACHE].GetFloat(1004)
        
                    rd = doc.GetActiveRenderData()
                    self.rs.SetStartFrame(rd[c4d.RDATA_FRAMEFROM].GetFrame(doc.GetFps()))
        
                    force = op[res.GRIDDER_EVERYFRAME]
                    frame = doc.GetTime().GetFrame(doc.GetFps())
                    noise, shaderAnimated = self.CacheShader(op, doc)
        
                    if force is 1 and preFrame != frame:
                        return False
        
                    if preOption != self.HelperGetOptions(op):
                        return False
        
                    if preNoise != noise:
                        return False
        
                    field = self.CacheField(op, doc)
        
                    if preField != field:
                        return False
        
                    return True
        
                return False
        
        #-----------------------------------------------------------------
        # after everything is calculated:
                bc = c4d.BaseContainer()
        
                bc.SetData(1001, self.HelperGetOptions(op))
                bc.SetData(1002, self.CacheShader(op, doc)[0])
                bc.SetData(1003, self.CacheField(op, doc))
        
                if doc != None:
                    bc.SetData(1004, frame)
        
                op[res.GRIDDER_CACHE] = bc
        
        
        1 Reply Last reply Reply Quote 0
        • i_mazlovI
          i_mazlov
          last edited by

          Hi Sebastian,

          FYI I'll get to answer your posting beginning next week.

          Cheers,
          Ilia

          MAXON SDK Specialist
          developers.maxon.net

          i_mazlovI 1 Reply Last reply Reply Quote 0
          • i_mazlovI
            i_mazlov @i_mazlov
            last edited by

            Hi Sebastian,

            Sorry for the delay.

            I'm afraid you're quite limited with the python generator, when it comes to storing your data, so the general suggestion would be switching to using the plugin. This way you could just override the NodeData.Read, NodeData.Write and NodeData.CopyTo to store and load your data using the HyperFile. For the more information on the NodeData.Read/Write function you could check the C++ manual.

            Let me know you have any other questions!
            Cheers,
            Ilia

            MAXON SDK Specialist
            developers.maxon.net

            1 Reply Last reply Reply Quote 0
            • P
              pyr
              last edited by

              Could you provide an snipped where you show how to cache it in a plugin?

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