Use GetDataInstance - Dont use GetDataInstance?



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

    On 16/04/2012 at 06:41, xxxxxxxx wrote:

    The example (below) from PY Double Circle uses the GetDataInstance()

    yet
    the post here
    https://plugincafe.maxon.net/topic/5284/5286_please-use-getparametersetparameter

    recommends we don't

    again - I'm confused

    please advise

     def GetContour(self, op, doc, lod, bt) :
            bc = op.GetDataInstance()
            bp = self.GenerateCircle(bc.GetReal(c4d.PYCIRCLEOBJECT_RAD))
            if not bp: return None
            bb = bp.GetDataInstance()
            
            bb.SetLong(c4d.SPLINEOBJECT_INTERPOLATION, bc.GetLong(c4d.SPLINEOBJECT_INTERPOLATION))
            bb.SetLong(c4d.SPLINEOBJECT_SUB, bc.GetLong(c4d.SPLINEOBJECT_SUB))
            bb.SetReal(c4d.SPLINEOBJECT_ANGLE, bc.GetReal(c4d.SPLINEOBJECT_ANGLE))
            bb.SetReal(c4d.SPLINEOBJECT_MAXIMUMLENGTH, bc.GetReal(c4d.SPLINEOBJECT_MAXIMUMLENGTH))
            
            DoubleCircleData.OrientObject(bp, bc.GetLong(c4d.PRIM_PLANE), bc.GetBool(c4d.PRIM_REVERSE))
            
            return bp
    


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

    On 16/04/2012 at 06:43, xxxxxxxx wrote:

    That is for C++, we're in Python here. I guess this doesn't affect us at all as Get~()/SetParameter() isn't even implemented in Python. Use GetDataInstance() when you are aiming to modify the Object's parameters directly, GetData() to obtain a copy of the parameters.



  • 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



  • 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



  • 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)



  • 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



  • 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



  • 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.



  • 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



  • 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



  • 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://plugincafe.maxon.net/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



  • 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.



  • 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



  • 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 ?


Log in to reply