1
$\begingroup$

I want to add another menu item to my Custom Panel for scaling the size of an object by +2. I get the following code whenever I do the scaling.

bpy.ops.transform.resize(value=(2, 2, 2), constraint_axis=(False, False, False),
constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', 
proportional_edit_falloff='SMOOTH', proportional_size=1)

How do I pass this code to col.operator() so it works as at the moment I am getting an error.

This is my current code which works fine and allows me to add a plane or cube object.

import bpy

class CustomPanel(bpy.types.Panel):
    """A Custom Panel in the Viewport Toolbar"""
    bl_label = "Custom Panel"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'TOOLS'

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

        row = layout.row()
        row.label(text="Add Objects:")

        split = layout.split()
        col = split.column(align=True)

        col.operator("mesh.primitive_plane_add", text="Plane")
        col.operator("mesh.primitive_cube_add", text="Cube")

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

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

if __name__ == "__main__":
    register()
$\endgroup$
3
$\begingroup$

If all you want to set for the operator is a single property, you can do:

col.operator("transform.resize").value = (2,2,2)

If you want to set multiple properties, use the object that is returned by .operator() and set the properties on it one after another:

props = col.operator("transform.resize")
props.value = (2,2,2)
props.constraint_orientation = 'GLOBAL'
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.