1

I have a question regarding ArcGIS ModelBuilder. I've created a model that calculates a few fields. It runs flawlessly when attachments are NOT enabled on the feature class. However, I need the ability to have attachments enabled on this layer. When I run the model with attachments enabled I get:

RuntimeError: Objects in this class cannot be updated outside an edit session [MES_Suvey.DBO.MI.South]

Does any one know if it is possible to start an editing session within ModelBuilder?

I know I can manually enter a session within ArcMap and run successfully but I am also publishing the model as a geoprocessing service and it fails when run from a web map if the feature class has attachments enabled.

2
  • Which version of ArcMap?
    – KHibma
    Nov 5, 2021 at 18:41
  • @KHibma ArcMap Version 10.8.1
    – Ryan
    Nov 5, 2021 at 22:17

2 Answers 2

0

This cannot be achieved, this is a known limitation.

You have to Disable attachments.

And in case you are using any cursor(InsertCursor), use it outside an edit session.

0

I think you can use Calculate Value tool of the Model Builder. The main idea behind this tool to make your model flexible enough to accommodate full power of python (including arcpy package). For example, a simple case would be:

enter image description here

where the Code block is as follows for demonstration, where it assumes inline variable of field_to_be_calculated is a string field and all values will be changed to "new value":

def calculate_field_in_editing_session(fc, fld):
    ws = arcpy.os.path.dirname(fc)

    with arcpy.da.Editor(ws) as edit:
        arcpy.CalculateField_management(fc, fld, '"new value"', 'PYTHON')
    return fc

enter image description here

Please note, this workaround uses a Feature Class as an input and if the input is a feature layer, you need to use layer's data source property to be able to set workspace (e.g., ws = arcpy.os.path.dirname(fc.dataSource)).

I presume that you will be fine when publishing the model as a geoprocessing service since some ESRI examples use Calculate Value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.