bl_info = { "name": "Save Selection", "author": "Markus Ewald", "version": (1, 0), "blender": (2, 7, 7), "location": "Object -> Tools -> Misc", "description": "Saves and restores vertex selections", #"warning": "20 Nov 2016", "wiki_url": "", "tracker_url": "", "category": "3D View" } import os import bpy import bmesh mode_set = bpy.ops.object.mode_set # Global variable to hold the list of selected vertex indices vertex_selection = [] class SaveVertexSelectionOperator(bpy.types.Operator): """Remembers the indices of the currently selected vertices""" bl_idname = "object.save_vertex_selection" bl_label = "Short Name" def execute(self, context): global vertex_selection if bpy.context.object.mode == 'EDIT': bm = bmesh.from_edit_mesh(bpy.context.object.data) vertex_selection = [v.index for v in bm.verts if v.select] else: vertex_selection = [v.index for v in bpy.context.active_object.data.vertices if v.select] self.report({'INFO'}, "Saved selection of %d vertices" % len(vertex_selection)) return {'FINISHED'} class RestoreVertexSelectionOperator(bpy.types.Operator): """Reselects those vertices that have been remembered by the SaveVertexSelectionOperator""" bl_idname = "object.restore_vertex_selection" bl_label = "Short Name" def execute(self, context): global vertex_selection bpy.context.tool_settings.mesh_select_mode = (True , False , False) if bpy.context.object.mode == 'EDIT': bm = bmesh.from_edit_mesh(bpy.context.object.data) # Deselect everything for v in bm.verts: v.select = False for e in bm.edges: e.select = False for f in bm.faces: f.select = False # Restore saved selection for i in vertex_selection: bm.verts[i].select = True else: # Deselect everything for v in bpy.context.active_object.data.vertices: v.select = False for e in bpy.context.active_object.data.edges: e.select = False for p in bpy.context.active_object.data.polygons: p.select = False # Restore saved selection for i in vertex_selection: bpy.context.active_object.data.vertices[i].select = True self.report({'INFO'}, "Restored selection of %d vertices" % len(vertex_selection)) return {'FINISHED'} class VertexSelectionPanel(bpy.types.Panel): """Creates a Panel in the Object properties window""" bl_label = "Vertex Selection" bl_idname = "OBJECT_PT_clone_restore" bl_space_type = 'VIEW_3D' bl_region_type = 'TOOLS' def draw(self, context): layout = self.layout obj = context.object col = layout.column() col.operator("object.save_vertex_selection", text='Save Selection') col.operator("object.restore_vertex_selection", text='Restore Selection') def register(): bpy.utils.register_module(__name__) def unregister(): bpy.utils.unregister_module(__name__) if __name__ == "__main__": register()