Solved Changing the syntax from "SetString" to "Brackets" type


DISCLAIMER: This might be a trivial matter but I hope you'll hear me out.

I'm trying to add a userdata with a dropdown list. Much like this interface in Maya (

I managed to do that with the help of this blog. I modified it and it works as expected but my concern is it is using a "SetString" type rather than "Brackets" type. See illustration below.

So instead of
bc[c4d.DESC_NAME] = "Name"
It uses
bc.SetString(c4d.DESC_NAME, "Name")

I would prefer the former as my previous codes are written like that.

In the code below, I inserted a # comment line for the things that I'd like to be revised.

    con = c4d.BaseObject(5181)

    bc = c4d.GetCustomDataTypeDefault(c4d.DTYPE_LONG)
    bc[c4d.DESC_NAME] = "spaceSwitch"
    # how to change to bracket type
    test = c4d.BaseContainer()
    test.SetString(1, "head")
    test.SetString(2, "chest")
    bc.SetContainer(c4d.DESC_CYCLE, test)
    # how to change to bracket type
    descID = con.AddUserData(bc)
    con[c4d.ID_USERDATA, descID[1].id]=1

Thank you for looking at my problem.

Hi @bentraje,

[] bracket operator in a case of a BaseList2D is an alias for Set/GetParameter.
[] bracket operator in a case of BaseContainer is an alias for SetData / GetData, see __setitem__ and __getitem__.

So you can use them directly.

test = c4d.BaseContainer()
test[1] = "head"
test[2] = "chest"
bc[c4d.DESC_CYCLE] = test

Hope it make sense.


Interesting. I never knew about the bracket operator being different on a BaseList2D and the BaseContainer.

Thank you for the response. Works as expected. Have a great day ahead!

Hi @m_adam

Sorry for reviving the thread.

But I just want to clarify how do I use the Set methods for an existing UserData.
Basically, a reverse from the question above.

Currently, I have this bracket type code:

space_switch_obj[c4d.ID_USERDATA,3] = 0

I want to change it to a Set method with this one:


It does not error out but also it doesn't set the parameter to zero.
My logic for the [2] is because it is the third user data with zero being the first
For the [1] is because it is the base container.
For the [3] is because it matches with the [c4d.ID_USERDATA,3] .

Is there a way around this?

I'd like to provide you screenshot on the result of the GetUserDataContainer but it's hard to represent since the console do not wrap its result. So the result is a bit long

GetUserDataContainer() returns the BaseContainer that stores the user data description. This BaseContainer does not store the user data values.

The user data values are stored with the host object and must be accessed using a DescID with c4d.ID_USERDATA. See the DescID Manual.


Thanks for the response.
Unfortunately, the C++ manual is all foreign to me. The Python documentation doesn't have as many examples compared to the C++.

Anyway, on the page you referred on the section
"User data parameters are stored in a sub-container with the ID ID_USERDATA."

It doesn't have any examples to change parameters but only to get them which is GetParameter. So I guess the proper method would be SetParameter instead of SetFloat?

If so, how do I use the SetParameter?
It requires parameters of (id, param, groupid).

@bentraje The access for userdata is indeed through Get/SetParameter. The needed DescID is constructed by two DescLevels, the first being a (constant) DescLevel for UserData, the second being the ID and type of the specific userdata entry that you look for:

import c4d
from c4d import gui

def main():
    print "---------------------------"

    userdata_entry = 1 # your ID of the userdata

    # construct a DescID for user data
    dId = c4d.DescID(c4d.DescLevel(c4d.ID_USERDATA, c4d.DTYPE_SUBCONTAINER), c4d.DescLevel(userdata_entry,c4d.DTYPE_LONG))

    # read the user data value
    print op.GetParameter(dId, c4d.DESCFLAGS_GET_NONE)

    # write user data value
    userdata_new_value = 42

    # list all user data definitions (not values)
    for id, bc in op.GetUserDataContainer():
        print id, bc # pry apart bc for the exact definition (types, min, max...)

if __name__=='__main__':

This script assumes that your op has a userdata element with the ID 1 which is an integer.
I didn't add the third value for the DescLevels which is 0 in both cases.

@bentraje You find also some information in this discussion: Miscellaneous questions about "BaseContainer","DescID" etc


Thanks for the code. It works as expected.


Thanks for the reference. Reading it at the moment and the whole base container is much more complicated than I thought it would be.