Hello,
I'd like to save the state of the user data of an object for the user to recall at a later time. What would be the best way to go about this? Rather than trying to navigate through the parent groups, I'd rather store the user data in a base container in its entirety and then use SetUserDataContainer()
to restore it later. Is that possible? As GetUserDataContainer()
returns a list, I'm not able to use BaseContainer's SetContainer()
method as demonstrated in the example below. My first two attempts were discovering that the UserDataContainer from GetUserDataContainer()
is a list and not a Base Container. Thank you for any help you can give!
import c4d
PLUGIN_ID = 1234567
def main(doc):
#get selected object
obj = doc.GetActiveObject()
#get object's base container
bc = obj.GetDataInstance()
#create new container to store user data values
subBc = c4d.BaseContainer()
#get user data container
udc = obj.GetUserDataContainer()
#returns a list: [(((700, 5, 0), (1, 400006001, 0)), <c4d.BaseContainer object at 0x00000271AB6F8870>)]
#ATTEMPT 1: Storing the base container with SetContainer
#subBc.SetContainer(PLUGIN_ID,udc) #TypeError: argument 2 must be c4d.BaseContainer, not list
#ATTEMPT 2: Storing the list by index
#subBc[1000] = udc #TypeError: could not convert 'list'
#ATTEMPT 3: Using the DescID to store the user data's BaseContainers
#for index,item in udc:
# subBc[index] = item #TypeError: __setitem__ expected int, not c4d.DescID
#adding the sub BaseContainer
bc.SetContainer(PLUGIN_ID,subBc)
#update object's BaseContainer
obj.SetData(bc)
#Print the values stored in the object's base container.
for cid, value in bc.GetContainer(PLUGIN_ID):
print cid, value
# Execute main()
if __name__=='__main__':
main(doc)