Skip to content

Instantly share code, notes, and snippets.

@vansoest
Forked from zeffii/space_view3d_move_origin.py
Last active April 5, 2020 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vansoest/db2a34f3bd80547060517baecfc531b7 to your computer and use it in GitHub Desktop.
Save vansoest/db2a34f3bd80547060517baecfc531b7 to your computer and use it in GitHub Desktop.
Updated to Blender 2.8
'''
BEGIN GPL LICENSE BLOCK
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
END GPL LICENCE BLOCK
'''
import bpy
bl_info = {
'name': 'Move origin to selected',
'author': '',
'version': (0, 0, 2),
'blender': (2, 80, 0),
'location': '3d view > space bar > Origin Move to Selected',
'description': 'in edit mode, sets object origin to the median of selected verts/edges/faces',
'wiki_url': '',
'tracker_url': '',
'category': '3D View'}
class MoveOrigin(bpy.types.Operator):
"""Tooltip"""
bl_idname = "object.origin_to_selected"
bl_label = "Origin Move To Selected"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
obj = context.active_object
return obj is not None and obj.mode == 'EDIT'
def execute(self, context):
saved_location = bpy.context.scene.cursor.location.copy()
bpy.ops.view3d.snap_cursor_to_selected()
bpy.ops.object.mode_set(mode = 'OBJECT')
bpy.ops.object.origin_set(type='ORIGIN_CURSOR')
bpy.context.scene.cursor.location = saved_location
bpy.ops.object.mode_set(mode = 'EDIT')
return {'FINISHED'}
def register():
bpy.utils.register_class(MoveOrigin)
def unregister():
bpy.utils.unregister_class(MoveOrigin)
if __name__ == "__main__":
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment