I'm trying to create an add-on which changes the number of bpy.types.BoolProperty dynamically along with the context by using bpy.props.CollectionProperty. But, Blender will crash when I changes the status of dynamically created checkbox.
Is there best practice to change the number of properties such as bpy.types.BoolProperty?
To help understanding what I want to do, I will show the whole my codes.
import bpy
from bpy.props import CollectionProperty, BoolProperty
from bpy_extras.io_utils import ImportHelper
bl_info = {
"name": "Collection Property",
"author": "nutti",
"version": (1, 0, 0),
"blender": (2, 91, 0),
"location": "",
"description": "",
"support": "COMMUNITY",
"category": "UV"
}
class BoolPropertyCollection(bpy.types.PropertyGroup):
checked: BoolProperty(name="", default=True)
class TEST_OT_TestOp(bpy.types.Operator, ImportHelper):
bl_idname = "uv.test_op"
bl_label = "Test Op"
bl_description = "Test Operator"
bl_options = {'REGISTER', 'UNDO'}
bool_prop_collection: CollectionProperty(type=BoolPropertyCollection)
bool_prop_list = []
def draw(self, context):
cls = self.__class__
layout = self.layout
cls.bool_prop_list = []
self.bool_prop_collection.clear()
for i in range(200):
item = self.bool_prop_collection.add()
cls.bool_prop_list.append({"name": str(i), "item": item})
for d in cls.bool_prop_list:
layout.prop(d["item"], "checked", text=d["name"])
def execute(self, context):
return {'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
wm.fileselect_add(self)
return {'RUNNING_MODAL'}
def menu_fn(self, _):
layout = self.layout
layout.operator(TEST_OT_TestOp.bl_idname)
def register():
bpy.utils.register_class(BoolPropertyCollection)
bpy.utils.register_class(TEST_OT_TestOp)
bpy.types.TOPBAR_MT_file_import.append(menu_fn)
def unregister():
bpy.types.TOPBAR_MT_file_import.remove(menu_fn)
bpy.utils.unregister_class(TEST_OT_TestOp)
bpy.utils.unregister_class(BoolPropertyCollection)
if __name__ == "__main__":
register()
check
method as another way to dynamically populate based on some user input data. blender.stackexchange.com/questions/203747/… The invoke is run once, check many times. Apologies for missing comment. Congratulations on working it out., Consider adding an answer. $\endgroup$