On 22/01/2018 at 06:29, xxxxxxxx wrote:
With reference to an old Topic
Python Generator and Storing Variables [SOLVED]
(11881)
I need to persist some data over all frames and I wanted to use the suggested op[id] (where id is unique using a plugin id) The generator runs every frame and normal global variables are reset
so initialising the variable dstore at the top = to the unique id if I write:
op[dstore] = 0 #Initialise
or op[dstore] += 1 # To Change, it works fine
(providing I don't change the type)
but if I want to use a BaseContainer as in the example from the old Post:
myData = c4d.BaseContainer()
myData[1] = "something"
myData[2] = "something else"
op[123456] = myData
# something
for data in op[123456]:
print(data)
this works fine to initialise the data and you can read the data as op[123456][2] but you cannot change the data by op[123456][2] = "another' it doesn't error but does not update the value
So referencing another older post:
Initializing compositing-tag problem
(6282)
The only way I could update and persist the data properly was as follows:
Above functions:
dstore = unique integer from plugin-id
To SetUp:
myData = c4d.BaseContainer()
myData[1000] = "something"
myData[2000] = 0
bc=op.GetDataInstance()
opData = bc.GetContainer(dstore)
bc.SetContainer(dstore, myData)
To Change something in the structure:
bc=op.GetDataInstance()
opData = bc.GetContainer(dstore)
opData[2000] = 1
bc.SetContainer(dstore, opData)
This persists and changes the data fine but I wonder if this is the best method? Ideally I would like to use a Dictionary but there is no SetDictionary method
Thanks
Dean