I was planning to write a script which would save a copy of aprx from the template and perform the zoom on all Layouts. Just to simplify things I will give an example of one Layout. On Layout called Elevation, zoom should be performed to Site Boundary (always different size, geometry, and location). See below what I have prepared, but it is not performing the zoom. I think I don't call correctly newly created aprx, but I can not figure out where is the issue. If I create and aprx and run the zoom on the opened aprx (using "CURRENT") it works very well, but I would like to do the same without needing to open it. Below is the script and I would really appreciate any feedback
import arcpy, os
import math
def path_file(path):
path_split = path.split(os.sep)
site_name = arcpy.GetParameterAsText(0)
out_path = arcpy.GetParameterAsText (1)
aprx = arcpy.mp.ArcGISProject(r"C:\...\Template.aprx")
aprx.saveACopy(out_path + os.sep + site_name + ".aprx")
new_aprx = arcpy.mp.ArcGISProject(out_path + os.sep + site_name + ".aprx")
m = new_aprx.listMaps("Elevation")[0]
lyr = m.listLayers("Site Boundary")[0]
lyt = new_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.15
mf.camera.scale = math.ceil(mf.camera.scale/2000)*2000