Getting User Data (DescID issue) [resolved]

  • On 02/05/2014 at 00:38, xxxxxxxx wrote:

    Hey all

    Here's my first post here. Seems there's a great community here!

    I'm currently working on an OSC plugin for C4D which allows you to use c4d as a timelining tool for creative coding purposes. So far it works great, but i'm a little slow at picking up the Python API so far....

    Enumerate all User Data parameters for a c4d.BaseObject, and for each get the name and the current value.


    I have test parameters:
    * brightness (real)
    * resolution (long)
    * name with spaces (%)
    * subgroup (group)
    * testSubGroupMember (%)

    screenshot of User Data

    And if I do:


    i get:

    [((2, 19, 0), <c4d.BaseContainer object at 0x118e17bc8>), ((1, 15, 0), <c4d.BaseContainer object at 0x118e0eae8>), ((4, 19, 0), <c4d.BaseContainer object at 0x118f4e340>), ((5, 1, 0), <c4d.BaseContainer object at 0x118f4e308>), ((6, 19, 0), <c4d.BaseContainer object at 0x118f4e030>)]

    so i'm able to get the name of each parameter by doing like:

    userData = obj.GetUserDataContainer()
    [returns] : brightness

    then i get the name of the 0th parameter, great! so now all I need is the value...

    To get each value, I can use

    print obj[c4d.ID_USERDATA, index ]

    and i can see the correct index from

    [returns] ( 2 , 19, 0)

    which is a DescID, and is useful, because it means I can do

    print obj[c4d.ID_USERDATA, 2 ]
    [returns] : 0.083

    Which is the correct value.

    So far, wonderful!

    So now I have to get that index of 2 out of the DescID, so I would do something like:

    obj[c4d.ID_USERDATA, userData[0][0][0]
    [returns] <c4d.DescLevel object at 0x117c241f8>

    ok, so that wasn't what I wanted, we get a DescLevel instead of a DescId, 
    so let's see if we can get the 2 out of that DescLevel....

    print obj[c4d.ID_USERDATA, userData[0][0][0].id
    [returns] 700

    ok so how do I get the 2 out? I can't see any other accessors which are useful here
    currently the only option i can see is

    idString = obj[c4d.ID_USERDATA, userData[0][0][0].__str__()

    and then performing string operations to get the 2 out of "(2, 19, 0)"
    but that seems crazy. which is where the question come in :).

    how to get the 2 out of the DescID?

    To note, I'm doing this within the context for an plugins.ObjectData and looking at the child objects

    Thank you

  • On 02/05/2014 at 05:05, xxxxxxxx wrote:

    Hi elliotwoods,

    welcome to the Forum.

    Just use the DescID.

    > desc_id = user_data[0][0]
    > print obj[desc_id]

    If you still need the actual user-data index, it is stored at the second position. The first is c4d.ID_USERDATA (700)

    > index = desc_id[1].id

    (the text representation of the DescID is not really helpful.)

    Btw, use str() instead of .__str__().


  • On 03/05/2014 at 21:04, xxxxxxxx wrote:

    thanks Niklas!

    that totally makes sense. not sure why i couldn't see that before

    is there a page anywhere with all the c4d constants btw?
    i'm often finding constants that i can't identify within many different ranges

    so i presume str(obj) is more standard than obj.__str__()
    i'm still new in python

    I managed to get the exact result that I wanted using:

    def GetFirstArg(descID) :
    text = descID.__str__()
    return int(text.lstrip("(").rstrip(")").split(",")[0])

    but this seems much more sensible now.

Log in to reply