Skip to main content
API link
Source Link
brockmann
  • 12.8k
  • 4
  • 51
  • 94

That's pretty close. Just add real properties to the operator class. Minimal example:

enter image description here

import bpy
from bpy.types import Operator
from bpy.props import IntProperty, FloatProperty, FloatVectorProperty


class OBJECT_OT_add_object(Operator):
    """Create a new Mesh Object"""
    bl_idname = "your_category.add_object"
    bl_label = "Add Mesh Object"
    bl_options = {'REGISTER', 'UNDO'}
    
    my_radius : FloatProperty()
    my_depth : IntProperty()
    my_location : FloatVectorProperty()
    my_rotation : FloatVectorProperty()
    
    def execute(self, context):
        # Call primitve_add
        bpy.ops.mesh.primitive_cylinder_add(
            radius = self.my_radius, 
            depth = self.my_depth, 
            location = self.my_location, 
            rotation = self.my_rotation)

        return {'FINISHED'}


def register():
    bpy.utils.register_class(OBJECT_OT_add_object)

def unregister():
    bpy.utils.unregister_class(OBJECT_OT_add_object)

if __name__ == "__main__":
    register()

Further reading: https://docs.blender.org/api/current/bpy.props.html

That's pretty close. Just add real properties to the operator class. Minimal example:

enter image description here

import bpy
from bpy.types import Operator
from bpy.props import IntProperty, FloatProperty, FloatVectorProperty


class OBJECT_OT_add_object(Operator):
    """Create a new Mesh Object"""
    bl_idname = "your_category.add_object"
    bl_label = "Add Mesh Object"
    bl_options = {'REGISTER', 'UNDO'}
    
    my_radius : FloatProperty()
    my_depth : IntProperty()
    my_location : FloatVectorProperty()
    my_rotation : FloatVectorProperty()
    
    def execute(self, context):
        # Call primitve_add
        bpy.ops.mesh.primitive_cylinder_add(
            radius = self.my_radius, 
            depth = self.my_depth, 
            location = self.my_location, 
            rotation = self.my_rotation)

        return {'FINISHED'}


def register():
    bpy.utils.register_class(OBJECT_OT_add_object)

def unregister():
    bpy.utils.unregister_class(OBJECT_OT_add_object)

if __name__ == "__main__":
    register()

That's pretty close. Just add real properties to the operator class. Minimal example:

enter image description here

import bpy
from bpy.types import Operator
from bpy.props import IntProperty, FloatProperty, FloatVectorProperty


class OBJECT_OT_add_object(Operator):
    """Create a new Mesh Object"""
    bl_idname = "your_category.add_object"
    bl_label = "Add Mesh Object"
    bl_options = {'REGISTER', 'UNDO'}
    
    my_radius : FloatProperty()
    my_depth : IntProperty()
    my_location : FloatVectorProperty()
    my_rotation : FloatVectorProperty()
    
    def execute(self, context):
        # Call primitve_add
        bpy.ops.mesh.primitive_cylinder_add(
            radius = self.my_radius, 
            depth = self.my_depth, 
            location = self.my_location, 
            rotation = self.my_rotation)

        return {'FINISHED'}


def register():
    bpy.utils.register_class(OBJECT_OT_add_object)

def unregister():
    bpy.utils.unregister_class(OBJECT_OT_add_object)

if __name__ == "__main__":
    register()

Further reading: https://docs.blender.org/api/current/bpy.props.html

Source Link
brockmann
  • 12.8k
  • 4
  • 51
  • 94

That's pretty close. Just add real properties to the operator class. Minimal example:

enter image description here

import bpy
from bpy.types import Operator
from bpy.props import IntProperty, FloatProperty, FloatVectorProperty


class OBJECT_OT_add_object(Operator):
    """Create a new Mesh Object"""
    bl_idname = "your_category.add_object"
    bl_label = "Add Mesh Object"
    bl_options = {'REGISTER', 'UNDO'}
    
    my_radius : FloatProperty()
    my_depth : IntProperty()
    my_location : FloatVectorProperty()
    my_rotation : FloatVectorProperty()
    
    def execute(self, context):
        # Call primitve_add
        bpy.ops.mesh.primitive_cylinder_add(
            radius = self.my_radius, 
            depth = self.my_depth, 
            location = self.my_location, 
            rotation = self.my_rotation)

        return {'FINISHED'}


def register():
    bpy.utils.register_class(OBJECT_OT_add_object)

def unregister():
    bpy.utils.unregister_class(OBJECT_OT_add_object)

if __name__ == "__main__":
    register()