Is it possible to to customise Blender specific data structures?
For example how could I add a python
list data type to a Blender
You can use a CollectionProperty to store a variable amount of items like a list, the properties per item need to be declared beforehand:
import bpy class VectorPropGroup(bpy.types.PropertyGroup): # name = StringProperty() # this is inherited from bpy.types.PropertyGroup vector = bpy.props.IntVectorProperty(size=3) bpy.utils.register_class(VectorPropGroup) bpy.types.Action.my_collection = bpy.props.CollectionProperty(type=VectorPropGroup) action = bpy.data.actions.new("My Action") item = action.my_collection.add() item.name = "First" item.vector = (1,2,3) item = action.my_collection.add() item.name = "Second" item.vector = (2,3,4) print(action.my_collection.name, action.my_collection.vector[:]) print(action.my_collection.name, action.my_collection.vector[:])
It will print:
First (1, 2, 3) Second (2, 3, 4)
Note that you can't
add() items from within a
draw() method. You need to call it manually (text editor / Python console) or create an operator for the user to be used in a UI.
You can customize data structures with custom properties.
Note that only bpy.types.ID, bpy.types.Bone and bpy.types.PoseBone classes support custom properties.
bpy.types.ID subclasses: WindowManager, Speaker, MetaBall, ParticleSettings, Palette, PaintCurve, Camera, GreasePencil, NodeTree, Material, Mask, Lamp, Sound, Object, Library, Screen, MovieClip, Brush, Mesh, FreestyleLineStyle, Scene, Text, Curve, Lattice, Texture, Image, Armature, Key, Group, VectorFont, Action, World
So Yes, Action will support custom properties
There are several types of custom properties: static, dynamic and ID
For static type the format to store lists in is for example bpy.props.StringProperty(), so any data needs to be encoded into string and then decoded.
For ID type you can use lists and dictionaries but lists may only contain floats and integers. Also they are declared only for single datablock.
The dynamic accept functions and are not stored with blend file.