<?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 Selected Layer in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/get-selected-layer/m-p/472179#M36879</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;How about:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#prints a list of the selected layers in the TOC along with the number of selected records
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
for lyr in arcpy.mapping.ListLayers(df):
&amp;nbsp;&amp;nbsp; selectedCount = len([int(fid) for fid in arcpy.Describe(lyr).fidset.split(";") if fid != ''])
&amp;nbsp;&amp;nbsp; if selectedCount &amp;gt; 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "The " + str(lyr) + " layer has " + str(selectedCount) + " records selected..."&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 20:53:05 GMT</pubDate>
    <dc:creator>ChrisSnyder</dc:creator>
    <dc:date>2021-12-11T20:53:05Z</dc:date>
    <item>
      <title>Get Selected Layer</title>
      <link>https://community.esri.com/t5/python-questions/get-selected-layer/m-p/472177#M36877</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm looking for a way to get the currently selected layer(s) from the TOC.&amp;nbsp; arcpy.mapping.ListLayers() returns all layers in the data frame.&amp;nbsp; I only want the ones the user has selected.&amp;nbsp; Does anyone know how to do this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ted Chapin&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SGC Engineering&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Apr 2013 12:03:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-selected-layer/m-p/472177#M36877</guid>
      <dc:creator>TedChapin</dc:creator>
      <dc:date>2013-04-24T12:03:37Z</dc:date>
    </item>
    <item>
      <title>Re: Get Selected Layer</title>
      <link>https://community.esri.com/t5/python-questions/get-selected-layer/m-p/472178#M36878</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;As of 10.1 you can return a handle on a &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;single&lt;/SPAN&gt;&lt;SPAN&gt; selected layer, have a look at this &lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/94198-determining-selected-layers-in-the-table-of-contents-with-arcpy"&gt;thread&lt;/A&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Nov 2013 13:21:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-selected-layer/m-p/472178#M36878</guid>
      <dc:creator>DuncanHornby</dc:creator>
      <dc:date>2013-11-25T13:21:36Z</dc:date>
    </item>
    <item>
      <title>Re: Get Selected Layer</title>
      <link>https://community.esri.com/t5/python-questions/get-selected-layer/m-p/472179#M36879</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;How about:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#prints a list of the selected layers in the TOC along with the number of selected records
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
for lyr in arcpy.mapping.ListLayers(df):
&amp;nbsp;&amp;nbsp; selectedCount = len([int(fid) for fid in arcpy.Describe(lyr).fidset.split(";") if fid != ''])
&amp;nbsp;&amp;nbsp; if selectedCount &amp;gt; 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "The " + str(lyr) + " layer has " + str(selectedCount) + " records selected..."&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:53:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-selected-layer/m-p/472179#M36879</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-11T20:53:05Z</dc:date>
    </item>
  </channel>
</rss>

