0
$\begingroup$

enter image description here

For example:

I want to be able to just click a button and able to have the same size cube or sphere every time. I'm gonna be making hundreds of cubes and spheres all the same size but I don't want to keep having re-size them every time I create them.

I want the spheres to always be 10m and the Cubes to be 15 x15x20mm Is this possible?

Thank so you for time in advance weather you can help or not


import bpy


class HelloWorldPanel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_label = "WIRES  &  PIPES"
    bl_idname = "OBJECT_PT_hello"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'TOOLS'
    #bl_category = "Shortcuts"

    def draw(self, context):
        layout = self.layout

        row = layout.row()
        op = row.operator("mesh.primitive_cube_add", text="Plug", icon="MESH_CUBE")
        op.size = 0.5
        op.scale = (1, 2, 3)

        op = row.operator("mesh.primitive_uv_sphere_add", text="Ground", icon="MESH_UVSPHERE")
        op.radius = 0.1

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

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


if __name__ == "__main__":
    register()
$\endgroup$
2
  • 1
    $\begingroup$ can you tell us a bit more why you need hundreds of cubes? do you move them all by hand? or why do you need that much? $\endgroup$
    – Chris
    Jul 13, 2021 at 16:50
  • $\begingroup$ just e.g. you could just use CTRL-D to duplicate an object - which is IMHO faster than tapping a button.... $\endgroup$
    – Chris
    Jul 14, 2021 at 0:22

1 Answer 1

2
$\begingroup$

Add the operator properties to the layout.

Add a primitive using the UI, and take note of the chosen parameters. Can then add to draw method of TOOL panel

    def draw(self, context):
        layout = self.layout

        col = layout.column()
        op = col.operator("mesh.primitive_cube_add")
        op.scale = (1, 2, 3)
        op.size = 1

will add an add cube operator button than when pressed adds a dimension (0.5, 1.0, 1.5) blender unit cube to the scene.

Related:

To see any errors or warnings: Where does console output go

$\endgroup$
6
  • $\begingroup$ Hello BatFINGER..... Where can I add the custom size here? I think I am doing something wrong, I'm super new at this row = layout.row() row.operator("mesh.primitive_cube_add", text="Plug", icon="MESH_CUBE") row.operator("mesh.primitive_uv_sphere_add", text="Ground", icon="MESH_UVSPHERE") $\endgroup$ Jul 14, 2021 at 20:17
  • $\begingroup$ As in answer. op = row.operator(...) then op.size = 0.2 $\endgroup$
    – batFINGER
    Jul 14, 2021 at 20:28
  • $\begingroup$ I'm still screwing it up somehow :( $\endgroup$ Jul 15, 2021 at 1:53
  • $\begingroup$ Edit your draw method into question. $\endgroup$
    – batFINGER
    Jul 15, 2021 at 3:20
  • $\begingroup$ batFINGER, I tired the script that you helped me with, but my cubes still didn't change dimension. I feel really stupid doing this lol especially since I never written anything before. I looked at the other suggestions but they just confused me even more :P $\endgroup$ Jul 15, 2021 at 16:00

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