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':
            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

            return {'RUNNING_MODAL'}
  {'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():

def unregister():


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.