I'm using the template of UIList in this answer
but the code to move up or down the items in the UIList don't work... do you know the reason?
# ui list item actions
class Uilist_actions(bpy.types.Operator):
bl_idname = "custom.list_action"
bl_label = "List Action"
action = bpy.props.EnumProperty(
items=(
('UP', "Up", ""),
('DOWN', "Down", ""),
('REMOVE', "Remove", ""),
('ADD', "Add", ""),
)
)
def invoke(self, context, event):
scn = context.scene
idx = scn.custom_index
try:
item = scn.custom[idx]
except IndexError:
pass
else:
if self.action == 'DOWN' and idx < len(scn.custom) - 1:
item_next = scn.custom[idx+1].name
scn.custom_index += 1
info = 'Item %d selected' % (scn.custom_index + 1)
self.report({'INFO'}, info)
elif self.action == 'UP' and idx >= 1:
item_prev = scn.custom[idx-1].name
scn.custom_index -= 1
info = 'Item %d selected' % (scn.custom_index + 1)
self.report({'INFO'}, info)
elif self.action == 'REMOVE':
info = 'Item %s removed from list' % (scn.custom[scn.custom_index].name)
scn.custom_index -= 1
self.report({'INFO'}, info)
scn.custom.remove(idx)
if self.action == 'ADD':
item = scn.custom.add()
item.id = len(scn.custom)
item.name = get_activeSceneObject() # assign name of selected object
scn.custom_index = (len(scn.custom)-1)
info = '%s added to list' % (item.name)
self.report({'INFO'}, info)
return {"FINISHED"}