bpy.ops undo argument doesn't work if the main operator has UNDO in bl_options #112851

Open
opened 2023-09-25 14:39:22 +02:00 by Andrej · 1 comment
Contributor

Blender 3.6.3

When I run some operator with bpy.ops.object.test_operator_undo(True) (with undo argument = True) from operator bpy.ops.object.test_operator that has "UNDO" in the bl_options, undo argument doesn't work - it doesn't create undo step and doesn't allow redo.

Steps to reproduce:

  1. Default Blender scene

  2. Run the code below

  3. F3 - Test Operator

  4. F9 (redo) shows "Test Operator" when bpy.ops.object.test_operator_undo was called with True as undo argument which suppose to create an undo step for this operator so that it will be possible to redo it.

  5. If you remove UNDO from TestOperator bl_options (meaning commenting line 7 and uncomment line 8) and run the code and operator again
    F9 now shows "Undo Test Operator" but now it's not possible to redo the TestOperator in case if it finishes without calling another operator (if some_condition was True).
    I've found that I can add bpy.ops.ed.undo_push(message='Test Operator') to make sure it still will be possible to atleast undo it but redo is not available.

import bpy


class TestOperator(bpy.types.Operator):
    bl_idname = "object.test_operator"
    bl_label = "Test Operator"
    bl_options = {"REGISTER", "UNDO"}
#    bl_options = {"REGISTER"}

    def execute(self, context):
#        bpy.ops.ed.undo_push(message='Test Operator')
        some_condition = False
        if some_condition:
            context.object.location = (0,0,0)
        else:
            bpy.ops.object.test_operator_undo(True)
        return {'FINISHED'}
    
class TestOperatorUndo(bpy.types.Operator):
    bl_idname = "object.test_operator_undo"
    bl_label = "Undo Test Operator"
    bl_options = {"REGISTER", "UNDO"}
    test: bpy.props.IntProperty()

    def execute(self, context):
        print('hello')
        return {'FINISHED'}
    
def register():
    bpy.utils.register_class(TestOperator)
    bpy.utils.register_class(TestOperatorUndo)

def unregister():
    bpy.utils.unregister_class(TestOperator)
    bpy.utils.unregister_class(TestOperatorUndo)


if __name__ == "__main__":
    register()
Blender 3.6.3 When I run some operator with `bpy.ops.object.test_operator_undo(True)` (with undo argument = `True`) from operator `bpy.ops.object.test_operator` that has "UNDO" in the `bl_options`, undo argument doesn't work - it doesn't create undo step and doesn't allow redo. Steps to reproduce: 1) Default Blender scene 2) Run the code below 3) F3 - Test Operator 4) F9 (redo) shows "Test Operator" when` bpy.ops.object.test_operator_undo` was called with `True` as [undo argument](https://docs.blender.org/api/current/bpy.ops.html#keywords-and-positional-arguments) which suppose to create an undo step for this operator so that it will be possible to redo it. 5) If you remove UNDO from TestOperator bl_options (meaning commenting line 7 and uncomment line 8) and run the code and operator again F9 now shows "Undo Test Operator" but now it's not possible to redo the TestOperator in case if it finishes without calling another operator (if `some_condition` was `True`). I've found that I can add `bpy.ops.ed.undo_push(message='Test Operator')` to make sure it still will be possible to atleast undo it but redo is not available. ```python import bpy class TestOperator(bpy.types.Operator): bl_idname = "object.test_operator" bl_label = "Test Operator" bl_options = {"REGISTER", "UNDO"} # bl_options = {"REGISTER"} def execute(self, context): # bpy.ops.ed.undo_push(message='Test Operator') some_condition = False if some_condition: context.object.location = (0,0,0) else: bpy.ops.object.test_operator_undo(True) return {'FINISHED'} class TestOperatorUndo(bpy.types.Operator): bl_idname = "object.test_operator_undo" bl_label = "Undo Test Operator" bl_options = {"REGISTER", "UNDO"} test: bpy.props.IntProperty() def execute(self, context): print('hello') return {'FINISHED'} def register(): bpy.utils.register_class(TestOperator) bpy.utils.register_class(TestOperatorUndo) def unregister(): bpy.utils.unregister_class(TestOperator) bpy.utils.unregister_class(TestOperatorUndo) if __name__ == "__main__": register() ```
Andrej added the
Status
Needs Triage
Type
Report
Priority
Normal
labels 2023-09-25 14:39:23 +02:00

That undo parameter is confusing, but I can confirm that it doesn't seem to be working in this case.

This parameter was implemented in a09feb7386 by @ideasman42

That `undo` parameter is confusing, but I can confirm that it doesn't seem to be working in this case. This parameter was implemented in a09feb7386 by @ideasman42
Germano Cavalcante added
Module
Python API
Status
Confirmed
and removed
Status
Needs Triage
labels 2023-09-26 00:18:02 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#112851
No description provided.