Select to view content in your preferred language

How do I set the map in a layout mapframe with python in Arc Pro?

2166
12
08-03-2022 07:08 AM
by Anonymous User
Not applicable
 
0 Kudos
12 Replies
by Anonymous User
Not applicable

Hi Josh

All the objects are correct and if I run the script without the last line it doesn't return an error. 

Not sure what else to try, which is a shame! I will keep searching for a solution.

0 Kudos
by Anonymous User
Not applicable

I'm not sure if you interested but the below works in terms of setting the extent if you manually select the map you want for the mapframe first:

aprx = arcpy.mp.ArcGISProject("CURRENT")

m = aprx.listMaps("Osterley_Boundary")[0]
lyr = m.listLayers("Osterley")[0]
lyt = aprx.listLayouts("Property_Boundary")[0]
mf = lyt.listElements("MAPFRAME_ELEMENT", "Map Frame 1")[0]
mf.camera.setExtent(mf.getLayerExtent(lyr, False, True))

0 Kudos
RandyMcGregor_BMcD
Frequent Contributor

Is it possible to identify the selected - or active - map frame? If this is obvious, sorry, but I have not been able to find it. I have a script that creates a polygon from a map frame extent and the user has to enter the map name to make sure I am running on the right map frame (the script picks the map frame based on the map that is selected. Kind of awkward, but may be necessary).

Thank you,

Randy

0 Kudos