I am trying to write a script that accomplishes 2 tasks: change the extent of all map frames using a boundary layer as reference and rotate the map frames by -17 degrees. To complete the first task, I decided to use the
getLayerExtent() method to retrieve the extent of the boundary layer, then assign each mapframes' extent by using
setExtent(). Unfortunately, I cannot get past this first task.
When trying to run the
getLayerExtent() method in my script I am met with an error that reads:
ValueError: MappingLayerObject object at 0x000002210CE738A0
Needless to say, the error message isn't very descriptive and doesn't offer many hints on how to tackle it. When searching online, I could not find many examples on how to use this method or even how to fix the value error.
Below is my script where I try to use the specified method:
import arcpy aprx = arcpy.mp.ArcGISProject("C:/JHU406Lab7/Lab7/Toronto/Toronto_Overview.aprx") region_map = aprx.listMaps("Region") boundary = region_map.listLayers("boundary") lyt = aprx.listLayouts() mfs = lyt.listElements("MAPFRAME_ELEMENT") for mf in mfs: mf.camera.setExtent(mf.getLayerExtent(boundary)) print("Map frame extents have been updated") mf.elementRotation = -17 print("Map frames have been rotated") aprx.saveACopy("C:/JHU406Lab7/Lab7/Toronto/Toronto_Overview_q5.aprx") del aprx
To use the
getLayerElements() method, I first had to retrieve the boundary layer by specifying the map and layer. I then retrieved the layout and the list of map elements I want to iterate. Lastly, I tried to iterate through each map frame and use the
getLayerExtent() method. I'm stumped on what is causing this error.