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

    storing data in memory

    Scheduled Pinned Locked Moved PYTHON Development
    8 Posts 0 Posters 727 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 23/06/2015 at 22:08, xxxxxxxx wrote:

      Hi,

      I'm new to Cinema 4D Python SDK "but familiar with the C++ SDK".
      I have a Python Generator , I'm reading data from files, I need to read data only once "storing it in memory", then use this data in the document "in animation".

      I know that this question is kinda noob, but bare with me.
      what confuses me:
      * the generator will get executed at any frame, so how to make sure that the data is cached in memory so I can safely read it? i.e if it will run every frame, data will get erased after execution right?

      so the behavior is something like this:
      at first run, read files and cache data into memory, at other runs I will handle these data, I ask this question because in C++ this needs a class with Init and possibly some command buttons "too easy to do in C++".

      offtopic:
      in C++ plugin, there is a dll ".cdl64 for example" , and res folder, what is the equivalent in Python plugin?

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

        On 25/06/2015 at 10:18, xxxxxxxx wrote:

        Global variables seems to carry over from frame to frame. Then you just need some kind of test or flag to decide when to execute the read.

          
        import c4d   
        #Welcome to the world of Python   
          
        inputData = -1   
          
        def main() :   
            global inputData   
            fps = doc.GetFps()   
            time = doc.GetTime()   
            frame = time.GetFrame(fps)   
            if frame == 0:   
                print "read"   
                inputData = 2   
          
            print inputData   
        

        An other option is to use an interaction tag and set its language to python. Check out the different events in the example code you get when you set the language. You could use the "message" function to check for document load and execute your read.

        Python plugins are named .pyp

        Cheers
        Bonsak

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

          On 25/06/2015 at 10:37, xxxxxxxx wrote:

          You shouldn't use global variables in a Python Plugin. A second
          instance of your Python Tag Plugin would use the same global
          variable, interfering with the first tag. Global variables in a Python
          Scripting Tag, on the other side, are for visible to that tag only.

          In a Python Plugin, use attributes instead.

            def __init__(self) :
              super(MyTag, c4d.plugins.TagData).__init__()
              self.counter = 0
            def Execute(self, tag, doc, op, bt, priority, flags) :
              print self.counter
              self.counter += 1
              return c4d.EXECUTIONRESULT_OK
          

          -Niklas

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

            On 25/06/2015 at 10:57, xxxxxxxx wrote:

            thanks NirkalsR and bosnak.
            @NiklasR , your approach is what I will do "pretty much similar to C++ class members" , but what I'm missing here is: how does Cinema4D see a Python plugin? "for C++, it requires .cdl64 and res, what does it require for Python?"

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

              On 25/06/2015 at 11:19, xxxxxxxx wrote:

              @Niklas. Didn't know that. Always thought that global in one tag was contained to that tags scope.
              @Mohammed Check out the file and directory structure of some of the examples: https://developers.maxon.net/docs/py/2023_2//help/examples/plugins/Py-LookAtCamera/

              -b

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

                On 25/06/2015 at 11:32, xxxxxxxx wrote:

                @bonask: That is true for a Python Scripting Tag (the one built-in into Cinema where you can edit
                the code live from Cinema 4D) but not for Python Tag Plugins
                @MohamedSakr: A .pyp file which contains the Python source code, or .pypv for a protected Python plugin

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

                  On 29/06/2015 at 03:04, xxxxxxxx wrote:

                  Hello,

                  you find information on the plugin structure and PYP files in the documentation:

                  • Plugin Structure
                    best wishes,
                    Sebastian
                  1 Reply Last reply Reply Quote 0
                  • H Offline
                    Helper
                    last edited by

                    On 29/06/2015 at 16:55, xxxxxxxx wrote:

                    thanks a lot Niklas and Sebastian

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