Translate and Modal

Hi,

I have a little question !

I created a modal operator to make operation and when I launch the operator, I use the transform.translate in Invoke.

Like this


bpy.ops.transform.translate('INVOKE_DEFAULT', True)

There is a code example, select the object you want place a cube on it, launche the tool.



import bpy
from bpy.props import IntProperty, FloatProperty




class Project_Cube_Modal(bpy.types.Operator):
    """Move an object with the mouse, example"""
    bl_idname = "object.project_cube_modal"
    bl_label = "Simple Modal Operator"


    first_mouse_x = IntProperty()
    count = 0
    
    def modal(self, context, event):
        scene = bpy.context.scene
        wm = bpy.context.window_manager
        self.count += 1
              
        if self.count == 1 :
            bpy.ops.transform.translate('INVOKE_DEFAULT', True)
        
        if event.type == 'MIDDLEMOUSE':
            return {'PASS_THROUGH'} 


        if event.type == 'S' and event.value == 'PRESS':
            act_obj = bpy.context.active_object
            for obj in context.selected_objects:
                bpy.context.scene.objects.active = obj
                bpy.ops.transform.resize('INVOKE_DEFAULT', True)


        elif event.type == '' and event.value == 'PRESS':
            for obj in context.selected_objects:
                bpy.context.scene.objects.active = obj
                bpy.ops.transform.rotate('INVOKE_DEFAULT',True, constraint_axis=(False, False, True), constraint_orientation='LOCAL')
            
        elif event.type == 'LEFTMOUSE':
            
            bpy.context.scene.tool_settings.use_snap = False
            self.first_mouse_x = event.mouse_x
            
            return {'FINISHED'}
            
        elif event.type in {'RIGHTMOUSE', 'ESC', 'SPACE'}:
            return {'CANCELLED'}


        return {'RUNNING_MODAL'}


    def invoke(self, context, event):
        
        if context.object:
            bpy.context.scene.tool_settings.use_snap = True
            bpy.ops.mesh.primitive_cube_add(radius=1)


            self.first_mouse_x = event.mouse_x


            context.window_manager.modal_handler_add(self)
            return {'RUNNING_MODAL'}
        else:
            self.report({'WARNING'}, "No active object, could not finish")
            return {'CANCELLED'}


class Projection_Cube_Modal_Panel(bpy.types.Panel):
    bl_idname = "projection_cube_modal_panel"
    bl_label = "Projection Cube Modal Panel"
    bl_space_type = "VIEW_3D"
    bl_region_type = "TOOLS"
    bl_category = "category"


    def draw(self, context):
        layout = self.layout
        layout.operator("object.project_cube_modal", text='Project', icon='FACESEL')


def register():
    bpy.utils.register_module(__name__)


def unregister():
    bpy.utils.unregister_module(__name__)


if __name__ == "__main__":
    register()

My issue is that I cannot exit the translate mode to start other modes.

If you have any idea :wink:
thx for your help !

Sorry for bumping that old thread, but did you ever find a solution?
I’m in the same situation here.