<?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 hold of features selected in the map... in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/getting-hold-of-features-selected-in-the-map/m-p/575562#M45097</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That's great.&amp;nbsp; I'll have a look and see how I go.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 02 Jul 2012 12:37:14 GMT</pubDate>
    <dc:creator>AndrewJones</dc:creator>
    <dc:date>2012-07-02T12:37:14Z</dc:date>
    <item>
      <title>Getting hold of features selected in the map...</title>
      <link>https://community.esri.com/t5/python-questions/getting-hold-of-features-selected-in-the-map/m-p/575560#M45095</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello all...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am coming from an ArcObjects background and seeing what I can do in Python to make my life easier!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have been tasked with writing a tool that extracts all features in the map to a new set of shapefiles in a folder somewhere.&amp;nbsp; I thought I'd have a go in python so the users can run this from model builder but I have stumbled at the first hurdle.&amp;nbsp; There seems to be no way to get at features already selected in the map.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Can someone direct me at the best way of getting at already selected features?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Many Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Andy&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Jul 2012 08:21:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-hold-of-features-selected-in-the-map/m-p/575560#M45095</guid>
      <dc:creator>AndrewJones</dc:creator>
      <dc:date>2012-07-02T08:21:47Z</dc:date>
    </item>
    <item>
      <title>Re: Getting hold of features selected in the map...</title>
      <link>https://community.esri.com/t5/python-questions/getting-hold-of-features-selected-in-the-map/m-p/575561#M45096</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try this, which will loop through all the layers in a map, find ones that have selected features, and copy those features to a shapefile.&amp;nbsp; You will have to name them better than my example, but this should get you started.&amp;nbsp; Key thing to remember is that most Toolbox tools honor selection.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import os, sys import arcpy&amp;nbsp; def main(): &amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument("CURRENT") &amp;nbsp;&amp;nbsp;&amp;nbsp; df = mxd.activeDataFrame &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; counter = 1 &amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in arcpy.mapping.ListLayers(mxd, "", df): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ext1 = lyr.getExtent() &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ext2 = lyr.getSelectedExtent() &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if not ext1 or ext1.equals(ext2):&amp;nbsp; #no selection &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; continue &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outfc = ''.join(('c:/temp/shapefile', str(counter), '.shp')) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures_management(lyr, outfc) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; counter += 1&amp;nbsp; if __name__ == '__main__': &amp;nbsp;&amp;nbsp;&amp;nbsp; main()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;good luck,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Jul 2012 10:25:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-hold-of-features-selected-in-the-map/m-p/575561#M45096</guid>
      <dc:creator>MikeHunter</dc:creator>
      <dc:date>2012-07-02T10:25:19Z</dc:date>
    </item>
    <item>
      <title>Re: Getting hold of features selected in the map...</title>
      <link>https://community.esri.com/t5/python-questions/getting-hold-of-features-selected-in-the-map/m-p/575562#M45097</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That's great.&amp;nbsp; I'll have a look and see how I go.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Jul 2012 12:37:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-hold-of-features-selected-in-the-map/m-p/575562#M45097</guid>
      <dc:creator>AndrewJones</dc:creator>
      <dc:date>2012-07-02T12:37:14Z</dc:date>
    </item>
  </channel>
</rss>

