Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
'''
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
'''
bl_info = {
'name': 'Move origin to selected',
'author': '',
'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
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()
@beothorn

This comment has been minimized.

Copy link

commented Sep 23, 2014

Very helpful addon, thanks!

@avex48

This comment has been minimized.

Copy link

commented Jan 25, 2018

Hi @zeffii, had tried to contact you via "blenderstackexchange" and in this page "https://blender.meta.stackexchange.com/questions/2434/how-do-i-send-a-message-to-a-specific-user/2435?noredirect=1#comment5367_2435" I had written this message:
/--------------------------------------------------
Hello zeffii, forgive me if I steal some attention from you. I'm a chess enthusiast, I modeled a chessboard (http://www.avelino.it/wa/scacchiera/) and (not knowing Python) I embarked on writing a program that reads a game from a PGN file and, controlled by a Tkinter interface via the Forward, Back buttons etc., should make moves on the chessboard. The program is only sketched out, and I found out only now that the moves are executed, but the 3D view updates only when the script ends. I have looked for solutions on the web and none seem to work.

I tried to implement the brilliant solution you proposed in the script of the page "blender.stackexchange.com/questions/28673/…; but given my poor python knowledge I could not get any results!

If I sent you the Blender file and the script, would you have the chance to give it a look?
Thank you and excuse me for the length of the message. Translated with www.DeepL.com/Translator
/------------------------------------------------
.... and thank you very much for this very useful addon.

Avelino De Sabbata

@gehvaugeh

This comment has been minimized.

Copy link

commented Feb 15, 2018

Thx alot, thought i will script this myself but then i found your script :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.