kalley

Undo/Redo Python AddIn edits on SDE feature classes?

Discussion created by kalley on Mar 13, 2013
Latest reply on Dec 20, 2016 by tlaxson
I have a Python AddIn that edits SDE feature classes.  I???d like to have the option to Undo/Redo edits made with the AddIn.  So far I???ve tried several approaches (below), and am wondering if anybody can shed some insight on my observations.  If you have any other ideas about how to undo/redo AddIn edits, let me know!  Alternatively, if this is not possible using Python AddIns, what would be my best approach to reproduce some VBA tools requiring user input that are now obsolete?

Unsuccessful attempts to undo Python AddIn edits: 
1) Managing the edit session from within the Addin.
Code structure:
edit = arcpy.da.Editor(workspace)
edit.startEditing() 
edit.startOperation()
Cur.insertRow([geometry])
edit.stopOperation()
edit.stopEditing(True) 
arcpy.SelectLayerByAttribute_management(layer, "CLEAR_SELECTION")

Observation:  When I run my AddIn, the Undo button activates with a single operation in the stack, and I can apparently undo the clear selection (but only if the initial selection was made using a tool in my AddIn rather than the standard ArcMap ???select by rectangle??? button).  I???m not surprised that the AddIn edits are not visible to the operation stack in ArcMap, but have no idea what the selection is doing there.  Any insights?

2) Alternatively, if I starting an edit session in ArcMap before running the AddIn (with the editing code commented out) I see this: The AddIn edits are undoable only incidentally when there are manually generated edits on the operation stack before the AddIn is run (i.e. undoing the last manual edit also undoes any AddIn edits that were made after the manual edits).

Outcomes