Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bl_info = {
- "name": "crease-set-editor",
- "description": "Add and manage crease sets within Blender",
- "author": "Tom Paul",
- "version": (0,1),
- "blender": (2,80,0),
- "warning": "",
- "tracker_url": "",
- "category": "Modelling"
- }
- import bpy
- from bpy.props import (IntProperty,
- BoolProperty,
- StringProperty,
- CollectionProperty,
- PointerProperty)
- from bpy.types import (Operator,
- Panel,
- PropertyGroup,
- UIList)
- class CUSTOM_OT_actions(Operator):
- bl_idname = "custom.list_action"
- bl_label = "List Actions"
- bl_description = "Move items up and down, add and remove"
- bl_options = {'REGISTER'}
- 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.move(idx, idx+1)
- scn.custom_index += 1
- info = 'Item "%s" moved to position %d' % (item.name,scn.custom_index + 1)
- self.report({'INFO'}, info)
- elif self.action == 'UP' and idx >= 1:
- item_prev = scn.custom[idx-1].name
- scn.custom.move(idx, idx-1)
- scn.custom_index -= 1
- info = 'Item "%s" moved to position %d' % (item.name, scn.custom_index + 1)
- self.report({'INFO'}, info)
- elif self.action == 'REMOVE':
- item = scn.custom[scn.custom_index]
- item_name = item.name
- info = '%s removed from scene' % (item_name)
- scn.custom.remove(idx)
- if scn.custom_index == 0:
- scn.custom_index = 0
- else:
- scn.custom_index -= 1
- self.report({'INFO'}, info)
- if self.action == 'ADD':
- item = scn.custom.add()
- item.id = len(scn.custom)
- item.name = "Crease %d" % (item.id)
- scn.custom_index = (len(scn.custom)-1)
- info = '%s added to list' % (item.name)
- self.report({'INFO'}, info)
- return {"FINISHED"}
- class CUSTOM_OT_clearList(Operator):
- bl_idname = "custom.clear_list"
- bl_label = "Clear Crease List"
- bl_description = "Clear all items of the list and remove from scene"
- bl_options = {'INTERNAL'}
- @classmethod
- def poll(cls, context):
- return bool(context.scene.custom)
- def invoke(self,context,event):
- return context.window_manager.invoke_confirm(self, event)
- def execute(self, context):
- if bool(context.scene.custom):
- context.scene.custom.clear()
- self.report({'INFO'}, "List Cleared")
- else:
- self.report({'INFO'}, "Nothing to remove")
- return{'FINISHED'}
- class CUSTOM_UL_items(UIList):
- def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
- if self.layout_type in {'DEFAULT', 'COMPACT'}:
- split = layout.split(factor=1)
- split.label(text = "Crease %d" % (index+1))
- def invoke(self, context, event):
- pass
- class CUSTOM_PT_objectList(Panel):
- bl_idname = 'CREASE_PT_my_panel'
- bl_label = "Custom Crease List"
- bl_space_type = "VIEW_3D"
- bl_region_type = "UI"
- bl_category = "Crease Manager"
- def draw(self, context):
- layout = self.layout
- scn = bpy.context.scene
- rows = 2
- row = layout.row()
- row.template_list("CUSTOM_UL_items", "custom_def_list", scn, "custom", scn, "custom_index", rows=rows)
- col = row.column(align = True)
- col.operator("custom.list_action", icon='ADD', text = "").action = 'ADD'
- col.operator("custom.list_action", icon='REMOVE', text = "").action = 'REMOVE'
- col.separator()
- col.operator("custom.list_action", icon='TRIA_UP', text = "").action = 'UP'
- col.operator("custom.list_action", icon='TRIA_DOWN', text = "").action = 'DOWN'
- row = layout.row()
- col = row.column(align=True)
- row = col.row(align=True)
- row.operator("custom.clear_list", icon="X")
- classes = (
- CUSTOM_OT_actions,
- CUSTOM_OT_clearList,
- CUSTOM_UL_items,
- CUSTOM_PT_objectList
- )
- def register():
- from bpy.utils import register_class
- for cls in classes:
- register_class(cls)
- bpy.types.Scene.custom_index = IntProperty()
- def unregister():
- from bpy.utils import unregister_class
- for cls in reversed(classes):
- unregister_class(cls)
- del bpy.types.Scene.custom_index
- if __name__ == "__main__":
- register()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement