# How can I avoid Undo/Redo on StringPropery or bpy.props in general?

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

• You want to remove changes to a particular property from the Undo / Redo stack ? 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.

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():
else:
return "Default"

def set_foo(self, value):
f = Path(filepath)
f.write_text(value)

bpy.types.Scene.foo = StringProperty(
get=get_foo,
set=set_foo,
)

def draw(self, context):
scene = context.scene
self.layout.prop(scene, "foo")

bpy.types.TEXT_HT_footer.prepend(draw)


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.

• 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? May 23 at 13:56
• No expert in the ins and outs of how the undo stack works. But imagine it would be difficult to maintain state. May 23 at 15:08
• I think maybe it could also be interesting to use bpy.app.handlers undo_pre, undo_post, redo_pre, redo_post. May 29 at 12:42