0

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")

1 Answer 1

2

It's unclear why you want to do this and personally I think you are going down the wrong road with your coding route. That said if you want to show features turn on/off one after another then you could "abuse" the range property of a feature layer.

So using a polygon dataset I had created and uniquely numbered I set the layers range properties as shown below. 25 comes from there being 25 rows in the featureclass.

Properties

You now have a range tab in the ribbon and I set min and max to be both 1 as shown below and active the range.

Ribbon

Finally click on the play button and you get this...

Animation

Zero coding!

2
  • Great :-). Yes it requires 0 coding. The only issue I am having now that it shows the value inside "Steps Interval" as 4. I would like to set it to 1 but it changes back to 4. Any suggestion.
    – Riz
    Commented Aug 14 at 13:05
  • 1
    Set min/max to 1 in current range, see video.
    – Hornbydd
    Commented Aug 14 at 16:58

Your Answer

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

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