Trying to create a toolbox that will run locate features along routes for all layers in two separate Maps in ArcGIS Pro. Code snippet is below.

aprx = arcpy.mp.ArcGISProject("CURRENT")
myMap = aprx.listMaps("Map")[0]
myMap1 = aprx.listMaps("Map")[1]

out_table = arcpy.GetParameterAsText(0)
in_routes = arcpy.GetParameterAsText(1)

for lyr in myMap.listLayers():
    arcpy.lr.LocateFeaturesAlongRoutes(lyr, in_routes, "RouteId", "0 Feet", out_table, "RouteId Line FMEAS TMEAS", "FIRST", "DISTANCE", "ZERO", "FIELDS", "M_DIRECTON")

for lyr in myMap1.listLayers():
    arcpy.lr.LocateFeaturesAlongRoutes(lyr, in_routes, "RouteId", "0 Feet", out_table, "RouteId Point FMEAS", "FIRST", "DISTANCE", "ZERO", "FIELDS", "M_DIRECTON")

Returns an

IndexErrror: list index out of range
  • Please Edit the Question to indicate where the error occurs
    – Vince
    Commented Jun 2, 2022 at 0:17
  • aprx.listMaps("Map") returns either 0 or 1 items but you're trying to access the first and second.
    – mikewatt
    Commented Jun 2, 2022 at 0:44

1 Answer 1


Unless both of your maps are named "Map", then aprx.listMaps("Map")[index] won't work.

Read the doc - The listMaps method optionally expects a wildcard string, so "Map" will only match maps called "Map" exactly.

Try something like:

# Assumes exactly 2 maps in aprx
map1, map2 = aprx.listMaps()  

# or

# Assumes first 2 maps in aprx are the ones
maps = aprx.listMaps() 
map1 = maps[0]
map2 = maps[1]

# or  

# Assumes only 2 maps in aprx called Map*, e.g Map and Map2
map1, map2 = aprx.listMaps("Map*")

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.