I have defined an Operator class which has a CollectionProperty like this:

class LinkMakeProxy(bpy.types.Operator):
    my_list = bpy.props.CollectionProperty(type=BoolProperty)

First, the type of my_list is a tuple:

(<built-in function CollectionProperty>, {'type': <built-in function BoolProperty>})

which I am having trouble wrapping my head around, since I expected some mutable data-structure with data rather than functions.

My question is, how can I access and update this property from the exec method of the operator? Similar to what is done in the example given here.


The type parameter of CollectionProperty is expecting a subclass of bpy.types.PropertyGroup. So you would need something like:

class MyBool(bpy.types.PropertyGroup):
    bool = BoolProperty()

Then in your operator, you use that type in your CollectionProperty:

my_list = CollectionProperty(type=MyBool)

You add to your collection by using add():

mybool = self.my_list.add()

...which gives you an instance of the PropertyGroup and the properties it contains. Here is an example that makes a list of booleans based on the selected vertices in the active object and prints the list:

import bpy
from bpy.props import CollectionProperty, BoolProperty

class MyBool(bpy.types.PropertyGroup):
    bool = BoolProperty()

class SimpleOperator(bpy.types.Operator):
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"

    def poll(cls, context):
        return context.active_object is not None

    my_list = CollectionProperty(type=MyBool)

    def execute(self, context):
        obj = context.active_object
        for vert in obj.data.vertices:
            mybool = self.my_list.add()
            mybool.bool = vert.select
        for b in self.my_list:
        return {'FINISHED'}

def register():

def unregister():

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.