<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: perform zoom on NOT opened APRX in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/perform-zoom-on-not-opened-aprx/m-p/1387835#M69977</link>
    <description>&lt;P&gt;That's spirit!&amp;nbsp;&lt;/P&gt;&lt;P&gt;Actually I ran your code several times, and it perfectly works. But I modified the map_frame string as&amp;nbsp;&lt;SPAN&gt;MAPFRAME_ELEMENT"&lt;/SPAN&gt;&lt;SPAN&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;"Map&amp;nbsp;Frame* as I suggest.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;You can see the difference of this two images below&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlexanderDaniel_Pratama_0-1709088317927.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/96068i550BEF07F90B62FB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AlexanderDaniel_Pratama_0-1709088317927.png" alt="AlexanderDaniel_Pratama_0-1709088317927.png" /&gt;&lt;/span&gt;&amp;nbsp;scale 6000 with&amp;nbsp;mf.camera.scale * 1.15&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlexanderDaniel_Pratama_1-1709088346587.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/96069iBBE676667898A5E4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AlexanderDaniel_Pratama_1-1709088346587.png" alt="AlexanderDaniel_Pratama_1-1709088346587.png" /&gt;&lt;/span&gt;scale 16000 with mf.camera.scale * 3&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's your code. NOTES: please do not mind of arcpy.GetParameterAsText be removed, I just use the string to main code is fine or not.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os
import math

site_name = 'test'  
out_path = 'C:\..\TEMPLATE_COPY'
aprx = arcpy.mp.ArcGISProject(r"C:\..\TEMPLATE\LAYOUT_1.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("First Page Map")[0]
lyr = m.listLayers("POI")[0]
lyt = new_aprx.listLayouts("Layout")[0]  
mf = lyt.listElements("MAPFRAME_ELEMENT", "Map Frame*")[0]  
mf.camera.setExtent(mf.getLayerExtent(lyr, False, True ))  
if mf.camera.scale &amp;lt; 1000:   
    mf.camera.scale = 1000  
else: mf.camera.scale = mf.camera.scale * 1.15  

mf.camera.scale = math.ceil(mf.camera.scale/2000)*2000

lyt.exportToJPEG(os.path.join(out_path, 'Sample.jpeg'), resolution=200)

del new_aprx
del aprx&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did not open the aprx also. I am using ArcGIS Pro 3.2. However, I believe the Arcgis pro version does not affect the code. If everything does not work, I suggest updating the ArcGIS Pro if you do not have other concerns.&lt;/P&gt;</description>
    <pubDate>Wed, 28 Feb 2024 03:12:44 GMT</pubDate>
    <dc:creator>AlexanderDanielPratama</dc:creator>
    <dc:date>2024-02-28T03:12:44Z</dc:date>
    <item>
      <title>perform zoom on NOT opened APRX</title>
      <link>https://community.esri.com/t5/python-questions/perform-zoom-on-not-opened-aprx/m-p/1385359#M69932</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I was planning to write a script which would save a copy of aprx&amp;nbsp;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).&amp;nbsp;See below what I have prepared, but it is not performing the zoom.&amp;nbsp; I think I don't call correctly newly created aprx, but I can not figure out where is the issue. If I create&amp;nbsp;and aprx&amp;nbsp;and run the zoom on the opened aprx&amp;nbsp;(using "CURRENT") it works very well, but I would&amp;nbsp;like to do the same without needing to open it. Below is the script and I would really appreciate any feedback&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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 &amp;lt; 1000:   
   mf.camera.scale = 1000  
else: mf.camera.scale = mf.camera.scale * 1.15  
mf.camera.scale = math.ceil(mf.camera.scale/2000)*2000  &lt;/LI-CODE&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2024 12:03:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/perform-zoom-on-not-opened-aprx/m-p/1385359#M69932</guid>
      <dc:creator>Kloucek</dc:creator>
      <dc:date>2024-02-22T12:03:46Z</dc:date>
    </item>
    <item>
      <title>Re: perform zoom on NOT opened APRX</title>
      <link>https://community.esri.com/t5/python-questions/perform-zoom-on-not-opened-aprx/m-p/1385944#M69936</link>
      <description>&lt;P&gt;Hi, I think the issue is when you define &lt;STRONG&gt;mf&amp;nbsp;&lt;/STRONG&gt;variable&lt;/P&gt;&lt;P&gt;it should be&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;mf&amp;nbsp;=&amp;nbsp;lyt.listElements(&lt;/SPAN&gt;&lt;SPAN&gt;"MAPFRAME_ELEMENT"&lt;/SPAN&gt;&lt;SPAN&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;"Map&amp;nbsp;Frame*"&lt;/SPAN&gt;&lt;SPAN&gt;)[&lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;below is a glimpse of my code, which usually works for me&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlexanderDaniel_Pratama_0-1708689069501.png" style="width: 465px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/95619iD1F12F0872598F06/image-dimensions/465x121?v=v2" width="465" height="121" role="button" title="AlexanderDaniel_Pratama_0-1708689069501.png" alt="AlexanderDaniel_Pratama_0-1708689069501.png" /&gt;&lt;/span&gt;&lt;P&gt;Don't forget to delete variable aprx and new aprx using &lt;STRONG&gt;del&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Hopefully it helps you&lt;/P&gt;&lt;P&gt;Cheers.&lt;/P&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 23 Feb 2024 11:52:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/perform-zoom-on-not-opened-aprx/m-p/1385944#M69936</guid>
      <dc:creator>AlexanderDanielPratama</dc:creator>
      <dc:date>2024-02-23T11:52:47Z</dc:date>
    </item>
    <item>
      <title>Re: perform zoom on NOT opened APRX</title>
      <link>https://community.esri.com/t5/python-questions/perform-zoom-on-not-opened-aprx/m-p/1387448#M69969</link>
      <description>&lt;P&gt;HI Alexander Daniel_Pratama, thanks for getting back to me. I have tried your suggestion, but sorry it doesn't work. Anyway I will keep trying&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2024 15:39:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/perform-zoom-on-not-opened-aprx/m-p/1387448#M69969</guid>
      <dc:creator>Kloucek</dc:creator>
      <dc:date>2024-02-27T15:39:55Z</dc:date>
    </item>
    <item>
      <title>Re: perform zoom on NOT opened APRX</title>
      <link>https://community.esri.com/t5/python-questions/perform-zoom-on-not-opened-aprx/m-p/1387835#M69977</link>
      <description>&lt;P&gt;That's spirit!&amp;nbsp;&lt;/P&gt;&lt;P&gt;Actually I ran your code several times, and it perfectly works. But I modified the map_frame string as&amp;nbsp;&lt;SPAN&gt;MAPFRAME_ELEMENT"&lt;/SPAN&gt;&lt;SPAN&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;"Map&amp;nbsp;Frame* as I suggest.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;You can see the difference of this two images below&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlexanderDaniel_Pratama_0-1709088317927.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/96068i550BEF07F90B62FB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AlexanderDaniel_Pratama_0-1709088317927.png" alt="AlexanderDaniel_Pratama_0-1709088317927.png" /&gt;&lt;/span&gt;&amp;nbsp;scale 6000 with&amp;nbsp;mf.camera.scale * 1.15&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlexanderDaniel_Pratama_1-1709088346587.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/96069iBBE676667898A5E4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AlexanderDaniel_Pratama_1-1709088346587.png" alt="AlexanderDaniel_Pratama_1-1709088346587.png" /&gt;&lt;/span&gt;scale 16000 with mf.camera.scale * 3&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's your code. NOTES: please do not mind of arcpy.GetParameterAsText be removed, I just use the string to main code is fine or not.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os
import math

site_name = 'test'  
out_path = 'C:\..\TEMPLATE_COPY'
aprx = arcpy.mp.ArcGISProject(r"C:\..\TEMPLATE\LAYOUT_1.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("First Page Map")[0]
lyr = m.listLayers("POI")[0]
lyt = new_aprx.listLayouts("Layout")[0]  
mf = lyt.listElements("MAPFRAME_ELEMENT", "Map Frame*")[0]  
mf.camera.setExtent(mf.getLayerExtent(lyr, False, True ))  
if mf.camera.scale &amp;lt; 1000:   
    mf.camera.scale = 1000  
else: mf.camera.scale = mf.camera.scale * 1.15  

mf.camera.scale = math.ceil(mf.camera.scale/2000)*2000

lyt.exportToJPEG(os.path.join(out_path, 'Sample.jpeg'), resolution=200)

del new_aprx
del aprx&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did not open the aprx also. I am using ArcGIS Pro 3.2. However, I believe the Arcgis pro version does not affect the code. If everything does not work, I suggest updating the ArcGIS Pro if you do not have other concerns.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2024 03:12:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/perform-zoom-on-not-opened-aprx/m-p/1387835#M69977</guid>
      <dc:creator>AlexanderDanielPratama</dc:creator>
      <dc:date>2024-02-28T03:12:44Z</dc:date>
    </item>
    <item>
      <title>Re: perform zoom on NOT opened APRX</title>
      <link>https://community.esri.com/t5/python-questions/perform-zoom-on-not-opened-aprx/m-p/1388000#M69983</link>
      <description>&lt;P&gt;thanks again AlexanderDaniel_Pratama, still not working I am getting error on&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;mf = lyt.listElements("MAPFRAME_ELEMENT", "Map Frame*")[0]  &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;possible asterisk*? . Using ArcGIS Pro version 2.9.5. Anyway I have figure out the way, to export every Layout after being zoomed in. so added a line at the end of my scritpt&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;lyt.exportToPDF(os.path.join(out_path, lyt.name + ".pdf"), resolution=300)&lt;/LI-CODE&gt;&lt;P&gt;which is an idea I&amp;nbsp; used from you answer. All works fine now, so thanks a bunch&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2024 13:26:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/perform-zoom-on-not-opened-aprx/m-p/1388000#M69983</guid>
      <dc:creator>Kloucek</dc:creator>
      <dc:date>2024-02-28T13:26:24Z</dc:date>
    </item>
  </channel>
</rss>

