As per the question, is it possible to avoid the effect of Undo / Redo on a StringProperty? I've run into a situation where I have to avoid this, but I'm not sure if it can be done, and how.

At this moment in particular I am focused on a StringPropery, but I think it may be useful to know also for other types of bpy.props

  • $\begingroup$ You want to remove changes to a particular property from the Undo / Redo stack ? $\endgroup$
    – Gorgious
    May 23 at 11:52

Setter and getter saving data outside blend file data.

Suggest this could be done with a setter / getter. For example could append string property to a text file, which would be outside the influence of the blend file data (undo stack.)

Here is a test example, using a hardcoded filepath to a text file. The property is prepended to the text editor footer to test.

enter image description here

import bpy
from bpy.props import StringProperty

from pathlib import Path
filepath = "/tmp/test.txt"

def get_foo(self):
    f = Path(filepath)
    if f.exists():
        return f.read_text()
        return "Default"

def set_foo(self, value):
    f = Path(filepath)
bpy.types.Scene.foo = StringProperty(
def draw(self, context):
    scene = context.scene
    self.layout.prop(scene, "foo")

Note: This is solely a proof of concept. Would require a blend file name based filepath, or in file data for different values on a per blend basis.

  • $\begingroup$ It could be a solution. I am surprised that there are no APIs in Blender to avoid this, such as operators that can avoid undo and redo. I wonder if I am making "absurd" claims, or is it simply an API missing in Blender. You who are an expert in Python / Blender, what do you think about this? $\endgroup$
    – Noob Cat
    May 23 at 13:56
  • $\begingroup$ No expert in the ins and outs of how the undo stack works. But imagine it would be difficult to maintain state. $\endgroup$
    – batFINGER
    May 23 at 15:08
  • $\begingroup$ I think maybe it could also be interesting to use bpy.app.handlers undo_pre, undo_post, redo_pre, redo_post. $\endgroup$
    – Noob Cat
    May 29 at 12:42

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.