What is the best practice way to store a python list defined in an addon as a scene variable in Blender?
Using
global mylist
doesn't work because the variable is not a Blender-specific type and therefore not saved after a button click operation completes. I would like the list to exist in the Blender environment so that I can access it from future function calls.
My current solution is to use Blender Collection Properties, with my own wrapper functions, but this seems kind of excessive:
bpy.types.Object.CP_list = bpy.props.CollectionProperty(type=bpy.types.PropertyGroup)
def CollectionProperty2list(CP, numerical = False):
new_list = []
if (numerical):
for elt in CP:
new_list.append(float(elt.name))
else:
for elt in CP:
new_list.append(elt.name)
return (new_list)
def list2CollectionProperty(mylist, CP):
CP.clear()
for elt in mylist:
CP.add().name = str(elt) # stores string for numerical or string input
return()
storing:
list2CollectionProperty(py_list, obj.CP_list)
retreiving:
py_list = CollectionProperty2list(obj.CP_list)