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")[0]

boundary = region_map.listLayers("boundary")[0]

lyt = aprx.listLayouts()[0]

mfs = lyt.listElements("MAPFRAME_ELEMENT")

for mf in mfs:


    print("Map frame extents have been updated")

    mf.elementRotation = -17

    print("Map frames have been rotated")


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.


I think the issue is to do with your sequence of logic.

  1. You get the first layout in your map document, I assume there is always only one?
  2. From that you get all the map frames in that layout.
  3. You then try to set the extent of each map frame using a layer called boundary that you grabbed out of map called Region.

Now does boundary exist in all map frames in that layout?

Reading the help indicates you grab the extent of a layer in the map frame so the layer must exist in it, it does not appear you can grab an extent of some layer in some map and apply it to a map frame.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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