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 (https://www.dropbox.com/s/8d7n77nb7imtnuh/c4d087_enum_list_attribute.jpg?dl=0)
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"
I would prefer the former as my previous codes are written like that.
In the code below, I inserted a
# commentline for the things that I'd like to be revised.
con = c4d.BaseObject(5181) doc.InsertObject(con) bc = c4d.GetCustomDataTypeDefault(c4d.DTYPE_LONG) bc[c4d.DESC_NAME] = "spaceSwitch" bc[c4d.DESC_CUSTOMGUI]=c4d.CUSTOMGUI_CYCLE # 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.id]=1 c4d.EventAdd()
Thank you for looking at my problem.
m_adam last edited by
So you can use them directly.
test = c4d.BaseContainer() test = "head" test = "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!
Sorry for reviving the thread.
But I just want to clarify how do I use the
Setmethods for an existing
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
Setmethod with this one:
It does not error out but also it doesn't set the parameter to zero.
My logic for the
is because it is the third user data with zero being the first
is because it is the base container.
is because it matches with the
Is there a way around this?
I'd like to provide you screenshot on the result of the
GetUserDataContainerbut it's hard to represent since the console do not wrap its result. So the result is a bit long
PluginStudent last edited by
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
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
If so, how do I use the
It requires parameters of
(id, param, groupid).
Cairyn last edited by
@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 op.SetParameter(dId,userdata_new_value,c4d.DESCFLAGS_SET_NONE) c4d.EventAdd() # 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__': 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.
s_bach last edited by
@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.