Skip to main content
added 495 characters in body
Source Link
batFINGER
  • 85.2k
  • 10
  • 114
  • 244

If we simply ourselves add

rotation : FloatVectorProperty()

the rotation will always show in the base unit of radians. 360 degrees = 2pi radians. In scene unit settings degrees is the default set to display in the UI

rotation : FloatVectorProperty(unit='ROTATION')

is required in the property definition to make it behave like other rotation props. Just as unit='LENGTH' will add metres etc.

All this is done for us by the helper class..

If we simply ourselves add

rotation : FloatVectorProperty()

the rotation will always show in the base unit of radians. 360 degrees = 2pi radians. In scene unit settings degrees is the default set to display in the UI

rotation : FloatVectorProperty(unit='ROTATION')

is required in the property definition to make it behave like other rotation props. Just as unit='LENGTH' will add metres etc.

All this is done for us by the helper class..

added 147 characters in body
Source Link
batFINGER
  • 85.2k
  • 10
  • 114
  • 244

With the AddObjectHelper class

enter image description here

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_cylinderand 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

With the AddObjectHelper class

enter image description here

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_cylinderand 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

With the AddObjectHelper class

enter image description here

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_cylinderand 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

added 57 characters in body
Source Link
batFINGER
  • 85.2k
  • 10
  • 114
  • 244

With the AddObjectHelper class

enter image description here

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_objectOBJECT_OT_add_cylinder(Operator, AddObjectHelper):
    """Create a new Mesh Object"""
    bl_idname = "cylinder"object.add_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_cylinderand 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

With the AddObjectHelper class

enter image description here

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_object(Operator, AddObjectHelper):
    """Create a new Mesh Object"""
    bl_idname = "cylinder.add_object"
    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, 
                align=self.align,
                location=self.location, 
                rotation=self.rotation)

        return {'FINISHED'}

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

With the AddObjectHelper class

enter image description here

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_cylinderand 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
added 163 characters in body
Source Link
batFINGER
  • 85.2k
  • 10
  • 114
  • 244
Loading
Source Link
batFINGER
  • 85.2k
  • 10
  • 114
  • 244
Loading