I wrote an addon with several UI Lists. In Blender 3.2, I had no trouble scrolling down the list if it became longer than the box on the screen. However, I recently switched to Blender 3.3.6 and I realized that I can't scroll down if my UI List is long enough. The scroll bar appears on the right side, but if I try to move it, the list does not scroll. Here is an excerpt from my code:
bl_info = {
"name": "UI LIST Test_Addon",
"blender": (3, 3, 6),
"description": "UI List does not scroll",
"warning": "",
}
import bpy
from bpy.props import StringProperty, BoolProperty, FloatProperty, IntProperty, CollectionProperty
from bpy.types import UIList, Operator, Panel
class CustomListItem(bpy.types.PropertyGroup):
objectName: StringProperty()
class LIST_OT_NewItem(Operator):
"""Add a new item to the list."""
bl_idname = "my_list.new_item"
bl_label = "Add a new item"
list_name: StringProperty(name="list_name")
def execute(self, context):
item_list=eval("context.scene."+self.list_name+"_list")
item_value=eval("context.scene."+self.list_name+"_item")
item=item_list.add()
item.name = str(item_value)
return{'FINISHED'}
class LIST_OT_DeleteListItem(Operator):
"""Delete the selected item from the list."""
bl_idname = "my_list.delete_list_item"
bl_label = "Deletes an item"
@classmethod
def poll(cls, context):
# item_list=eval("context.scene."+self.list_name+"_list")
# print(bool(item_list))
return True
list_name: StringProperty(name="list_name")
def execute(self, context):
item_list=eval("context.scene."+self.list_name+"_list")
index=eval("context.scene."+self.list_name+"_index")
item_list.remove(index)
index = min(max(0, index - 1), len(item_list) - 1)
return{'FINISHED'}
class OBJECT_UL_List(bpy.types.UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
scene = data
if self.layout_type in {'DEFAULT', 'COMPACT'}:
layout.label(text=item.name)
class SCENE_PT_Params(bpy.types.Panel):
"""Creates a Panel in the scene context of the properties editor"""
bl_label = "Define Properties"
bl_idname = "SCENE_PT_def_props"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"
def draw(self, context):
layout = self.layout
scene = context.scene
layout.label(text="Parameters:")
split=layout.split()
col = split.column()
col.label(text="Parameter 1")
col.template_list("OBJECT_UL_List", "",scene,"param1_list",scene,"param1_index")
row=col.row()
row.operator('my_list.delete_list_item', text='',icon='REMOVE').list_name="param1"
row.operator('my_list.new_item', text='',icon='ADD').list_name="param1"
row.prop(scene, "param1_item",text="units")
col = split.column()
col.label(text="Parameter 2")
col.template_list("OBJECT_UL_List", "",scene,"param2_list",scene,"param2_index")
row=col.row()
row.operator('my_list.delete_list_item', text='', icon = 'REMOVE').list_name="param2"
row.operator('my_list.new_item', text='', icon = 'ADD').list_name="param2"
row.prop(scene, "param2_item",text="units")
classes = (OBJECT_UL_List,
LIST_OT_NewItem,
CustomListItem,
LIST_OT_DeleteListItem,
SCENE_PT_Params)
def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.Scene.param1_list = CollectionProperty(type = CustomListItem)
bpy.types.Scene.param1_index = IntProperty(name = "param1_index", default = 0)
bpy.types.Scene.param1_item = FloatProperty(name = "param1_item", default = 500)
bpy.types.Scene.param2_list = CollectionProperty(type = CustomListItem)
bpy.types.Scene.param2_index = IntProperty(name = "param2_index", default = 0)
bpy.types.Scene.param2_item = FloatProperty(name = "param2_item", default = 0.5)
def unregister():
del bpy.types.Scene.param1_list
del bpy.types.Scene.param1_index
del bpy.types.Scene.param1_item
del bpy.types.Scene.param2_item
del bpy.types.Scene.param2_list
del bpy.types.Scene.param2_index
for cls in reversed(classes):
bpy.utils.unregister_class(cls)
if __name__ == "__main__":
register()
I wrote my code starting with the example here: https://sinestesia.co/blog/tutorials/using-uilists-in-blender/, and the example scrolls properly. I've compared the two codes and I do not understand why the example in the tutorial scrolls properly and mine does not. I would appreciate any suggestions.