I am trying to store a list of lists in a property with python and am having difficulties. My ultimate objective is identical to this thread: http://blender.stackexchange.com/questions/16511/how-can-i-store-and-retrieve-a-custom-list-in-a-blend-file. However, I was unable to implement the code since the author did not include a complete example and my attempt to execute his explanation failed. Frustratingly, I was unable to comment on this post directly since I did not have enough reputation on the site. Any chance someone can help me out here?
Ok here is the complete code of how I think it’s supposed to go.
import bpy
class subcustomPropertiesGroup(bpy.types.PropertyGroup):
customString = bpy.props.StringProperty()
bpy.utils.register_class(subcustomPropertiesGroup)
class customPropertiesGroup(bpy.types.PropertyGroup):
subLists = bpy.props.CollectionProperty(type=subcustomPropertiesGroup)
bpy.utils.register_class(customPropertiesGroup)
bpy.types.Scene.customLists = bpy.props.CollectionProperty(type=customPropertiesGroup)
bpy.types.Scene.subLists = bpy.props.CollectionProperty(type=subcustomPropertiesGroup)
bpy.context.scene.customLists.clear()
bpy.context.scene.subLists.clear()
bpy.context.scene.customLists.add().name = 'list1'
bpy.context.scene.customLists.add().name = 'list2'
newCustomItem = bpy.context.scene.customLists['list1'].subLists.add()
newCustomItem.customString = "test1"
newCustomItem = bpy.context.scene.customLists['list1'].subLists.add()
newCustomItem.customString = "test2"
newCustomItem = bpy.context.scene.customLists['list2'].subLists.add()
newCustomItem.customString = "test3"
newCustomItem = bpy.context.scene.customLists['list2'].subLists.add()
newCustomItem.customString = "test4"
print('_______________')
for customList in bpy.context.scene.customLists:
print("List: "+customList.name)
for subList in customList.subLists:
print("Property: "+subList.customString)