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:
THE DATA TYPE
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 elseis it possible to completely delete a user data?
thanks in advanceps: 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_CUSTOMGUI]=1009059
bc[c4d.DESC_NAME] = name
bc[c4d.DESC_SHORT_NAME] = shortname
bc[c4d.DESC_MIN]=0
bc[c4d.DESC_MAX]=1
bc[c4d.DESC_UNIT]=c4d.DESC_UNIT_PERCENT
bc[c4d.SPLINECONTROL_GRID_H ]=1
bc[c4d.SPLINECONTROL_GRID_V ]=1
bc[c4d.SPLINECONTROL_VALUE_EDIT_H ]=1
bc[c4d.SPLINECONTROL_VALUE_EDIT_V ]=1
bc[c4d.SPLINECONTROL_VALUE_LABELS_H]=1
bc[c4d.SPLINECONTROL_VALUE_LABELS_V]=1
bc[c4d.SPLINECONTROL_X_MIN ]=0
bc[c4d.SPLINECONTROL_X_MAX]=1
bc[c4d.SPLINECONTROL_X_STEPS]=0.001
bc[c4d.SPLINECONTROL_Y_MIN ]=0
bc[c4d.SPLINECONTROL_Y_MAX]=1
bc[c4d.SPLINECONTROL_Y_STEPS]=0.001
bc[c4d.SPLINECONTROL_PRESET_BTN ]=1
bc[c4d.SPLINECONTROL_ROUND_SLIDER ]=1
bc[c4d.SPLINECONTROL_GRIDLINES_H]=0.2
bc[c4d.SPLINECONTROL_GRIDLINES_V]=0.01
bc[c4d.SPLINECONTROL_MINSIZE_H ]=500
bc[c4d.SPLINECONTROL_MINSIZE_V ]=200
bc[c4d.SPLINECONTROL_CUSTOMCOLOR_COL]=c4d.Vector(50,120,250)
bc[c4d.SPLINECONTROL_CUSTOMCOLOR_SET]=1
bc[c4d.SPLINECONTROL_OPTIMAL]=1
bc[c4d.SPLINECONTROL_OPTIMAL_X_MIN]=100
bc[c4d.SPLINECONTROL_OPTIMAL_Y_MIN]=100
bc[c4d.SPLINECONTROL_OPTIMAL_X_MAX]=600
bc[c4d.SPLINECONTROL_OPTIMAL_Y_MAX]=600
bc[c4d.SPLINECONTROL_X_TEXT]="OFFSET"
bc[c4d.SPLINECONTROL_Y_TEXT]="THIKNESS"
bc[c4d.SPLINECONTROL_HIDE_ROUND_SLIDER]=1
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,
Sebastian -
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]) " functionhere is the code:
for id, bc in op.GetUserDataContainer() :
del(op[id])
op.RemoveUserData(id)
c4d.EventAdd()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())) :
op.RemoveUserData(i)
c4d.gui.UpdateMenus()
c4d.EventAdd()
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() :
del(op[id])
op.RemoveUserData(id)
c4d.EventAdd()
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 comparisonI 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:
https://developers.maxon.net/forum/topic/7119/8084_add-userdata-with-details
i found my answer and now it works perfectlyspecificStartingID=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
c4d.EventAdd()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...