<?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 Zoom to FC in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/zoom-to-fc/m-p/361233#M28512</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;When a Fields polygon is selected the script zooms to the polygon extent.&amp;nbsp; But, I want to return the AddMessage line if the correct Feature Class is not selected. The script does not get to the else statement for other Feature Classes. But, when another polygon or polyline Feature Class is selected it zooms to full extent, as expected. So, why does the script not use the else statement for Feature Classes other than Fields?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;fds = arcpy.mapping.ListLayers(mxd, "Fields", df)[0] for fds in arcpy.mapping.ListLayers(fds): &amp;nbsp;&amp;nbsp;&amp;nbsp; desc = arcpy.Describe(fds) &amp;nbsp;&amp;nbsp;&amp;nbsp; type = desc.shapeType &amp;nbsp;&amp;nbsp;&amp;nbsp; if type == "Polygon": &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df.extent = fds.getSelectedExtent() &amp;nbsp;&amp;nbsp;&amp;nbsp; else: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Fields polygon not selected")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 15 Oct 2013 12:29:11 GMT</pubDate>
    <dc:creator>JamesSmith7</dc:creator>
    <dc:date>2013-10-15T12:29:11Z</dc:date>
    <item>
      <title>Zoom to FC</title>
      <link>https://community.esri.com/t5/python-questions/zoom-to-fc/m-p/361233#M28512</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;When a Fields polygon is selected the script zooms to the polygon extent.&amp;nbsp; But, I want to return the AddMessage line if the correct Feature Class is not selected. The script does not get to the else statement for other Feature Classes. But, when another polygon or polyline Feature Class is selected it zooms to full extent, as expected. So, why does the script not use the else statement for Feature Classes other than Fields?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;fds = arcpy.mapping.ListLayers(mxd, "Fields", df)[0] for fds in arcpy.mapping.ListLayers(fds): &amp;nbsp;&amp;nbsp;&amp;nbsp; desc = arcpy.Describe(fds) &amp;nbsp;&amp;nbsp;&amp;nbsp; type = desc.shapeType &amp;nbsp;&amp;nbsp;&amp;nbsp; if type == "Polygon": &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df.extent = fds.getSelectedExtent() &amp;nbsp;&amp;nbsp;&amp;nbsp; else: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Fields polygon not selected")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Oct 2013 12:29:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zoom-to-fc/m-p/361233#M28512</guid>
      <dc:creator>JamesSmith7</dc:creator>
      <dc:date>2013-10-15T12:29:11Z</dc:date>
    </item>
    <item>
      <title>Re: Zoom to FC</title>
      <link>https://community.esri.com/t5/python-questions/zoom-to-fc/m-p/361234#M28513</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You are probably getting your specific issue from limiting your fds variable to "Fields" only. However, you have a few other issues as well.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Primarily, these lines are very confusing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;fds = arcpy.mapping.ListLayers(mxd, "Fields", df)[0]
for fds in arcpy.mapping.ListLayers(fds):&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the first line you assign your "Fields" layer to the fds variable. Then in the second line you create a new fds variable listing the layers in your fds variable. Try writing it a little cleaner using unique variable names.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:51:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zoom-to-fc/m-p/361234#M28513</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-11T16:51:07Z</dc:date>
    </item>
    <item>
      <title>Re: Zoom to FC</title>
      <link>https://community.esri.com/t5/python-questions/zoom-to-fc/m-p/361235#M28514</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I removed the redundant statement.&amp;nbsp; I want to limit the selection to "Fields" or else return the AddMessage line.&amp;nbsp; Otherwise, the zoom will work for all Feature Classes.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My modified code now returns the AddMessage for when "Fields" are selected and when the are not.&amp;nbsp; The script still zooms to selected "Fields" and zooms to full extent when other Feature Classes are selected.&amp;nbsp; How can I get the Message to only return when a Feature Class other than "Fields" is selected?&amp;nbsp; The message retuns approx 50 times.&amp;nbsp; I just need one instance of the Message.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; for df in arcpy.mapping.ListDataFrames(mxd):&lt;BR /&gt;&amp;nbsp; for lyr in arcpy.mapping.ListLayers(mxd, "", df):&lt;BR /&gt;&amp;nbsp;&amp;nbsp; if lyr.name == "Fields":&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; df.extent = lyr.getSelectedExtent()&lt;BR /&gt;&amp;nbsp;&amp;nbsp; else:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Fields polygon not selected")&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Oct 2013 13:23:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zoom-to-fc/m-p/361235#M28514</guid>
      <dc:creator>JamesSmith7</dc:creator>
      <dc:date>2013-10-15T13:23:02Z</dc:date>
    </item>
    <item>
      <title>Re: Zoom to FC</title>
      <link>https://community.esri.com/t5/python-questions/zoom-to-fc/m-p/361236#M28515</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ideas/suggestions/comments?&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Oct 2013 18:59:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zoom-to-fc/m-p/361236#M28515</guid>
      <dc:creator>JamesSmith7</dc:creator>
      <dc:date>2013-10-15T18:59:09Z</dc:date>
    </item>
    <item>
      <title>Re: Zoom to FC</title>
      <link>https://community.esri.com/t5/python-questions/zoom-to-fc/m-p/361237#M28516</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Perhaps try explicitly stating the false condition with an elif?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for df in arcpy.mapping.ListDataFrames(mxd):
for lyr in arcpy.mapping.ListLayers(mxd, "", df):
if lyr.name == "Fields":
&amp;nbsp;&amp;nbsp;&amp;nbsp; df.extent = lyr.getSelectedExtent()
elif lyr.name != "Fields":
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Fields polygon not selected")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:51:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zoom-to-fc/m-p/361237#M28516</guid>
      <dc:creator>TimBarnes</dc:creator>
      <dc:date>2021-12-11T16:51:10Z</dc:date>
    </item>
    <item>
      <title>Re: Zoom to FC</title>
      <link>https://community.esri.com/t5/python-questions/zoom-to-fc/m-p/361238#M28517</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Perhaps try explicitly stating the false condition with an elif?&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for df in arcpy.mapping.ListDataFrames(mxd):
for lyr in arcpy.mapping.ListLayers(mxd, "", df):
if lyr.name == "Fields":
&amp;nbsp;&amp;nbsp;&amp;nbsp; df.extent = lyr.getSelectedExtent()
elif lyr.name != "Fields":
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Fields polygon not selected")&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the suggestion.&amp;nbsp; But, the AddMessage statement is returned when a "Fields" polygon is selected and when a polygon or polyline from another feature class is selected.&amp;nbsp; The AddMessage statement is still returned 50 times.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Changing the ListLayers from "" to "Fields" is the complete opposite.&amp;nbsp; The AddMessage statement is not returned for "Fields" or for another selected Feature Class.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:51:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zoom-to-fc/m-p/361238#M28517</guid>
      <dc:creator>JamesSmith7</dc:creator>
      <dc:date>2021-12-11T16:51:13Z</dc:date>
    </item>
    <item>
      <title>Re: Zoom to FC</title>
      <link>https://community.esri.com/t5/python-questions/zoom-to-fc/m-p/361239#M28518</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Unless you have multiple "Fields" layers you don't need to loop through anything.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;df = arcpy.mapping.ListDataFrames(mxd)[0]
lyr = arcpy.mapping.ListLayers(mxd, "Fields", df)[0]
df.extent = lyr.getSelectedExtent()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:51:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zoom-to-fc/m-p/361239#M28518</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-11T16:51:15Z</dc:date>
    </item>
    <item>
      <title>Re: Zoom to FC</title>
      <link>https://community.esri.com/t5/python-questions/zoom-to-fc/m-p/361240#M28519</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks, but I still do not understand the AddMessage issue.&amp;nbsp; Why does specifying "Fields" using ListLayers not return the AddMessage and leaving the ListLayers as "" returns the AddMessage for all Feature Class selections, including "Fields"?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;lyr = arcpy.mapping.ListLayers(mxd, "Fields", df)[0] - Specifies "Fields" FC&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;lyr = arcpy.mapping.ListLayers(mxd, "", df)[0] - Includes all Layers within TOC&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Oct 2013 12:12:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zoom-to-fc/m-p/361240#M28519</guid>
      <dc:creator>JamesSmith7</dc:creator>
      <dc:date>2013-10-16T12:12:21Z</dc:date>
    </item>
    <item>
      <title>Re: Zoom to FC</title>
      <link>https://community.esri.com/t5/python-questions/zoom-to-fc/m-p/361241#M28520</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This line should only return the first layer in your dataframe.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;lyr = arcpy.mapping.ListLayers(mxd, "", df)[0]&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you want to test if "Fields" has any features selected you can do this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;df = arcpy.mapping.ListDataFrames(mxd)[0] lyr = arcpy.mapping.ListLayers(mxd, "Fields", df)[0] desc = arcpy.Describe("Fields") if desc.FIDSet: &amp;nbsp;&amp;nbsp;&amp;nbsp; df.extent = lyr.getSelectedExtent() else: &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Fields polygon not selected")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Oct 2013 13:17:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zoom-to-fc/m-p/361241#M28520</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2013-10-16T13:17:07Z</dc:date>
    </item>
    <item>
      <title>Re: Zoom to FC</title>
      <link>https://community.esri.com/t5/python-questions/zoom-to-fc/m-p/361242#M28521</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The describe is what I needed.&amp;nbsp; Thanks!!!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Oct 2013 13:21:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zoom-to-fc/m-p/361242#M28521</guid>
      <dc:creator>JamesSmith7</dc:creator>
      <dc:date>2013-10-16T13:21:29Z</dc:date>
    </item>
  </channel>
</rss>

