storing custom data

Hi all,

I need to store custom data in the scene, mostly lists like this:
mylist=[[12,15,94],[65,95,23], …]

i’ve tried to use something like bpy.types.Scene.Mylist = EnumProperty(item,name)

but it do not work… “item” must contain only strings, not numerics.

is there a way to store arrays of floats in the scene ?

Cobbled this together from http://www.blender.org/documentation/blender_python_api_2_57_release/bpy.props.html


import bpy
from mathutils import Vector


# Assign a collection
class SceneSettingItem(bpy.types.PropertyGroup):
    name = bpy.props.StringProperty(name="Test Prop", default="Unknown")
    vec = bpy.props.FloatVectorProperty(name="vec", default=Vector([0,0,0]))

bpy.utils.register_class(SceneSettingItem)

bpy.types.Scene.vecs = \
    bpy.props.CollectionProperty(type=SceneSettingItem)

print("Adding 2 values!")
obj = bpy.context.object

my_item = bpy.context.scene.vecs.add()
my_item.name = "Location"
my_item.vec = obj.location

my_item = bpy.context.scene.vecs.add()
my_item.name = "Scale"
my_item.vec = obj.scale

for my_item in bpy.context.scene.vecs:
    print(my_item.name, my_item.vec)

If worse comes to worse, JSON encode the list and store on string.

The enum property is a convenient type of property when it comes to user interface or operator stuff when it comes to providing a set of options, which one might be chosen from, but when it comes to storing arbitrary data, the CollectionProperty is what you want.
Judging from your example

mylist=[[12,15,94],[65,95,23], …]
IF that is what your needs are mostly like, then you could store IntVectors in a CollectionProperty, since your mylist example elements are both themselves three integers. If you can expect that the number of the length of the list of the integers will always be three, then the default IntVector should store them fine (up to 32 ints or floats per vector).

However, if three ints per mylist element is merely coincidental, maybe you need to be storing collections of collections of ints, not just collections of IntVectors. A custom class foo descended from bpy.types.PropertyGroup, with the properties you want to store PER element, and then a bpy.props.CollectionProperty(type=foo) which you treat somewhat like it is a list( except with special method for adding things to the list). you would register the foo class with blender, then bpy.types.Scene.foos = bpy.props.CollectionProperty(type=foo). to add to the list, bpy.context.scene.foos.add() or n = bpy.context.scene.foos.add()

Hi all,

Thanks for your support and suggestions. I found a way to do it (with a text).