Select to view content in your preferred language

How to refresh attribute table after editing data with Python script?

11999
20
Jump to solution
12-21-2023 11:53 AM
Labels (3)
AllenDailey1
Frequent Contributor

Is there a way to refresh the data in a feature class's attribute table after running a standalone Python script?

Fully closing and re-opening ArcGIS Pro does accomplish this kind of refresh.  But it would be very helpful to get it to refresh without having to close the program!

I'm using Pro 3.0.3 and cannot upgrade for a long time, due to my organization's needs relating to versions of License Manager, ArcGIS Server, existing map services and apps, etc.

I'm running a standalone Python script that edits attribute data in a feature class that's in an enterprise geodatabase.  I am both editing and viewing the default, not a version.  After running the script, the edits do not appear in Pro, unless I close and reopen the software.  I have tried closing and reopening the attribute table, refreshing the data source in the Catalog pane (you'd think that would do it, but it does not), and panning/zooming the map in Pro.  None of that makes the edits appear in the table.  Any ideas?

Thank you!

20 Replies
AnneDunckel_RapidCity
New Contributor

I've been struggling with this all morning and AI helped me come up with a creative work around. Doing an empty append to a layer seems to get it to refresh after doing any edits to an SDE dataset. Here is what Claude made up for me. Seems to work OK. Let me know if this has any issues for folk.
def refresh_sde_layer(layer):

def refresh_sde_layer(layer):
    """
    Force an ArcGIS Pro map layer to refresh after SDE edits.

    Call this after any arcpy.da cursor-based edit (update/insert/delete)
    on a versioned SDE feature class to make the changes appear on the
    map without manually hitting Versioning > Refresh.

    Parameters:
        layer: The map layer reference (e.g. from GetParameterAsText
               or map.listLayers()). Must be the layer, not a catalog path.
    """
    try:
        temp_fc = "memory/temp_refresh"
        if arcpy.Exists(temp_fc):
            arcpy.management.Delete(temp_fc)
        sr = arcpy.Describe(layer).spatialReference
        arcpy.management.CreateFeatureclass(
            "memory", "temp_refresh",
            geometry_type="POINT",
            spatial_reference=sr,
        )
        arcpy.management.Append(temp_fc, layer, "NO_TEST")
        arcpy.management.Delete(temp_fc)
    except Exception as e:
        arcpy.AddWarning(f"Could not refresh layer: {e}")