dynamic userData issue [SOLVED]

On 16/07/2015 at 05:40, xxxxxxxx wrote:

hi everybody
i'm quite new in python and my English is crap so please be comprehensive
i'm trying to generate user data dynamicly
thanks to scottA examples it works pretty well so far exept one problem:
if I delete a user data(a float slider for example) and create a new one (a spline UD) c4d expect the type of the previous user data like if the type was store somewhere else

is it possible to completely delete a user data?
thanks in advance

ps: since it was not in scottA example I put below the splineUD creation function:

def CreateUserDataSpline(obj, name, parentGroup=None, shortname=None) :
    if obj is None: return False
    if shortname is None: shortname = name
    bc = c4d.GetCustomDatatypeDefault(c4d.DESC_CUSTOMGUI)
    bc[c4d.DESC_NAME] = name
    bc[c4d.DESC_SHORT_NAME] = shortname
    bc[c4d.SPLINECONTROL_X_MIN ]=0
    bc[c4d.SPLINECONTROL_Y_MIN ]=0
    if parentGroup is not None:
        bc[c4d.DESC_PARENTGROUP] = parentGroup
    return obj.AddUserData(bc)

On 17/07/2015 at 01:49, xxxxxxxx wrote:

Hello and welcome,

could you please share the code that shows how exactly you "delete a user data"?

Best wishes,

On 17/07/2015 at 02:52, xxxxxxxx wrote:

hello Sébastian and thanks for your interrest
since my last post I discover the "del(op[id]) " function

here is the code:

for id, bc in op.GetUserDataContainer() :

it seems to work cause if added at the early begining of the code it allow me to avoid the type expected error when I force update
before i had to copy paste the code in a new python generator each time the userdata was a differente type
the problem I m facing now is that not all user data are supose to be changed (and reset ).I have 40 UD generated thrue Python before the Main function that are supposed to stay.
before i had :

specificStartingID=41 # Under this ID I don't want to delete
for i in range(specificStartingID,len(op.GetUserDataContainer())) :
            c4d.SendCoreMessage(c4d.COREMSG_CINEMA, c4d.BaseContainer(c4d.COREMSG_CINEMA_FORCE_AM_UPDATE))

I m not sure the 3 last lines are all necessary it was added when looking for the bug reason

I 'm trying now to find a way to use the :

for id, bc in op.GetUserDataContainer() :
with a condition based on the user data ID but i'm a bit lost cause it's no longer just an ID it's a DESC_ID (from what i understand)
and for some reason i can't retrieve the first element for a comparison

I hope it's clear ,I did my best
please Help Me

On 17/07/2015 at 06:58, xxxxxxxx wrote:

IT WORKS !!!!!!!

thanks to this post:
i found my answer and now it works perfectly

specificStartingID=41      #under this id the UD stay
for id_, bc in op.GetUserDataContainer() :
            rid = id_[id_.GetDepth() - 1].id #the id of the user data(thanks NiklasR)
            if rid >= specificStartingID:
               del(op[id_]) #remove the Type expected
               op.RemoveUserData(id_)# remove the UD

thanks Sébastian for your time anyway I realy appreciate
i'll try to put below the code as an example for dynamic UD creation
(i have to finish it and clean it a bit first)

back to the code...