Skip to content

Instantly share code, notes, and snippets.

Created June 27, 2013 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/5879582 to your computer and use it in GitHub Desktop.
Save anonymous/5879582 to your computer and use it in GitHub Desktop.
test
bl_info = {
'name': 'Move origin to selected',
'author': 'Dealga McArdle (zeffii)',
'version': (0, 0, 1),
'blender': (2, 6, 7),
'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'}
import bpy
import mathutils
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):
from mathutils import Vector
bpy.ops.object.mode_set(mode = 'OBJECT')
obj = context.active_object
current_center = (0, 0 ,0)
selected_verts = [v.co for v in obj.data.vertices if v.select]
median = Vector((0,0,0))
for v in selected_verts:
median += v
median /= len(selected_verts)
obj.data.transform(mathutils.Matrix.Translation(-median))
obj.location += median
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