How to set the layout scale from a list of scales using arcpy

465
1
Jump to solution
05-20-2024 03:40 AM
Abhinav_Cherukat
Emerging Contributor

Hi,

I'm trying to change the map frame scale (or layout scale) to match the scale given in the list of scales.

For some reason, it isn't changing the layout scale, but if I print this code, it shows the scale (in my case it is a change from 13800 to 15000)

 

Please find the code below: 

 

Main_Map = lyt.listElements('MapFrame_Element', "Main Frame Map Frame")[0]

#Main_Map.camera.setExtent(Main_Map.getLayerExtent(lyr,True, True))

scales = [2500, 5000, 10000, 15000, 20000, 25000]

current_scale = Main_Map.camera.scale

next_scale = min([scale for scale in scales if scale > current_scale], default=None)

if next_scale:
mf_extent = Main_Map.getLayerExtent(lyr)
mf_extent.scale = next_scale
Main_Map.camera.setExtent(mf_extent)

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
Abhinav_Cherukat
Emerging Contributor

Hey all,

I figured it out after some intense research and testing different stuffs.

Below is the fix:

mp = aprx.listMaps("Map")[0]
lyt = aprx.listLayouts("A3 Layout1")[0]

Main_Map = lyt.listElements('MapFrame_Element', "Main Frame Map Frame")[0]
Main_Map.map = mp
Main_Map.camera.setExtent(Main_Map.getLayerExtent(lyr,True, True))
scales = [1250.0, 2500.0, 5000.0, 10000.0, 15000.0, 20000.0, 25000.0]
next_scale = None
for scale in scales:
      if scale > Main_Map.camera.scale:
          if next_scale is None or scale < next_scale:
             next_scale = scale
Main_Map.camera.scale = next_scale

View solution in original post

0 Kudos
1 Reply
Abhinav_Cherukat
Emerging Contributor

Hey all,

I figured it out after some intense research and testing different stuffs.

Below is the fix:

mp = aprx.listMaps("Map")[0]
lyt = aprx.listLayouts("A3 Layout1")[0]

Main_Map = lyt.listElements('MapFrame_Element', "Main Frame Map Frame")[0]
Main_Map.map = mp
Main_Map.camera.setExtent(Main_Map.getLayerExtent(lyr,True, True))
scales = [1250.0, 2500.0, 5000.0, 10000.0, 15000.0, 20000.0, 25000.0]
next_scale = None
for scale in scales:
      if scale > Main_Map.camera.scale:
          if next_scale is None or scale < next_scale:
             next_scale = scale
Main_Map.camera.scale = next_scale

0 Kudos