I've run into the following issue: When a Geoprocessing tool runs operations in its own Python code, it has no idea whether the user currently has unsaved edits in an ArcGIS Pro edit session. The .NET SDK gives us Project.Current.HasEdits, IsEditingEnabled, and EditedDatastores — but those are only accessible to Add-Ins running on the Main UI Thread.
Any GP tool that writes to a geodatabase outside the Pro edit session is operating blind. The user won't get a warning that their uncommitted edits are invisible to the tool, and the tool's own writes won't be visible until someone manually refreshes.
Is there any architectural intended way to not run into this problem with GP Tools? If not I would wish for the following:
arcpy.mp.ArcGISProject.hasUnsavedEdits — A simple yes/no on whether the project has uncommitted edits. Basically the Python equivalent of Project.Current.HasEdits.
arcpy.mp.ArcGISProject.isEditingEnabled — Whether the editing toggle is even active.
arcpy.mp.ArcGISProject.editedDatastores — A list showing which datastores have pending edits. This would let a tool check if its specific workspace is affected.
Ideally: A declarative flag in the tool definition like requiresNoEditSession = True. Similar to canRunInBackground, this would let Pro gray out the Run button or show a warning if there are unsaved changes on any input workspace. No extra code needed in the tool itself.
Edit sessions in arcpy are monitored at the workspace level using functions like arcpy.IsBeingEdited(workspace)
Script tools are aware of any edits performed via an edit session in the app - both edited attributes and modified features should be in sync from the app to your script tool's execution code. The script execution should be aware of those new attributes and features. This simple execution test code shows that after starting editing, creating a new feature, the messages from execute indicate the workspace is being edited and the new features are available in the cursor.
Execution sample:
import arcpy
in_features = arcpy.GetParameterAsText(0)
workspace = arcpy.Describe(in_features).path
# Return True/False message about the edit session
arcpy.AddMessage(f"Workspace containing input features ~{in_features}~ is in an Edit Session: {arcpy.IsBeingEdited(workspace)}")
count = 0
with arcpy.da.SearchCursor(in_features, ["OID@"]) as scur:
for row in scur:
count+=1
# Return count message to show new features from the edit session are available to the cursor
arcpy.AddMessage(f"Count of records in input features using cursor: {count}")
Here are the output messages before doing the edits:
Workspace containing input features ~Devices~ is in an Edit Session: False
Count of records in input features using cursor: 3
And the messages after creating features using interactive editing tools (edits are still pending, not saved or discarded)
Workspace containing input features ~Devices~ is in an Edit Session: True
Count of records in input features using cursor: 4
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.