0

I have a script that zooms to the selected layer, Site Boundary (always different size, geometry and location) on specific Layout (called Elevation) and zooms to that feature. If the record is very small it rounds up to 1:1000 and zooms to 1.2 size around the feature if it's bigger than 1000. In the latter case I would like the scale to be nearest 2000 and up. Here is the script, which works fine for scales below 1000, but when bigger it works for zooming in, but not sure why its not scaling to next 2000 number.

import arcpy  
import math  
aprx = arcpy.mp.ArcGISProject("CURRENT")  
m = aprx.listMaps("Elevation")[0]  
lyr = m.listLayers("Site Boundary")[0]  
lyt = aprx.listLayouts("Elevation")[0]  
mf = lyt.listElements("mapframe_element", "Map" )[0]  
mf.camera.setExtent(mf.getLayerExtent(lyr, False, True ))  
if mf.camera.scale < 1000:  
   mf.camera.scale = 1000  
else: mf.camera.scale = mf.camera.scale * 1.2  
math.ceil(mf.camera.scale/2000)*2000

2 Answers 2

0

I believe your problem is how you've written your final line: math.ceil(mf.camera.scale/2000)*2000

You're applying the math.ceil (rounding up function) on a number and never using it besides * 2000. This number is never actually used to adjust the camera scale.

Let's assume you have 2000 as your scale. This will hit the else, so 2000 * 1.2 = 2400. Your last line of code then evaluates to:

(ROUND ( 2400 / 2000) ) * 2000 = 4000.

This value of 4000 is not applied to anything. Do you mean to do: mf.camera.scale = math.ceil(mf.camera.scale/2000)*2000 ?

2
  • great thanks for you help. it worked fine
    – user113001
    Commented Aug 23, 2023 at 12:38
  • thanks again @KHibma, works fine on "current", but if I wan to do it as 1) save a copy of aprx 2) zoom to layer (s) and 3) export pdf my script would not fail, but it would not do the zoom properly. Do you know why that would be?
    – user113001
    Commented Aug 24, 2023 at 17:10
0

What I believe you want is as follows.

    else:
         increase_scale = mf.camara.scale * 1.2
         mf.camara.scale = math.ceil(increase_scale/2000) * 2000

increase_scale holds the 20% larger value than the current scale. This rounds up the nearest factor of 2000, then multiplies by 2000 to make map frame have the next scale divisible by 2000.

1
  • thansk for getting back to me with better suggestion
    – user113001
    Commented Aug 23, 2023 at 12:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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