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

    How to store data (with a plugin or a script)?

    Scheduled Pinned Locked Moved PYTHON Development
    12 Posts 0 Posters 1.4k 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

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 05/10/2012 at 00:14, xxxxxxxx wrote:

      Hi Rui.
      Thanks for the answer, I kinda was expecting the basecontainer, but honestly I have no idea where to start. So I create a basecontainer like this:

      bc = c4d.BaseContainer()  
      bc.SetString(1, "test")  
      bc.SetId(1234)  
      print bc.GetId()  
      print bc[1]
      

      Easy enough and works without a problem, but how do I store this specific container in the document/file? The SDK says follwoing:

      It is recommended that you use the available containers to store your own values as well. That way they will be automatically saved. However, if you want to store values in the top level of for example an object container, you'll have to use a unique id.

      But I have absolutely no idea how to get an "available container" that will be automatically saved, or how to add to an objects container. Or is adding to an objects container as simple as the follwoing code (given you have an object selected) :

      op[1234] = "test" 
      

      I stumbled yesterday upon this, but it seems way to easy to be the right way. Even if I store a new basecontainer within the document/file, how do I access it. Logical would be doc.GetBasecontainer(id) but there isn't a function like this.
      Thanks in advance.
      Phil

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

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 05/10/2012 at 01:38, xxxxxxxx wrote:

        Hi Phil,

        You can simply store a new BaseContainer in a document:

        doc[123456789] = bc
        

        And in an object:

        op[123456789] = bc
        

        This container can be accessed at any time and is automatically saved.
        Don't forget that BaseDocument and BaseObject are child of BaseList2D, BaseList2D child of GeListNode and GeListNode child of C4DAtom.

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

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 05/10/2012 at 02:08, xxxxxxxx wrote:

          So it is that easy?
          Thank you very much, I will give it a try. One last question: is it possible to delete these containers or reset the allocation?

          doc[123456789] = None
          

          gives me an error: TypeError expected c4d.BaseContainer, not None.

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

            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

            On 05/10/2012 at 02:55, xxxxxxxx wrote:

            Originally posted by xxxxxxxx

            One last question: is it possible to delete these containers or reset the allocation?

            doc[123456789] = None
            

            gives me an error: TypeError expected c4d.BaseContainer, not None.

            It seems calling

            del doc[123456789]
            

            deletes the assigned container.

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

              THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

              On 05/10/2012 at 03:16, xxxxxxxx wrote:

              Thank you very much.

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

                THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                On 12/10/2012 at 04:48, xxxxxxxx wrote:

                Interesting stuff! Don't know why I didn't think of this myself.
                Is there also a way to store arbitrary data (like custom python classes) in a basecontainer? Whenever I try, only a -1.0 float value is stored. In the documentation of the basecontainer object we have a method called GetCustomDataType() but no corresponding set method.

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

                  THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                  On 15/10/2012 at 03:48, xxxxxxxx wrote:

                  Originally posted by xxxxxxxx

                  Is there also a way to store arbitrary data (like custom python classes) in a basecontainer? Whenever I try, only a -1.0 float value is stored. In the documentation of the basecontainer object we have a method called GetCustomDataType() but no corresponding set method.

                  It isn't possible to store Python classes in a container. Custom data types are for example FontData, SplineData, InExcludeData etc. These are special data types that CINEMA recognizes.

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

                    THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                    On 15/10/2012 at 04:01, xxxxxxxx wrote:

                    Thats what I thought! Luckily I've found a workaround by now, that makes it possible to store classes in a basecontainer nevertheless.

                    Python has a standard module called pickle. It serializes Python objects into ASCII or binary strings. Because Strings are accepted data types for containers I can store whatever object I want using this technique.
                    If your code relies on speed you should use cPickle, which is written in native C and therefore lightning fast.

                    Hope that helps somebody out there who was struggling with the same problem.

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

                      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                      On 15/10/2012 at 06:23, xxxxxxxx wrote:

                      Make sure you use an ID registered at the plugincafe for assigning the container to. 😉

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

                        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                        On 16/10/2012 at 06:11, xxxxxxxx wrote:

                        Yeah, I actually used an ID of 1 when trying this out, but using the plugins (registered) ID is probably the way to go. 🙂

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