<?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: Zooming to selected features. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/zooming-to-selected-features/m-p/359126#M28341</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You will first need to create a &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#/Layer/00s300000008000000/" rel="nofollow noopener noreferrer" target="_blank"&gt;Layer&lt;/A&gt;&lt;SPAN&gt; object so you can call the 'getSelectedExtent()' method.&amp;nbsp; Ex:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
from arcpy import mapping

mxd = mapping.MapDocument("CURRENT")
df = mapping.ListDataFrames(mxd)[0]
lyr = mapping.Layer(arcpy.GetParameterAsText(0))
df.extent = lyr.getSelectedExtent()

del mxd&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 16:46:10 GMT</pubDate>
    <dc:creator>JakeSkinner</dc:creator>
    <dc:date>2021-12-11T16:46:10Z</dc:date>
    <item>
      <title>Zooming to selected features.</title>
      <link>https://community.esri.com/t5/python-questions/zooming-to-selected-features/m-p/359122#M28337</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi all,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have been told that in ArcGIS 10 we can now script display behaviors. I'm very new to scripting and trying to write a simple script that will zoom to a selected feature. The zoom would apply to all selected features in all layers in a data frame (but only the first data frame found if there are multiple). Any help on what the new code is to do this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Dec 2012 17:20:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zooming-to-selected-features/m-p/359122#M28337</guid>
      <dc:creator>Emilbrundage</dc:creator>
      <dc:date>2012-12-07T17:20:07Z</dc:date>
    </item>
    <item>
      <title>Re: Zooming to selected features.</title>
      <link>https://community.esri.com/t5/python-questions/zooming-to-selected-features/m-p/359123#M28338</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Here is an example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
df.zoomToSelectedFeatures()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:46:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zooming-to-selected-features/m-p/359123#M28338</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-11T16:46:05Z</dc:date>
    </item>
    <item>
      <title>Re: Zooming to selected features.</title>
      <link>https://community.esri.com/t5/python-questions/zooming-to-selected-features/m-p/359124#M28339</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That worked like a charm, thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Dec 2012 19:53:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zooming-to-selected-features/m-p/359124#M28339</guid>
      <dc:creator>Emilbrundage</dc:creator>
      <dc:date>2012-12-07T19:53:29Z</dc:date>
    </item>
    <item>
      <title>Re: Zooming to selected features.</title>
      <link>https://community.esri.com/t5/python-questions/zooming-to-selected-features/m-p/359125#M28340</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hmmm, now I'm trying to zoom to selections in a layer selected by the user. I see this code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;df.extent = lyr.getSelectedExtent()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;but can't quite get it to work. Here's my code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

# put map info into variable mxd
mxd = arcpy.mapping.MapDocument("CURRENT")
arcpy.AddMessage ("0")

# get layer from user
lyr = arcpy.GetParameterAsText (1)
arcpy.AddMessage ("1")

# get list of data frames
df = arcpy.mapping.ListDataFrames(mxd)[0]
arcpy.AddMessage ("2")


#zoom to the selected layer
df.extent = lyr.getSelectedExtent()
arcpy.AddMessage ("3")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The printing numbers is for my own debugging. It gets to 2, so clearly there's something wrong with "df.extent = lyr.getSelectedExtent()"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My error message:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;type 'exceptions.AttributeError'&amp;gt;: 'unicode' object has no attribute 'getSelectedExtent'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:46:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zooming-to-selected-features/m-p/359125#M28340</guid>
      <dc:creator>Emilbrundage</dc:creator>
      <dc:date>2021-12-11T16:46:07Z</dc:date>
    </item>
    <item>
      <title>Re: Zooming to selected features.</title>
      <link>https://community.esri.com/t5/python-questions/zooming-to-selected-features/m-p/359126#M28341</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You will first need to create a &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#/Layer/00s300000008000000/" rel="nofollow noopener noreferrer" target="_blank"&gt;Layer&lt;/A&gt;&lt;SPAN&gt; object so you can call the 'getSelectedExtent()' method.&amp;nbsp; Ex:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
from arcpy import mapping

mxd = mapping.MapDocument("CURRENT")
df = mapping.ListDataFrames(mxd)[0]
lyr = mapping.Layer(arcpy.GetParameterAsText(0))
df.extent = lyr.getSelectedExtent()

del mxd&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:46:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zooming-to-selected-features/m-p/359126#M28341</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-11T16:46:10Z</dc:date>
    </item>
    <item>
      <title>Re: Zooming to selected features.</title>
      <link>https://community.esri.com/t5/python-questions/zooming-to-selected-features/m-p/359127#M28342</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks tons for the help! I have a few questions that are just for my own curiosity and understanding. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1) What is the difference between what I did&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;lyr = arcpy.GetParameterAsText (1) &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;(when the 1 variable is set to layer type), and getting the layer as described in the code provided?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;lyr = mapping.Layer(arcpy.GetParameterAsText(0))&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2)&amp;nbsp; for df = mapping.ListDataFrames(mxd)[0], what does the [0] indicate?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;3) why del mxd?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any answers would be appreciated. I am sure they are very noobish questions.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Dec 2012 02:27:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zooming-to-selected-features/m-p/359127#M28342</guid>
      <dc:creator>Emilbrundage</dc:creator>
      <dc:date>2012-12-15T02:27:32Z</dc:date>
    </item>
    <item>
      <title>Re: Zooming to selected features.</title>
      <link>https://community.esri.com/t5/python-questions/zooming-to-selected-features/m-p/359128#M28343</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;1) What is the difference between what I did&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Even though you set the data type to Layer, this will not create the Layer object.&amp;nbsp; In order to call any methods for a layer, you will first need to create the object.&amp;nbsp; Also, when you use arcpy.GetParameterAsText, the first parameter is always 0 instead of 1.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2)&amp;nbsp; for df = mapping.ListDataFrames(mxd)[0], what does the [0] indicate?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The arcpy.mapping.ListDataFrames function returns a list.&amp;nbsp; The [0] indicates to use the first value in the list.&amp;nbsp; Even if you only have one data frame in your MXD, you will still need to indicate the index value for the list object.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;3) why del mxd?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This will release any locks on the MXD.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Dec 2012 10:08:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zooming-to-selected-features/m-p/359128#M28343</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2012-12-17T10:08:20Z</dc:date>
    </item>
    <item>
      <title>Re: Zooming to selected features.</title>
      <link>https://community.esri.com/t5/python-questions/zooming-to-selected-features/m-p/359129#M28344</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks a lot. The answers are very helpful.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Dec 2012 17:05:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zooming-to-selected-features/m-p/359129#M28344</guid>
      <dc:creator>Emilbrundage</dc:creator>
      <dc:date>2012-12-18T17:05:32Z</dc:date>
    </item>
  </channel>
</rss>

