Hello,
I am working on an automated map script that will allow me to import a Shapefile, assign it a pre-defined symbology, zoom to a layer and export a map. I am having one issue when I bring in my input file. I am using the addDataFromPath() function to bring in my data, and it indeed brings it in fine. However, the file shows up in my table of contents and legend with the text "_Layer2", "_Layer3" etc, after the name of the file I bring it.
I would like to simply rename what is in my legend and TOC to something I want such as "Project Area" or "AOI", etc.
Does anyone here have the experience with arcpy.mp to get that to work?
Thank you for your time!
Solved! Go to Solution.
Hi @ParkGIS307 ,
You can use the following code snippet to rename feature layers in TOC using arcpy:
aprx = arcpy.mp.ArcGISProject("CURRENT")
map = aprx.listMaps()[0]
for lyr in map.listLayers():
print(lyr.name)
# Here this renames a layer that has a keyword "Building" in it to "BuildingFootprint" in TOC
if "Building" in lyr.name:
layerName = str(lyr.name)
lyr.name = lyr.name.replace(layerName, "BuildingFootprint")
print(f"Layer renamed to: {lyr.name}")
this can be extended to more layers.
I hope that is insightful.
"name" in the CIM layer class is read/write
Layer—ArcGIS Pro | Documentation
did you try it?
My knowledge on CIM syntax is scant. So I have not tried it yet. I will read up on it more though.
Hi @ParkGIS307 ,
You can use the following code snippet to rename feature layers in TOC using arcpy:
aprx = arcpy.mp.ArcGISProject("CURRENT")
map = aprx.listMaps()[0]
for lyr in map.listLayers():
print(lyr.name)
# Here this renames a layer that has a keyword "Building" in it to "BuildingFootprint" in TOC
if "Building" in lyr.name:
layerName = str(lyr.name)
lyr.name = lyr.name.replace(layerName, "BuildingFootprint")
print(f"Layer renamed to: {lyr.name}")
this can be extended to more layers.
I hope that is insightful.