11

I am running the Calculate Field GP tool from the arcpy in ArcMap. When a row value is updated, it does not show up untill I use the Reload Cache tool (Table Options > Reload Cache). How do I refresh the attribute table automatically without using ArcObjects?

I have tried updating the definition query as @blah238 suggested Using python, how do you "reload cache" an opened Attribute Table, but this doesn't help. Resetting the data source is not an option because the feature class might be in the editing session and I don't want to lose the connection to the source data.

  • Are you using ArcGIS 10.1? If so are you using a Python Add-in or a Python script tool to run Calculate Field? – PolyGeo May 7 '13 at 7:59
  • 1
    Does it really matter? I am calling the Calculate Field GP tool from a Python Add-in, but the same thing is observed when running the GP tool from the Python window. – Alex Tereshenkov May 7 '13 at 8:13
  • 1
    I always figure that if I am going to try and reproduce a problem, then the most likely way I will see it is if I do exactly (or as close as I can get to) the same steps in the same configuration as it has been seen before. – PolyGeo May 7 '13 at 9:37
4

You appear to be hitting a limitation of ArcPy, in the absence of ArcObjects.

The limitations of ArcPy.mapping have been broadly described here as:

Arcpy.mapping is not a replacement for ArcObjects but rather an alternative for the different scenarios it supports. ArcObjects is still necessary for finer-grain development and application customization, whereas arcpy.mapping is intended for automating the contents of existing map documents and layer files.

If @blah238's other suggestion of using ArcObjects from ArcPy is not an option for you, then you may be best to submit an ArcGIS Idea to have this functionality exposed to ArcPy. If you post a link to such an ArcGIS Idea here then I will be happy to vote for it.

  • Thanks PolyGeo, pity we cannot find a way to refresh the attribute table when calculating field values outside the editing session. – Alex Tereshenkov May 7 '13 at 12:45
  • 1
    You might submit an enhancement request to ESRI tech support. I requested the ability to just have a button, menu option or F key to refresh the table to show changes without manually closing and opening. I was told the table should update on its own and the matter was closed as not locally reproducible. Usually they are helpful. I got the impression they are not even aware of the limitations. – johns May 7 '13 at 21:37
  • I recommend doing both of the above but ArcGIS Ideas lets you monitor popularity & implementation progress much more easily than local support here. – PolyGeo May 7 '13 at 22:04
  • 1
    @johns, do you know that you don't have to close and open the attribute table to refresh it? The current way to do this is to click Table Options button > Reload Cache. Another thing that works is to run the Calculate Field operation in the editing mode, then the values in the attribute tables are updated immediately. – Alex Tereshenkov May 8 '13 at 9:03
  • 1
    @Alex, thanks for the suggestion; it made me go back to test the issue further. I have used the reload cache but it failed/fails when I've added polygons in edit mode in layout view using an addin to get the layout extent. When in data view and I use the same addin, then the reload cache works. So it somehow involves the layout view. – johns May 8 '13 at 14:18
3

This may or may not be useful to your for your specific workflow. I have found that if you change the selection on your layer then the attribute table updates too.

So I often use

arcpy.SelectLayerByAttribute_management("MY-LAYER","CLEAR_SELECTION")

Of course if you actually have something selected that you don't want to loose track of then this is no good. In that case you might select from layer where OID is in list of OIDs from currently selected features (basically change selection to whatever is already currently selected). This might take to long to be practically, I have never tried it in a real life scenario.

1

Have you tried:

arcpy.RefreshCatalog(target) # Set the target to your layers data source

or

arcpy.RefreshActiveView() # Refreshes the map

or

arcpy.RefreshTOC() # I highly doubt this will do anything, but you never know

I think one of these will work, but I know sometimes in ArcMap I have to manually close the attribute table then re-open it to see some edits. I'm not sure if closing and opening the table can be done with ArcPy, but that would also be an option.

  • Thansk, Cody, unfortunately, nothing of this works. Closing and opening the attribute table manually does the trick, however I am looking for something that would do that programmatically. Opening and closing attribute table is not available with Python either. – Alex Tereshenkov May 6 '13 at 14:54
  • None of these are designed to refresh the attribute table. – Radar Jan 10 '17 at 17:10
1

This works:

    import arcpy

    definition_query = layer.definitionQuery
    # Change the Definition Query into something different
    if definition_query == '':
        oid = arcpy.ListFields(dataset = layer, field_type = 'OID')[0]
        layer.definitionQuery = '{} > 0'.format(oid.name)
    else:
        layer.definitionQuery = ''
    arcpy.RefreshActiveView()

    # Restore the Definition Query
    layer.definitionQuery = definition_query
    arcpy.RefreshActiveView()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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