bug(!?) with creating a list by using CollectionProperty

I wanted to create a List in a Panel where i could add items to and delete them like the list for shape keys for example.

in the properties_data_armature_rigify.py i found a nice example how to do that but somehow it wont work.
i always get the error that an RNA type derived from IDPropertyGroup was expected. unfortunately thats exactly it gets o.O

heres the code:

import bpy
class test(bpy.types.IDPropertyGroup):

mesh = bpy.types.Mesh

mesh.CollectionProperty(attr="testcollection", type=test, name="", description="")
mesh.IntProperty(attr="testcollection_index", default=-1, min=-1, max=100)

class OBJECT_PT_hello(bpy.types.Panel):
    bl_label = "Hello World Panel"
    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"
    bl_context = "object"

    def draw(self, context):
        layout = self.layout

        obj = context.object.data

        row = layout.row()
        layout.template_list(obj, "testcollection", obj, "testcollection_index", rows=1)


compare that to the code in the properties_data_armature_rigify.py in your /scripts/ui/ folder and tell me the difference between my code and the rigify code.
i realy cant spot my mistake

I didn’t have a look at properties_data_armature_rigify.py, but you need to register your test class, before it’s considered a proper rna property. So after your first 3 lines, add: bpy.types.register(test)

argh …

yes i knew it was something completely stupid

thanks :smiley:

it works … im glad it was so easy …


I’m struggling to use the template_list code that you used in the example. If I copy and paste your code blender just crashes…? Did you manage to get it working with just this code?

What version of blender were you using?

Thanks for any help…