I have a set of polylines as a layer in ArcGIS Pro in a table layer. I can highlight/visualize each polyline by clicking on the side of each row in the table. It is a time consuming process. I tried to automate this using python code in python code in a way that the code iterate through each row. Code still highlights the last polyline when code run is complete. I want it to highlight all polylines one by one. I introduce time function to delay the process but it does not work either. Here is the code below.
import time # Import the time module to add a delay
# Access the current ArcGIS Pro project and map
aprx = arcpy.mp.ArcGISProject("CURRENT")
mp = aprx.activeMap
# Specify the layer name and retrieve the layer object
layer_name = "Tracks_Polylines"
layer = mp.listLayers(layer_name)[0]
# Get a list of all unique TrackID values in the layer
with arcpy.da.SearchCursor(layer, ["TrackID"]) as cursor:
track_ids = sorted({row[0] for row in cursor}) # Use a set to get unique TrackIDs
# Loop through each TrackID and perform selection with a delay
for track_id in track_ids:
where_clause = f"TrackID = {track_id}"
arcpy.management.SelectLayerByAttribute(layer, "NEW_SELECTION", where_clause)
# print the current TrackID
print(f"Highlighting TrackID: {track_id}")
# Refresh the map view to ensure the selection is visible
arcpy.RefreshActiveView()
# Pause for a few seconds before moving to the next TrackID
time.sleep(2) # Adjust the duration as needed (2 seconds in this case)
# Clear the selection after processing all TrackIDs
arcpy.management.SelectLayerByAttribute(layer, "CLEAR_SELECTION")