<?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: Get Extend of mapframe in Layout in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/get-extend-of-mapframe-in-layout/m-p/1527800#M71316</link>
    <description>&lt;P&gt;Are you sure that the extent is wrong? I think it should be the correct extent? Maybe you could test it if you use&amp;nbsp; mapFrame.camera.setExtent(arcpy.Describe(lyr).extent) to zoom in the map Frame to another extent, the one of a layer file in your map Frame?&lt;/P&gt;&lt;P&gt;There's&amp;nbsp; also a solution here:&lt;/P&gt;&lt;P&gt;&lt;A href="https://gis.stackexchange.com/questions/467522/adding-data-to-existing-aprx-layout-and-zooming-to-extent-of-new-data-using-arc" target="_blank"&gt;https://gis.stackexchange.com/questions/467522/adding-data-to-existing-aprx-layout-and-zooming-to-extent-of-new-data-using-arc&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 27 Aug 2024 11:59:03 GMT</pubDate>
    <dc:creator>JohannesBierer</dc:creator>
    <dc:date>2024-08-27T11:59:03Z</dc:date>
    <item>
      <title>Get Extend of mapframe in Layout</title>
      <link>https://community.esri.com/t5/python-questions/get-extend-of-mapframe-in-layout/m-p/1527631#M71310</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have look online for two days and cannot find the solution.&lt;/P&gt;&lt;P&gt;What I try to achieve is to get my mapframe extend &lt;U&gt;in the layout&lt;/U&gt; and not the current map extend &lt;U&gt;in the mapview&lt;/U&gt;.&lt;/P&gt;&lt;P&gt;The Dynamic text offer to have it but I do not know how to acces sit in arpcy&lt;/P&gt;&lt;P&gt;In the mapframe "extend" &amp;gt; "use a custome extend" &amp;gt; "current visible extend" it is displayed. Same here, I do not know how to access it.&lt;/P&gt;&lt;P&gt;The code below displays the map extend&lt;U&gt; from the map view&lt;/U&gt;, not the actual extend in the layout.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;def get_layout_bbox(layout_name):&lt;/P&gt;&lt;P&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")&lt;BR /&gt;layouts = aprx.listLayouts(layout_name)&lt;/P&gt;&lt;P&gt;if not layouts:&lt;BR /&gt;raise ValueError(f"No layout found with the name {layout_name}")&lt;/P&gt;&lt;P&gt;layout = layouts[0]&lt;BR /&gt;&lt;BR /&gt;layout_metadata = layout.metadata&lt;BR /&gt;&lt;BR /&gt;# Get the layout's name or any other property as a title&lt;BR /&gt;layout_title = layout_metadata.title&lt;BR /&gt;&lt;BR /&gt;# Reference to the last map frame in the layout&lt;BR /&gt;last_map_frame = layout.listElements("MAPFRAME_ELEMENT")[-1]&lt;/P&gt;&lt;P&gt;# Get the extent of the current map frame&lt;BR /&gt;extent = last_map_frame.camera.getExtent()&lt;/P&gt;&lt;P&gt;# Get the spatial reference of WGS 84&lt;BR /&gt;wgs84_sr = arcpy.SpatialReference(4326)&lt;/P&gt;&lt;P&gt;# Project the extent to WGS 84&lt;BR /&gt;projected_extent = extent.projectAs(wgs84_sr)&lt;/P&gt;&lt;P&gt;# Format the bounding box&lt;BR /&gt;bbox = (&lt;BR /&gt;f"{round(projected_extent.XMin, 6)}, "&lt;BR /&gt;f"{round(projected_extent.YMin, 6)}, "&lt;BR /&gt;f"{round(projected_extent.XMax, 6)}, "&lt;BR /&gt;f"{round(projected_extent.YMax, 6)}"&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;return layout_title, bbox&lt;/P&gt;&lt;P&gt;if __name__ == "__main__":&lt;BR /&gt;# Get the layout name from the tool's parameters&lt;BR /&gt;layout_name = arcpy.GetParameterAsText(0)&lt;/P&gt;&lt;P&gt;# Get the layout title and bounding box&lt;/P&gt;&lt;P&gt;arcpy.AddMessage(f"_"*25)&lt;BR /&gt;layout_title, bbox = get_layout_bbox(layout_name)&lt;BR /&gt;arcpy.AddMessage(f"Layout Title: {layout_title}")&lt;BR /&gt;arcpy.AddMessage(f"Bounding Box: {bbox}")&lt;BR /&gt;arcpy.AddMessage(f"_"*25)&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Do you know how can I access the map extend in the layout ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Alex&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2024 06:05:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-extend-of-mapframe-in-layout/m-p/1527631#M71310</guid>
      <dc:creator>Alex_gis</dc:creator>
      <dc:date>2024-08-27T06:05:42Z</dc:date>
    </item>
    <item>
      <title>Re: Get Extend of mapframe in Layout</title>
      <link>https://community.esri.com/t5/python-questions/get-extend-of-mapframe-in-layout/m-p/1527652#M71311</link>
      <description>&lt;P&gt;&lt;A href="https://community.esri.com/t5/python-blog/code-formatting-the-community-version/ba-p/1007633" target="_blank"&gt;Code formatting ... the Community Version - Esri Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;to format your code to make it easier to comment on&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2024 06:53:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-extend-of-mapframe-in-layout/m-p/1527652#M71311</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2024-08-27T06:53:46Z</dc:date>
    </item>
    <item>
      <title>Re: Get Extend of mapframe in Layout</title>
      <link>https://community.esri.com/t5/python-questions/get-extend-of-mapframe-in-layout/m-p/1527662#M71312</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the snipped code:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

def get_layout_bbox(layout_name):
    aprx = arcpy.mp.ArcGISProject("CURRENT")
    layouts = aprx.listLayouts(layout_name)

    if not layouts:
        raise ValueError(f"No layout found with the name {layout_name}")
    
    # Select the layout
    layout = layouts[0]
    
    # Access layout metadata
    layout_metadata = layout.metadata
    
    # Get the layout's name or any other property as a title
    layout_title = layout_metadata.title  
    
    # Reference to the last map frame in the layout
    last_map_frame = layout.listElements("MAPFRAME_ELEMENT")[-1]

    # Get the extent of the current map frame
    extent = last_map_frame.camera.getExtent()

    # Get the spatial reference of WGS 84
    wgs84_sr = arcpy.SpatialReference(4326)

    # Project the extent to WGS 84
    projected_extent = extent.projectAs(wgs84_sr)

    # Format the bounding box
    bbox = (
        f"{round(projected_extent.XMin, 6)}, "
        f"{round(projected_extent.YMin, 6)}, "
        f"{round(projected_extent.XMax, 6)}, "
        f"{round(projected_extent.YMax, 6)}"
    )

    return layout_title, bbox

if __name__ == "__main__":
    # Get the layout name from the tool's parameters
    layout_name = arcpy.GetParameterAsText(0)

    # Get the layout title and bounding box
    arcpy.AddMessage(f"_"*25)
    layout_title, bbox = get_layout_bbox(layout_name)
    arcpy.AddMessage(f"Layout Title: {layout_title}")
    arcpy.AddMessage(f"Bounding Box: {bbox}")
    arcpy.AddMessage(f"_"*25)
    &lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 27 Aug 2024 07:40:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-extend-of-mapframe-in-layout/m-p/1527662#M71312</guid>
      <dc:creator>Alex_gis</dc:creator>
      <dc:date>2024-08-27T07:40:09Z</dc:date>
    </item>
    <item>
      <title>Re: Get Extend of mapframe in Layout</title>
      <link>https://community.esri.com/t5/python-questions/get-extend-of-mapframe-in-layout/m-p/1527685#M71314</link>
      <description>&lt;P&gt;I don't know how the extent could be accessed other than through the camera, however, there is more details information on the cim at....&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/Esri/cim-spec" target="_blank"&gt;Esri/cim-spec: This repository hosts the specification for the Cartographic Information Model (github.com)&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2024 08:19:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-extend-of-mapframe-in-layout/m-p/1527685#M71314</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2024-08-27T08:19:02Z</dc:date>
    </item>
    <item>
      <title>Re: Get Extend of mapframe in Layout</title>
      <link>https://community.esri.com/t5/python-questions/get-extend-of-mapframe-in-layout/m-p/1527800#M71316</link>
      <description>&lt;P&gt;Are you sure that the extent is wrong? I think it should be the correct extent? Maybe you could test it if you use&amp;nbsp; mapFrame.camera.setExtent(arcpy.Describe(lyr).extent) to zoom in the map Frame to another extent, the one of a layer file in your map Frame?&lt;/P&gt;&lt;P&gt;There's&amp;nbsp; also a solution here:&lt;/P&gt;&lt;P&gt;&lt;A href="https://gis.stackexchange.com/questions/467522/adding-data-to-existing-aprx-layout-and-zooming-to-extent-of-new-data-using-arc" target="_blank"&gt;https://gis.stackexchange.com/questions/467522/adding-data-to-existing-aprx-layout-and-zooming-to-extent-of-new-data-using-arc&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2024 11:59:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-extend-of-mapframe-in-layout/m-p/1527800#M71316</guid>
      <dc:creator>JohannesBierer</dc:creator>
      <dc:date>2024-08-27T11:59:03Z</dc:date>
    </item>
  </channel>
</rss>

