0

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()

Duarte Farrajota Ramos
  • 59,425
  • 39
  • 130
  • 187
Daniel Rahmani
  • 163
  • 1
  • 2
  • 11
  • 1
    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? – Chris Jul 13 '21 at 16:50
  • just e.g. you could just use CTRL-D to duplicate an object - which is IMHO faster than tapping a button.... – Chris Jul 14 '21 at 00:22

1 Answers1

2

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

brockmann
  • 12,613
  • 4
  • 50
  • 93
batFINGER
  • 84,216
  • 10
  • 108
  • 233
  • 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")

    – Daniel Rahmani Jul 14 '21 at 20:17
  • As in answer. op = row.operator(...) then op.size = 0.2 – batFINGER Jul 14 '21 at 20:28
  • I'm still screwing it up somehow :( – Daniel Rahmani Jul 15 '21 at 01:53
  • Edit your draw method into question. – batFINGER Jul 15 '21 at 03:20
  • 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 – Daniel Rahmani Jul 15 '21 at 16:00
  • @DanielRahmani going by image in question you are using an earlier version of blender. Things change slightly over time. Go to the python console in blender and type in bpy.ops.mesh.primitive_cube_add( and hit "Ctrl-Space" together for it to auto complete, showing the options. IIRC it could be the case that radius is used instead of size If this is the case there will be an error message in system console, added link above re seeing errors in system console. – batFINGER Jul 15 '21 at 21:57