7
$\begingroup$

I'm trying to get what operator had been called before the current operator and make some logic based on that. Is this information accessible?

$\endgroup$

1 Answer 1

7
$\begingroup$

Blender records all operator calls in WindowManager.operators list: https://docs.blender.org/api/current/bpy.types.WindowManager.html#bpy.types.WindowManager.operators

import bpy

ops = bpy.context.window_manager.operators
print(ops)
# <bpy_collection[46], WindowManager.operators>

To get the second-to-last operator name in the list, you can use negative indices and Operator.name to get the name: https://docs.blender.org/api/current/bpy.types.Operator.html#bpy.types.Operator.name

print(ops[-1].name) # last operator name
print(ops[-2].name) # second to last operator name

# Join
# Move

... same for Operator.bl_idname: https://docs.blender.org/api/current/bpy.types.Operator.html#bpy.types.Operator.bl_idname

print(ops[-1].bl_idname) # last operator bl_idname
print(ops[-2].bl_idname) # second to last operator bl_idname

# OBJECT_OT_join
# TRANSFORM_OT_translate
$\endgroup$
1
  • $\begingroup$ Is there any way to re-do the operators from this list? Basically I wanted to push the most recent operator onto a queue (filtered with some options), then repeat those actions. Basically do bpy.ops["bl_idname first part"]["bl_idname second part"]() $\endgroup$
    – michael b
    Commented Dec 20, 2023 at 19:33

You must log in to answer this question.

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