0

I am aware that I have already asked this question before I apologize ahead of time.

BUT I am STILL struggling really bad with it. as simple as it looks for some of you its really hard for me. The other similar answers suggested to me didn't help since I am super new at scripting.

here is some information----

I am using Blender 2.79b

I'm writing a code that I will eventually turn into addon at the end. the code is supposed to have 3 shortcut buttons.

button1- to add a cube

button2- to add a sphere

button3- to add a cylinder

enter image description here

Once each button is pressed, I want the object to have a custom scale or dimension. For example: Once the Add Cube button is pressed, Cube gets created with these dimension (15, 20, 15)

If you can help please be specifi since I have NOOOO idea what I am doing :p

Here is my code

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 = "NEW"

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

    row = layout.row()
    row.operator("mesh.primitive_cube_add")
    bpy.ops.transform.resize(value=(7.5, 10, 7.5))



    row = layout.row()
    row.operator("mesh.primitive_uv_sphere_add")
    bpy.ops.transform.resize(value=(5, 5, 5))



    row = layout.row()
    row.operator("mesh.primitive_cylinder_add")
    bpy.ops.transform.resize(value=(12, 12, 5))



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

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

if name == "main": register()

Daniel Rahmani
  • 163
  • 1
  • 2
  • 11

1 Answers1

0

Upgrade to Blender 2.90 and above

bpy.ops.mesh.primitive_cube_add(size=2, calc_uvs=True, enter_editmode=False, align='WORLD', location=(0, 0, 0), rotation=(0, 0, 0), scale=(0, 0, 0))

import bpy

class HelloWorld(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 = 'UI' bl_category = "NEW"

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

    row = layout.row()
    row.operator("mesh.primitive_cube_add").scale=(1, 1, 1)



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

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

if name == "main": register()

bpy.ops.transform.resize(value=(7.5, 10, 7.5)) works inside an Operator.

Karan
  • 1,984
  • 5
  • 21