<?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: Getting names of layers with selected features in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/getting-names-of-layers-with-selected-features/m-p/743255#M57445</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If&amp;nbsp; you are using &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-mapping/listlayers.htm"&gt;ListLayers&lt;/A&gt;, you might want to take another look at the documentation.&amp;nbsp; From your question in a related thread, it appeared that you might only be referencing the active data frame.&amp;nbsp; ListLayers requires a map document reference and an optional reference to the data frame.&amp;nbsp; Hope this helps.&lt;/P&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;ListLayers (map_document_or_layer, {wildcard}, {data_frame})&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 20 Mar 2019 19:38:42 GMT</pubDate>
    <dc:creator>RandyBurton</dc:creator>
    <dc:date>2019-03-20T19:38:42Z</dc:date>
    <item>
      <title>Getting names of layers with selected features</title>
      <link>https://community.esri.com/t5/python-questions/getting-names-of-layers-with-selected-features/m-p/743248#M57438</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'd like to get the names of any layer that has at least 1 selected feature.&amp;nbsp; A function is building a bunch of selections, after which I want to find the names of those layers that have selections within to do more stuff.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've tried:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for layer in layers:&lt;/P&gt;&lt;P&gt;&amp;nbsp; if len(layer.getSelectionSet()) &amp;gt; 0:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;print layer.name&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;which returns all the layers, even those with no selection.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've also tried something very similar to:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for layer in layers:&lt;/P&gt;&lt;P&gt;&amp;nbsp; if layer.getFIDSet != '':&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; print layer.name&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;which gives me an error message.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am a bit stumped.&amp;nbsp; I'll be using the output from this to create layer-specific messages based on if / elif statements, if that context helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Mar 2019 22:31:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-names-of-layers-with-selected-features/m-p/743248#M57438</guid>
      <dc:creator>AlanDodson</dc:creator>
      <dc:date>2019-03-19T22:31:32Z</dc:date>
    </item>
    <item>
      <title>Re: Getting names of layers with selected features</title>
      <link>https://community.esri.com/t5/python-questions/getting-names-of-layers-with-selected-features/m-p/743249#M57439</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You might try:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;for layer in layers:
    if layer.getSelectionSet() is not None:
        print layer.name, len(layer.getSelectionSet())&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 07:37:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-names-of-layers-with-selected-features/m-p/743249#M57439</guid>
      <dc:creator>RandyBurton</dc:creator>
      <dc:date>2021-12-12T07:37:54Z</dc:date>
    </item>
    <item>
      <title>Re: Getting names of layers with selected features</title>
      <link>https://community.esri.com/t5/python-questions/getting-names-of-layers-with-selected-features/m-p/743250#M57440</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Unfortunately I'm getting an error on line 2 of that code:&amp;nbsp; 'str' object has no attribute 'getSelectionSet'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any ideas?&amp;nbsp;&amp;nbsp;Is it finding strings when it shouldn't be?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Mar 2019 11:59:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-names-of-layers-with-selected-features/m-p/743250#M57440</guid>
      <dc:creator>AlanDodson</dc:creator>
      <dc:date>2019-03-20T11:59:29Z</dc:date>
    </item>
    <item>
      <title>Re: Getting names of layers with selected features</title>
      <link>https://community.esri.com/t5/python-questions/getting-names-of-layers-with-selected-features/m-p/743251#M57441</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; layer &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; layers&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; layer&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;getSelectionSet&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
        &lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt; layer&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 07:37:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-names-of-layers-with-selected-features/m-p/743251#M57441</guid>
      <dc:creator>MatthewDriscoll</dc:creator>
      <dc:date>2021-12-12T07:37:57Z</dc:date>
    </item>
    <item>
      <title>Re: Getting names of layers with selected features</title>
      <link>https://community.esri.com/t5/python-questions/getting-names-of-layers-with-selected-features/m-p/743252#M57442</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Given that error, how are you creating the layers list because my guess is that the list you are processing contains strings of layer names and not layer objects/references themselves.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Mar 2019 16:02:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-names-of-layers-with-selected-features/m-p/743252#M57442</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2019-03-20T16:02:25Z</dc:date>
    </item>
    <item>
      <title>Re: Getting names of layers with selected features</title>
      <link>https://community.esri.com/t5/python-questions/getting-names-of-layers-with-selected-features/m-p/743253#M57443</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The list where I got that error was strings of layer names, you are correct.&amp;nbsp; Sorry for not specifying that more clearly in the OP.&amp;nbsp; What would I need to change in this scenario to get the expected result, or is it too far gone now...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Later on in my script I need to run that again - this time it is running on layer objects returned from listing the layers in my dataframe and even though there are selected features within the layers, no result is given.&amp;nbsp; There is no error, but there is also no result.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Mar 2019 17:03:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-names-of-layers-with-selected-features/m-p/743253#M57443</guid>
      <dc:creator>AlanDodson</dc:creator>
      <dc:date>2019-03-20T17:03:23Z</dc:date>
    </item>
    <item>
      <title>Re: Getting names of layers with selected features</title>
      <link>https://community.esri.com/t5/python-questions/getting-names-of-layers-with-selected-features/m-p/743254#M57444</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To call Layer properties or methods, you will need to have references to Layer objects.&amp;nbsp; Since you don't show any code on how your layers list is created, I can't offer any suggestions on what to change.&amp;nbsp; Since you are creating a list of layer references/objects later in the script, and that is working, just use the same approach earlier in your script.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Mar 2019 18:05:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-names-of-layers-with-selected-features/m-p/743254#M57444</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2019-03-20T18:05:09Z</dc:date>
    </item>
    <item>
      <title>Re: Getting names of layers with selected features</title>
      <link>https://community.esri.com/t5/python-questions/getting-names-of-layers-with-selected-features/m-p/743255#M57445</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If&amp;nbsp; you are using &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-mapping/listlayers.htm"&gt;ListLayers&lt;/A&gt;, you might want to take another look at the documentation.&amp;nbsp; From your question in a related thread, it appeared that you might only be referencing the active data frame.&amp;nbsp; ListLayers requires a map document reference and an optional reference to the data frame.&amp;nbsp; Hope this helps.&lt;/P&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;ListLayers (map_document_or_layer, {wildcard}, {data_frame})&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Mar 2019 19:38:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-names-of-layers-with-selected-features/m-p/743255#M57445</guid>
      <dc:creator>RandyBurton</dc:creator>
      <dc:date>2019-03-20T19:38:42Z</dc:date>
    </item>
    <item>
      <title>Re: Getting names of layers with selected features</title>
      <link>https://community.esri.com/t5/python-questions/getting-names-of-layers-with-selected-features/m-p/743256#M57446</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, I will look at that.&amp;nbsp; I'm using a mix of hardcoded lists and ListLayers so I'm guessing that's where I'm running into trouble.&amp;nbsp; I just posted a long-winded reply in that other thread in case you'd like to know more about my warped little script&amp;nbsp;&lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Mar 2019 19:41:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-names-of-layers-with-selected-features/m-p/743256#M57446</guid>
      <dc:creator>AlanDodson</dc:creator>
      <dc:date>2019-03-20T19:41:44Z</dc:date>
    </item>
  </channel>
</rss>

