1

When I add an primitive via Python by using the following code:

import bpy

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

the Adjust Last Operation panel does not appear. Do I need to run any other code additionally?

enter image description here

Harry McKenzie
  • 10,995
  • 8
  • 23
  • 51
Lala_Ghost
  • 457
  • 4
  • 17

1 Answers1

1

I don't think you can because this panel is context sensitive, and it only appears when you do something in the 3D viewport, but you are programmatically adding it which will not trigger this panel directly. However, you can create your own operator that will trigger your own Adjust Last Operation panel, but you will have to execute the operator while in the context of the 3D Viewport. Copy the sample My Object Operator operator script and execute it. Then press F3 and search for it and press Enter. Notice I have added 2 properties in this panel which you can extend and can be adjusted. You can also bring this operator back if you haven't done anything else with Edit > Adjust Last Operation or press shortcut F9.

enter image description here

import bpy
from bpy.props import *
import math

class MyOperator(bpy.types.Operator): bl_idname = "object.my_operator" bl_label = "My Object Operator" bl_options = {'REGISTER', 'UNDO'}

scale_x : FloatProperty (
    name = "This is the X-Scale",
    description = "the x-scale",
    default = 1.0,
    min = 0.1,
    max = 5.0
)

rotation_z : IntProperty (
    name = "This is the Z-Rotation",
    description = "the z-rotation",
    default = 45,
    min = 0,
    max = 360
)

def execute(self, context):
    result = bpy.ops.mesh.primitive_cube_add(size=2, enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
    o = bpy.context.active_object;
    o.rotation_euler[2] = math.radians(self.rotation_z)
    o.scale[0] = self.scale_x

    return {'FINISHED'}

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

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

if name == "main": register()

Harry McKenzie
  • 10,995
  • 8
  • 23
  • 51