I have a map with more than 60 layers and I want to duplicate the map many times using arcpy. I use aprx.createMap() to create an empty map and .addLayer to add layers in the loop from the "template" map. The thing is that the order of layers in the resulting map is different than in the template one. I monitor the process with prints, the iteration of adding the layers looks fine but the output is different.
How to do it properly so that order of layers is identical?
Thanks, B
Solved! Go to Solution.
You can use ArcGISProject object method .copyItem() to make an exact copy of the map within the same project.
https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/arcgisproject-class.htm
It would look something like below.
import arcpy
aprx = arcpy.mp.ArcGISProject('CURRENT')
map_obj = aprx.listMaps('TEMPLATE_MAP')[0]
map_copy = aprx.copyItem(map_obj, 'NEW_MAP')
# Further operation on the map_copy object here
aprx.save()
You can use ArcGISProject object method .copyItem() to make an exact copy of the map within the same project.
https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/arcgisproject-class.htm
It would look something like below.
import arcpy
aprx = arcpy.mp.ArcGISProject('CURRENT')
map_obj = aprx.listMaps('TEMPLATE_MAP')[0]
map_copy = aprx.copyItem(map_obj, 'NEW_MAP')
# Further operation on the map_copy object here
aprx.save()
this code sometimes work, others don't understand why, not:
SystemError: <built-in method copyItem of MappingArcGISProjectObject object at 0x00000287B656FF30> returned a result with an exception set
Works like magic! Thanks!