Bellow is a script I am working on. The main idea is to via a button call a command that deselects everything, adds an empty at the 3D cursor, and then IMPORTANT calls a transform command so you can move the empty and snap it in object mode to geometry. once you LMB confirmed the placement the script continues. I sets the 3d cursor to them empty and then deletes the empty.
I am not able to figure out how to jump into the transform mode , let along continue after I placed the empty.
import bpy
from bpy.types import (
Panel,
Menu,
Operator,
)
from bpy.types import Menu, Panel, UIList
from rna_prop_ui import PropertyPanel
from bl_ui.properties_data_modifier import DATA_PT_modifiers
from bpy.props import *
########################
# Operator Definitions #
########################
# Command Snap Origin
class SnapOriginObject(bpy.types.Operator):
bl_idname = "snap.originobject"
bl_label = "Snap Object Origin"
bl_options = {'REGISTER'}
def execute(self, context):
bpy.ops.object.select_all(action='DESELECT')
bpy.ops.object.empty_add()
bpy.ops.transform.translate()
bpy.ops.view3d.snap_cursor_to_selected()
bpy.ops.object.delete()
return{'FINISHED'}
########################
# Interface Definition #
########################
# DATA
class ObjectData(bpy.types.Panel):
bl_label = "Object + Mesh Data"
bl_idname = "ObjectData"
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
bl_category = "Modeling Toolbox"
def draw(self, context):
layout = self.layout
obj = context.object
row = layout.row()
self.layout.operator("snap.originobject")
# END
def register(): bpy.utils.register_module(__name__)
def unregister(): bpy.utils.unregister_module(__name__)
if __name__ == "__main__":
register()