0
$\begingroup$

i have some basic code that i have been writing to generate me a tower of hanoi with customisable pins and the amount of rings (the rings slider isn't added yet) but i have been having trouble with getting data from the input. I have looked at this post but it didn't help so the code that i currently have is this:

bl_info = {
    "name" : "Tower of Hanoi Generator", 
    "author" : "Hatenal", 
    "version" : (0, 0, 1), 
    "blender" : (3, 60, 0),
    "location" : "3D Viewport > Sidebar > Tower of Hanoi",
    "description" : "just a tower of hanoi generator", 
    "category" : "Development"
}

import bpy


class MESH_OT_Make_Base(bpy.types.Operator):
    """Creates a Base For the Tower"""
    
    bl_idname = "mesh.base_gen"
    bl_label = "Make the Base"
    
    def execute(self, context):
        
        bpy.ops.mesh.primitive_cube_add(scale=(1.000, 3.000, 0.250))
        
        bpy.ops.mesh.primitive_cylinder_add(location=(0, 0, 1.250), scale=(0.150, 0.150, 1.000))
        
        print("hi")
        
        return {"FINISHED"}
    

class VIEW3D_PT_tower_of_hanoi_panel(bpy.types.Panel):
    pass
    #Specify the Panel Location
    bl_space_type = "VIEW_3D" #Specifies that it is in the Viewport
    bl_region_type = "UI" #Specifies it into the Sidebar Reigon
    
    #specify the label of the window
    bl_category = "Tower of Hanoi"
    bl_label = "Tower of Hanoi Generator"
    
    def draw(self, context):
        """define the layour of the panel"""
        row = self.layout.row()
        col = self.layout.column()
        n = 5
        
        row.prop(context.scene, 'pins')
        
        self.layout.separator()
        
        row = self.layout.row()
        row.operator("mesh.base_gen", text="Generate")
        
#Register the Panel
def register():
    bpy.types.Scene.pins = bpy.props.IntProperty(name="pins",description="The number of pages in my book",min=3,max=6,default=3)
    bpy.utils.register_class(MESH_OT_Make_Base)
    bpy.utils.register_class(VIEW3D_PT_tower_of_hanoi_panel)
    
def unregister():
    del bpy.types.Object.pins
    bpy.utils.unregister_class(MESH_OT_Make_Base)
    bpy.utils.unregister_class(VIEW3D_PT_tower_of_hanoi_panel)
    
register()
```
$\endgroup$

1 Answer 1

0
$\begingroup$

You need to define the "pins" property in your operator class:

pins = context.scene.pins

If you want to distribute the number of pins equally you can modify your code and add the following formula based on your cube Y scale:

    def execute(self, context):
        
        scale_Y = 3.000
        bpy.ops.mesh.primitive_cube_add(scale=(1.000, scale_Y, 0.250))
        
        pins = context.scene.pins
        
        for i in range(pins):
            bpy.ops.mesh.primitive_cylinder_add(location=(0, scale_Y*(2*(1 + i)/(pins + 1) - 1), 1.250), scale=(0.150, 0.150, 1.000))
        
        print("hi")
        
        return {"FINISHED"}
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .