how do I make custom operator attributes?

I’ve been making a custom menu for myself and have been using built-in blender operators like so:

layout.operator(“object.mode_set”,text=“edit mode”).mode=“EDIT”
layout.operator(“object.mode_set”,text=“object mode”).mode=“OBJECT”

Now I’m trying to make some simple operators of my own but don’t know how to do a property/attribute like “.mode=”

I have tried (in the main part of the class):
property = bpy.props.IntProperty(name=“property”, default=0, hard_min=-1, hard_max=1)

def init(self): = 1

But since I don’t really know how blender handles custom operator generation I don’t even know what to try. I looked in docs but couldn’t find an example. I have operators working as intended, I just can’t use properties/attributes with them.


import bpy

class SimpleOperator(bpy.types.Operator):
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"

    mode = bpy.props.StringProperty(default="OBJECT")

    def execute(self, context):
        print("Mode:", self.mode)
        return {'FINISHED'}

def register():

def unregister():

if __name__ == "__main__":


After messing around with what you gave me I saw that I must have been looking at an older example for IntProperty because hard_min and hard_max are aparrently not valid anymore. I’m assuming it just wasn’t properly registering the IntProperty.

there is min, max, soft_min and soft_max, whereas min and max are like hard_min / hard_max