# Can I avoid an undo when operator is called due to a property change?

I am writing an add-on that creates a mesh with several randomly generated aspects. The mesh is generated from default property values when the operator is initially called. These properties are added to the tools panel for the user to modify.

In some cases I want to modify the already generated mesh both to avoid wasted recalculation and to retain the majority of randomly generated features. Ie - it might look the way I want it except for some minor aspect I can change without effecting the overall appearance.

To do this, my property update functions set a flag to indicate whether the property change necessitates a complete regeneration of the mesh or if the existing mesh can be tweaked instead.

I am seeing that there is no object to tweak when the operator's execute function is called after a property change. It appears that an undo is performed before the operator is called again.

Is there a way to avoid the undo operation? Or a way to store the mesh and access it when the operator is called again?

As an example:

# ------------------------------------------------------------
# Operator for adding a Thing
# ------------------------------------------------------------

...

# set a flag indicating a complete regenerate is required
def update_regenerate(self, context):
self.do_regenerate = True

# set a flag to indicating a simpler update can be done
def update_modify(self, context):
self.do_modify = True

# flags used to determine if Thing should be regenerated or modified
do_regenerate = BoolProperty(name='Must regenerate object', default=False, options={'HIDDEN'})
do_modify     = BoolProperty(name='Can modify object', default=False, options={'HIDDEN'})

...

def execute(self, context):
self.do_regenerate = False
self.do_modify = False
return {'FINISHED'}

@classmethod
def poll(cls, context):
return context.mode == 'OBJECT'

def invoke(self, context, event):
return self.execute(context)

def draw(self, context):
...

# ------------------------------------------------------------
# Creates a random Thing
# ------------------------------------------------------------
if props.do_modify:
# At this point there is no object to modify!!
bpy.ops.object.mode_set(mode='EDIT', toggle=False)

# only resize because the user liked the randomly
# generated object but wants to resize the base
# without changing the other apsects of it
size_base(props)
else:
create_base(props)   # creates a base with a given size
create_spokes(props) # creates randomly oriented spokes
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)

• Blender's redo panel will revert all changes every time and re-run the operation, there's no way around that. The behavior might be different / more controllable when writing a modifier in C, I'm not sure. – CodeManX Aug 24 '14 at 1:19

To prevent calling the operator each time an option changes you could move the properties for the options to outside of the operator, maybe to an AddonPreferences instance? This can then be accessed by the operator and a panel or directly in the User Preferences when enabling the addon. See Cloud Generator addon for an example of properties added to bpy.types.Scene and used by both panel and operator.