Im manage to make a simple script to generate a stair in python. Now I would like to add it as a new mesh, and being able to have a menu where I can modify the value instead of changing the code. I start from the template addon_addObject
I can recreate my stairs but stuck with creating the parameters. Here is the code. Thank you for any help
import bpy
from bpy.types import Operator
from bpy.props import (FloatVectorProperty, FloatProperty, IntProperty)
from bpy_extras.object_utils import AddObjectHelper, object_data_add
from mathutils import Vector
def add_object(self, context):
#step variable
cubsize = 2
posx = 0
posy = 5
posz = 2
scalx = 10
scaly = 5
scalz = 0.5
#step numbers
step = 20
#step generators
for i in range (step):
bpy.ops.mesh.primitive_cube_add(size=cubsize, location=(posx, cubsize*i+posy*i,cubsize*i+posz*i))
bpy.ops.transform.resize(value=(scalx, scaly, scalz))
bpy.ops.object.select_pattern(pattern="Cube*")
bpy.ops.object.join()
bpy.context.object.name = "G_stair"
class OBJECT_OT_add_object(Operator, AddObjectHelper):
"""Create a new Mesh Object"""
bl_idname = "mesh.add_object"
bl_label = "parameter stair"
bl_options = {'REGISTER', 'UNDO', 'PRESET'}
step: IntProperty(
name="step",
default=10,
subtype='TRANSLATION',
description="scaling",
)
def execute(self, context):
add_object(self, context)
return {'FINISHED'}
# Registration
def add_object_button(self, context):
self.layout.operator(
OBJECT_OT_add_object.bl_idname,
text="stair",
icon='PLUGIN')
def register():
bpy.utils.register_class(OBJECT_OT_add_object)
bpy.types.VIEW3D_MT_mesh_add.append(add_object_button)
def unregister():
bpy.utils.unregister_class(OBJECT_OT_add_object)
bpy.types.VIEW3D_MT_mesh_add.remove(add_object_button)
if __name__ == "__main__":
register()
'''