Blender rotation script

Hello friends, help me write a script so that the rotation command is executed a little differently: now when we rotate an object, we enter a positive or negative angle value, but in my opinion this is not very convenient, it would be much more convenient to always enter a positive value and the object rotated in that direction, into which I pull it. Thanks in advance.

I sure there is the way to force blender to define the rotation axis automaticaly depending on direction you drag the object. :pray: :pray: :pray: :pray:

I have not understood exactly your request. By adapting the initial template example for rotating an object is done like this.

import bpy
from bpy.props import IntProperty, FloatProperty


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

    first_mouse_x: IntProperty()
    first_value: FloatProperty()

    def modal(self, context, event):
        if event.type == 'MOUSEMOVE':
            print(event)
            delta = self.first_mouse_x - event.mouse_x
            value = self.first_value + delta * 0.01        
            context.object.rotation_euler[2] = value
            
        elif event.type in ['LEFTMOUSE', 'ESC', 'SPACE']:
            return {'FINISHED'}
        
        return {'RUNNING_MODAL'}

    def invoke(self, context, event):
        if context.object:
            self.first_mouse_x = event.mouse_x
            self.first_value = context.object.location.x

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

def menu_func(self, context):
    self.layout.operator(ModalOperator.bl_idname, text=ModalOperator.bl_label)

# Register and add to the "view" menu (required to also use F3 search "Simple Modal Operator" for quick access)
def register():
    bpy.utils.register_class(ModalOperator)
    bpy.types.VIEW3D_MT_object.append(menu_func)

def unregister():
    bpy.utils.unregister_class(ModalOperator)
    bpy.types.VIEW3D_MT_object.remove(menu_func)

try:unregister()
except:pass
register()
bpy.ops.object.modal_operator('INVOKE_DEFAULT')

You can examine this code and see how things are done. Also if you want to clarify something in more detail, please feel free to.

Thank you! I think it will help.

Good, if you have any other trouble you can mention it.