Select to view content in your preferred language

Need help with editing value in versioned sde. Using arcpy.da.Editor

3215
1
Jump to solution
09-05-2013 01:20 PM
JaniceBaird
Frequent Contributor
I have a python script that updates the tiles for a cached basemap using a feature class of polygons for the area of interest. Once the tiles are updated, I would like to update the values in the original feature class, changing the field "Cache" values from yes to no. I have no trouble with updating the tiles based on the feature class. I am having trouble changing the values in the feature class "Cache" field from yes to no.

The feature class is in SDE and is versioned. I am using cursors and da.Editor. ArcGIS 10.1.

I get this error: Objects in this class cannot be updated outside an edit session [GisWork.SDEADM.SectionsToCache]
With this code:
        edit = arcpy.da.Editor(env.workspace)         edit.startEditing(True, True)         edit.startOperation()         #Use an update cursor to update the values. This cursor gets all the records in the SectionsToCache feature class where CACHE = 'Yes'         with arcpy.da.UpdateCursor(inputFeatureClass, fieldName, whereClause) as cursor:             # Update the field value to 'No'              for row in cursor:                 print row[0]                 row[0]= "No"                 cursor.updateRow(row)         edit.stopOperation()         edit.stopEditing(True)


I have tried placing the start and stop operations inside the for loop. I have tried with startEditing(False, True). I tried using with for the editor since this is supposed to eliminate the need to handle the stop and start, I believe, but had the same error.

I have also tried to use CalculateField but the values did not update in the feature class. Since I need to use a Feature Layer, I am not sure if MakeFeatureLayer affects the input feature class. It looks like it did not. I can post my code for this but am more interested in getting this to work using the editor and cursors on the feature class itself.

Does anyone else have this working?

Thanks for any suggestions!
Janice.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JaniceBaird
Frequent Contributor
There is nothing like a weekend to give a person a fresh perspective! I got this working with the help from this thread: Trying-to-edit-a-layer-in-a-versioned-SDE-GDB-in-a-Python-stand-alone-script and correcting a couple of errors.

For one: I had the wrong workspace.

The next: I don't know that I can call this an error because I was using the documentation for CalculateField and passing in a VB string as the new value. This did not work. When I changed to using Python 9.3, it worked. Go figure!

Here is the final bit of code that is working:
        outTable = "SectionsToUpdate"         arcpy.MakeFeatureLayer_management(inputFeatureClass, outTable, whereClause, workspace)         with arcpy.da.Editor(workspace) as edit:             arcpy.CalculateField_management(outTable, fieldName, "'No'", "PYTHON_9.3")


Janice.

View solution in original post

0 Kudos
1 Reply
JaniceBaird
Frequent Contributor
There is nothing like a weekend to give a person a fresh perspective! I got this working with the help from this thread: Trying-to-edit-a-layer-in-a-versioned-SDE-GDB-in-a-Python-stand-alone-script and correcting a couple of errors.

For one: I had the wrong workspace.

The next: I don't know that I can call this an error because I was using the documentation for CalculateField and passing in a VB string as the new value. This did not work. When I changed to using Python 9.3, it worked. Go figure!

Here is the final bit of code that is working:
        outTable = "SectionsToUpdate"         arcpy.MakeFeatureLayer_management(inputFeatureClass, outTable, whereClause, workspace)         with arcpy.da.Editor(workspace) as edit:             arcpy.CalculateField_management(outTable, fieldName, "'No'", "PYTHON_9.3")


Janice.
0 Kudos