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

    Use GetDataInstance - Dont use GetDataInstance?

    Scheduled Pinned Locked Moved PYTHON Development
    14 Posts 0 Posters 1.2k 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 16/04/2012 at 06:45, xxxxxxxx wrote:

      Thanks Niklas

      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/04/2012 at 11:55, xxxxxxxx wrote:

        Before you read this answer you should should read the chapter "NodeData Management" in the Python SDK.

        For programmers who write an object:

        A programmer of an object, tag, material... has two possibilities to store data for an object. The most used place is the data
        container which is in the BaseList2D (controller) object that can be accessed via GetDataInstance. There you can store
        floats, strings, integers, etc.

        But sometimes you want to have more control over data that is written/read to/from your object, e.g:

        \- to limit values that are passed to the object.
        \- to make values dependend on each other, maybe that data ABC can never be higher than XYZ
        

        - the structure does not fit in a data container

        (just three of many examples why you don't put data in the data container). Therfore you can set/get
        data in/from the underlying NodeData structure which is established with the BaseList2D (controller) object.

        In C++ you can do this by overriding GetDParameter/SetDParamter, this is not possible in Python yet.

        For programmers who want to access data of an object:

        What does that mean for a programmer who wants to access the data of an object? GetDataInstance() is a member of
        BaseList2D and just returns the data container of the "controller" object. This is a fast but unsafe because
        you don't always know where the programmer stores the data for this ID.

        With GetDataInstance() you just have access to this container and no access to data in the NodeData structure.
        So when you call GetDataInstance().GetString(MEMBER_123) and the data is stored in the underlying
        NodeData structure you can't read it.

        The function call which garantuess to extract data from the data container OR the underlying NodeData structure is
        BaseList2D::GetParameter/SetParameter in C++ and BaseList2D.__getitem__/__setitem__ in Python. So you should always access this.

        In the GetContour() example it would indeed be more consistent to write:

        op1[c4d.SPLINEOBJECT_INTERPOLATION] = op2[c4d.SPLINEOBJECT_INTERPOLATION] # safe
        bc1.SetLong(c4d.SPLINEOBJECT_INTERPOLATION, bc2.GetLong(c4d.SPLINEOBJECT_INTERPOLATION)) # fast but unsafe
        

        When you execute this example you see that for instance LIGHT_NOISETYPE is not part of the data container.

        import c4d
          
        light = c4d.BaseObject(c4d.Olight)
        for index, value in light.GetDataInstance() :
            if index == c4d.LIGHT_NOISETYPE:
                print "found" # will never be printed
          
          
        bc = op.GetDataInstance()
        bc.SetLong(c4d.LIGHT_NOISETYPE, c4d.LIGHT_NOISETYPE_VISIBLE) # has no effect
          
        op[c4d.LIGHT_NOISETYPE] = c4d.LIGHT_NOISETYPE_VISIBLE # works as it works as GetParameter in C++
        

        I hope this helps a bit.

        Cheers, Sebastian

        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/04/2012 at 12:42, xxxxxxxx wrote:

          It all helps to fill in the blanks  - cheers for the pointers (no pun intended)

          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/04/2012 at 13:13, xxxxxxxx wrote:

            @Sebastian: Interesting, thank you! I think this enlightens my knowledge a little more. I was always
            wondering how, just for example, the Dynamics tag interacts with the Cloner object (as it doesn't
            seem to be possible by modifieng the cache directly). I guess that is the way the information is being
            exchanged between the Cloner and the Tag (using Get~()/SetParameter())? Please correct me if I'm
            wrong.

            Thanks,
            Niklas

            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/04/2012 at 14:26, xxxxxxxx wrote:

              Thanks Sebastian for the info.

              So using GetDataInstance() is no problem (other than future compatibility) when:
              - Creating an object from scratch (point by point) with my own functions, AND,
              - I only use my own parameters (no includes), AND,
              - I need the fastest possible speed for calculations.

              Right?

              (I have a few of those "ABC can't bigger than XYZ when…" but they are
              taken care of post reading the container into the functions.)

              Cheers
              Lennart

              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 17/04/2012 at 13:46, xxxxxxxx wrote:

                Topic-push 'cause offc. SDK guys often only see the top post.

                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 18/04/2012 at 01:37, xxxxxxxx wrote:

                    
                  So using GetDataInstance() is no problem (other than future compatibility) when:   
                  - Creating an object from scratch (point by point) with my own functions, AND,   
                  - I only use my own parameters (no includes), AND,   
                  - I need the fastest possible speed for calculations.   
                    
                  Right?   
                  

                  I would use BaseList2D.__setitem__ to be on the safe side.

                  Cheers, Sebastian

                  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 18/04/2012 at 04:29, xxxxxxxx wrote:

                    Thanks again. So, sorry to be ignorant (not understanding).

                    When you say " BaseList2D.__getitem/__setitem__" that is the same as using:

                      
                    def Init(self,op)   
                         op[c4d.MY_ID] = 123   
                         return True   
                      
                    def Execute(self…. etc)   
                         myvalue = op[c4d.MY_ID]   
                    

                    ?
                    In other words, exactly the way how to get/set from/to the AM for any object.

                    Cheers
                    Lennart

                    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 18/04/2012 at 04:36, xxxxxxxx wrote:

                      yes, the bracket syntax is the snytax to call __setitem__ and __getitem__. it is explained in the
                      GetParameter thread.

                      https://developers.maxon.net/forum/topic/5284/5286_please-use-getparametersetparameter

                      hadn't we this discussion already a week ago on cgtalk ?

                      http://forums.cgsociety.org/showpost.php?p=7294996&postcount=28

                      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 18/04/2012 at 04:45, xxxxxxxx wrote:

                        I'm asking because I have a follow up of that and that it is still
                        a recommendation only, that's way.

                        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 18/04/2012 at 13:00, xxxxxxxx wrote:

                          littledevil, I'm not trying to be thick or anything,
                          my concern is that while __getitem/setitem__ is recommended now,
                          Sebastian wrote that:
                          "overriding GetDParameter/SetDParamter, this is not possible in Python yet".

                          Which means , for me, that instead of re write a year worth of plugins now,
                          to __set/getitem__ and then only to find out that GetDParameter/SetDParamter
                          is a recommended way.
                          As much as making tools are rewarded/needed, I rather do work that brings
                          food on my table than code. That's all.

                          Cheers
                          Lennart

                          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 18/04/2012 at 13:22, xxxxxxxx wrote:

                            well,

                            i am neither very experienced, nor i have the techincal background to understand fully why we
                            are supposed to use Get/setParameter. I am just following the thread where Rick Barret states,
                            that the bracket syntax aka setitem / getitem is the correct way in python and the equivalent to
                            the c++ Get/SetParameter syntax.

                            the wrong way in python would be to use GetDatainstance and then set the values via Set Type (),
                            just as in c++. if i have understood something wrong with your concerns, forgive my lousy english 
                            please 😉

                            ps : that you are not able to overwrite Get/SetParameter, is only a problem if you are not storing 
                            your plugins data within the plugins bc, or am i mistaken here ?

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