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

  • Hi,

    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.

  • @m_adam

    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!

Log in to reply