Select to view content in your preferred language

Delete and Update operations in sequence to be followed

139
3
2 weeks ago
Rohanrajan
Emerging Contributor

Hi,

 

I have been trying to select a number of features, delete some of them and update the rest. Like

edit = arcpy.da.Editor(workspace)
 
edit.startEditing(with_undo=True, multiuser_mode=False)
arcpy.AddMessage("Edit Session Started")
logging.info(f"Edit Session Started in : {workspace}")
try:
for id in Ids:
if id != Ids[0]
SearchCuror():
  UpdateCursor()     
    deleteRow()
except arcpy.ExecuteError as e:
arcpy.AddMessage(f"Error: {e}") 
for id in Ids:
SearchCuror():
  UpdateCursor()     
    updateRow()
 
edit.stopOperation()
edit.stopEditing(save_changes=True)

But it encounters an error: Need an edit session

What am I doing wrong

Any advice is much appreciated

 

Tags (3)
0 Kudos
3 Replies
VinceAngelo
Esri Esteemed Contributor

Please edit the question to place the code in a code block (click on "..." then "</>" in the second row of icons).
Reading Python code without indention is nearly impossible.

It's also nearly impossible to debug incomplete code (especially when there are TWO SearchCursor flavors [and arcpy.SearchCursor is deprecated, and should not be used in code written since 2013]).

But you should know that nesting cursors is an antipattern, and the likely cause of your error.

- V

0 Kudos
DanPatterson
MVP Esteemed Contributor

To supplement Vince's suggestion, for the visual 

Code formatting ... the Community Version - Esri Community


... sort of retired...
0 Kudos
CodyPatterson
MVP Regular Contributor

Hey @Rohanrajan 

This is a longshot, but it appears you're not performing an edit.startOperation() before starting the edit session.

Cody

0 Kudos