With the AddObjectHelper
class
Further to @brockmann's answer
The AddObjectHelper
class sets up some of the usual suspects for us, including location, rotation and align. It appears you have used the text editor > templates > python > Addon add object
template, so let's stick with it in.
class OBJECT_OT_add_cylinder(Operator, AddObjectHelper):
"""Create a new Mesh Object"""
bl_idname = "object.add_cylinder"
bl_label = "Add Mesh Object"
bl_options = {'REGISTER', 'UNDO'}
# set other args like name and description for all
vertices : IntProperty(
name="Vertices",
description="Number of Vertices",
min=0,
default=32)
radius : IntProperty(default=2)
depth : FloatProperty(default=2)
def execute(self, context):
bpy.ops.mesh.primitive_cylinder_add(
vertices=self.vertices,
radius=self.radius,
depth=self.depth,
# those defined in AddObjectHelper
align=self.align,
location=self.location,
rotation=self.rotation)
return {'FINISHED'}
Note: I've adjusted the classname OBJECT_OT_add_cylinder
and bl_idname = "object.add_cylinder"
to match desired naming convention
One issue tho is that its draw method puts its stuff first, so may need to add your own draw method to re-sort as desired
def draw(self, context):
layout = self.layout
layout.prop(self, "vertices")
layout.prop(self, "radius")
# and so on
Other examples based on add object template
https://blender.stackexchange.com/a/133880/15543
https://blender.stackexchange.com/a/102239/15543