The screencast explains what I try to do very wellstruggle with understanding the modal operator concept. https://drive.google.com/file/d/0Byzv_NlyKp_2Sk5NZEREcE5YZG8/view
Below is my code:
Idea is press a button empty is created user jumps right into translation mode with CTRL you can snap to an object vertex with LMB user places new empty 3D cursor will be set to newly positioned empty empty will be deleted
Everything works right besides the lastchain of commands I would like to steps
It seemsstep by step to me that after I start the transformationexecute, while still being in transformation, Blender already executedduring translate the following steps should wait till translate is done. So I think I need some sort of a break/pause after the transformation and when I LBM the script execution continuesmodal operator structure is needed here.
bl_info = {
"name": "Fullscreen Modelingbpy.ops.object.select_all(action='DESELECT') Toolbox",
"author": "Claas Kuhnen",
"version": (1, 0 bpy.ops.object.empty_add(),
"blender": (2, 75, 0),
"location": "View3D > Tools Shelfbpy.ops.transform.translate('INVOKE_DEFAULT')
> Modeling Toolbox",
"description": "Fullscreenbpy.ops.view3d.snap_cursor_to_selected()
Modeling with Access to Object Properties",
bpy.ops.object.delete()
This is the template I found and understand. I select one object, execute the command which will then get the location and the modal takes over. But I failed to implement my commands into this structure. How can I make the modal aware of that I added the empty and jump into translate.
I understand the confirm and cancel being the states where I can execute the rest after transform or even undo the initial empty generation if need needed.
import bpy
class "warning"ModalOperator(bpy.types.Operator):
"Beta - Concepy Study",
bl_idname = "object.modal_operator"
"category": "User Interface",
}bl_label = "Simple Modal Operator"
import bpy
from bpy.types import Menu,def Panel,__init__(self):
Operator, UIList
from rna_prop_ui import PropertyPanel
from bl_ui.properties_data_modifier import DATA_PT_modifiersprint("Start")
from
bpy.props import *
######################## def __del__(self):
# Operator Definitions #
########################
# Command Snap Origin print("End")
classdef SnapOriginObjectexecute(bpy.types.Operatorself, context):
bl_idname = "snap.originobject"
# bpy.ops.object.empty_new()
bl_label = "Snap Object Origin"
context.object.location.x = bl_optionsself.value =/ {'REGISTER'}1000.0
return {'FINISHED'}
def executemodal(self, context, event):
if event.type == 'MOUSEMOVE': # Apply
bpy.ops.object.select_all(action='DESELECT') self.value = event.mouse_x
bpy.ops.object self.empty_addexecute(context)
elif event.type == 'LEFTMOUSE': # Confirm
bpy.ops.transformview3d.translatesnap_cursor_to_selected('INVOKE_DEFAULT')
x bpy.ops.view3dobject.snap_cursor_to_selecteddelete()
return {'FINISHED'}
elif event.type in {'RIGHTMOUSE', 'ESC'}: # Cancel
bpy.ops.object.delete(use_global=False)
return {'CANCELLED'}
return {'FINISHED''RUNNING_MODAL'}
def invoke(self, context, event):
self.init_loc_x = context.object.location.x
######################## self.value = event.mouse_x
# Interface Definition # self.execute(context)
########################
context.window_manager.modal_handler_add(self)
# DATA return {'RUNNING_MODAL'}
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"object.originobject"modal_operator")
def register(): bpy.utils.register_module(__name__)
def unregister(): bpy.utils.unregister_module(__name__)
if __name__ == "__main__":
register()