Once in 2.79 used a script for “Move origin to selection” which also aligned the local axis to the polygon normal. Now in 2.8 the script doesn’t work anymore, and I am surprised, that there is absolutely no possible way in blender to rotate an origin at all. The only way is to rotate the geometry but then the initial position and rotation of the object is gone.
Fund this script, but I am unable to make this to work with the official python sdk.
bl_info = {
"name": "Origin to select",
"description": "Moves origin of selected object into selected part (v/e/f) of object",
"author": "enikeishik",
"blender": (2, 80, 0),
"category": "Mesh",
"location": "VIEW3D > Edit Mode > Mesh > Move origin to select",
}
import bpy
class OriginToSelect(bpy.types.Operator):
"""Origin of selected moving script"""
bl_idname = "mesh.origin_to_select"
bl_label = "Move origin to select"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
cursor3d_location = bpy.context.scene.cursor_location.copy()
ctx = bpy.context.copy()
ctx['area'] = area
ctx['region'] = area.regions[-1]
bpy.ops.view3d.snap_cursor_to_selected(ctx)
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.origin_set(type='ORIGIN_CURSOR')
bpy.context.scene.cursor_location = cursor3d_location
bpy.ops.object.mode_set(mode='EDIT')
break
return {'FINISHED'}
class CustomSetOriginOperator(bpy.types.Operator):
bl_idname = 'object.custom_set_origin'
bl_label = 'Custom set origin operator'
centre = bpy.props.StringProperty(default='')
def execute(self, context):
if self.centre == 'ORIGIN_TO_SELECT':
OriginToSelect.execute(self, context)
else:
return bpy.ops.object.origin_set(type=self.centre)
return {'FINISHED'}
class CustomSetOriginMenu(bpy.types.Menu):
bl_idname = "OBJECT_MT_custom_set_origin"
bl_label = "Custom set origin"
def draw(self, context):
layout = self.layout
layout.operator(CustomSetOriginOperator.bl_idname, text='Origin to select (Face/Edge/Vertex)').centre = 'ORIGIN_TO_SELECT'
layout.operator(CustomSetOriginOperator.bl_idname, text='Geometry to Origin').centre = 'GEOMETRY_ORIGIN'
layout.operator(CustomSetOriginOperator.bl_idname, text='Origin to Geometry').centre = 'ORIGIN_GEOMETRY'
layout.operator(CustomSetOriginOperator.bl_idname, text='Origin to 3D Cursor').centre = 'ORIGIN_CURSOR'
layout.operator(CustomSetOriginOperator.bl_idname, text='Origin to Center of Mass (Surface)').centre = 'ORIGIN_CENTER_OF_MASS'
layout.operator(CustomSetOriginOperator.bl_idname, text='Origin to Center of Mass (Volume)').centre = 'ORIGIN_CENTER_OF_VOLUME'
def menu_func(self, context):
self.layout.operator(OriginToSelect.bl_idname)
def register():
bpy.utils.register_class(OriginToSelect)
bpy.utils.register_class(CustomSetOriginOperator)
bpy.utils.register_class(CustomSetOriginMenu)
bpy.types.VIEW3D_MT_edit_mesh.append(menu_func)
wm = bpy.context.window_manager
win_keymaps = wm.keyconfigs.user.keymaps.get('Object Non-modal')
if win_keymaps:
# disable standard set origin keymap
for kmi in win_keymaps.keymap_items:
if kmi.idname == 'object.origin_set':
kmi.active = False
break
# add a keymap for our set origin operator
kmi = win_keymaps.keymap_items.new('wm.call_menu', 'C', 'PRESS', ctrl=True, alt=True, shift=True)
setattr(kmi.properties, 'name', CustomSetOriginMenu.bl_idname)
def unregister():
wm = bpy.context.window_manager
win_keymaps = wm.keyconfigs.user.keymaps.get('Object Non-modal')
if win_keymaps:
for kmi in win_keymaps.keymap_items:
# re-enable standard set origin
if kmi.idname == 'object.origin_set':
kmi.active = True
# remove our custom set origin
if kmi.idname == 'wm.call_menu' and getattr(kmi.properties, 'name') == CustomSetOriginMenu.bl_idname:
win_keymaps.keymap_items.remove(kmi)
bpy.types.VIEW3D_MT_edit_mesh.remove(menu_func)
bpy.utils.unregister_class(CustomSetOriginMenu)
bpy.utils.unregister_class(CustomSetOriginOperator)
bpy.utils.unregister_class(OriginToSelect)
if __name__ == "__main__":
register()