<?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: Python code for exporting multiple layers? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-code-for-exporting-multiple-layers/m-p/176948#M13615</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And someone please tell me how to insert python code into a post on these forums... &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 15 Dec 2016 14:45:51 GMT</pubDate>
    <dc:creator>TheoFaull</dc:creator>
    <dc:date>2016-12-15T14:45:51Z</dc:date>
    <item>
      <title>Python code for exporting multiple layers?</title>
      <link>https://community.esri.com/t5/python-questions/python-code-for-exporting-multiple-layers/m-p/176941#M13608</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;I have 10 layers in my MXD. Each layer's attribute table has a text field called 'Contractor'. This field has a few different values in it, but I'm only concerned with ones that contain the word 'TLG' or 'TLG[extra bits of text]'&lt;/P&gt;&lt;P&gt;I want to export each layer to create 10 new shapefiles in a seperate folder. But only exporting the records where 'Contractor' = 'TLG' or 'TLG%'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;At the moment I go into each layer, select all the records that include TLG and right click layer&amp;gt;export data (selected records only).&lt;/P&gt;&lt;P&gt;This is a manual slow process which I repeat every week or so when updating our clients with shapefile data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ArcMap 10.4.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!!! &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(I would like to use the geoprocessing&amp;gt;python console window if possible. I've used that before, so it's familiar to me!)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Dec 2016 16:51:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-code-for-exporting-multiple-layers/m-p/176941#M13608</guid>
      <dc:creator>TheoFaull</dc:creator>
      <dc:date>2016-12-09T16:51:33Z</dc:date>
    </item>
    <item>
      <title>Re: Python code for exporting multiple layers?</title>
      <link>https://community.esri.com/t5/python-questions/python-code-for-exporting-multiple-layers/m-p/176942#M13609</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Look at the Python examples in:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-mapping/listlayers.htm" title="http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-mapping/listlayers.htm"&gt;ListLayers—Help | ArcGIS Desktop&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="http://desktop.arcgis.com/en/arcmap/latest/tools/analysis-toolbox/select.htm" title="http://desktop.arcgis.com/en/arcmap/latest/tools/analysis-toolbox/select.htm"&gt;Select—Help | ArcGIS Desktop&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Dec 2016 17:04:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-code-for-exporting-multiple-layers/m-p/176942#M13609</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2016-12-09T17:04:41Z</dc:date>
    </item>
    <item>
      <title>Re: Python code for exporting multiple layers?</title>
      <link>https://community.esri.com/t5/python-questions/python-code-for-exporting-multiple-layers/m-p/176943#M13610</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Once you have created your python script from the above samples, you can then use Task Scheduler to have the script automatically run each&amp;nbsp;week. &amp;nbsp;This can be done either on your desktop or a more robust server machine if you have access to one.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Dec 2016 17:54:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-code-for-exporting-multiple-layers/m-p/176943#M13610</guid>
      <dc:creator>MichaelVolz</dc:creator>
      <dc:date>2016-12-09T17:54:29Z</dc:date>
    </item>
    <item>
      <title>Re: Python code for exporting multiple layers?</title>
      <link>https://community.esri.com/t5/python-questions/python-code-for-exporting-multiple-layers/m-p/176944#M13611</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OK so far I've managed to export all records from my LITTER_BIN shapefile that contain "TLG" in the 'contractor' field, into a new shapefile (called LITTER_BINS_new)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EDIT: damn this is annoying, how can I paste python code in the correct viewing format into this post? No option in advanced editor!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; import arcpy&lt;BR /&gt;... from arcpy import env&lt;BR /&gt;... &lt;BR /&gt;... env.workspace = "K:/Data/Estates_Services/GROUNDS MAINTENANCE/GROUP GROUNDS MAINTENANCE"&lt;BR /&gt;... arcpy.Select_analysis("LITTER_BINS.shp", "U:\Tasks\TLG_data_updates\TLG_update_14122016/LITTER_BINS_new.shp", '"Contractor" = \'TLG\'')&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Questions now:&lt;/P&gt;&lt;P&gt;1. How can I make the code select+export records from multiple shapefiles/into new multiple shapefiles? Not just one at a time?&lt;/P&gt;&lt;P&gt;2. How can I make the code select records where 'Contractor' = TLG or TLG%. The wildcard appears to be * in python (right?) but if I write '"Contractor" = \'TLG*\'', it exports a blank shapefile with no records.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Dec 2016 14:58:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-code-for-exporting-multiple-layers/m-p/176944#M13611</guid>
      <dc:creator>TheoFaull</dc:creator>
      <dc:date>2016-12-14T14:58:26Z</dc:date>
    </item>
    <item>
      <title>Re: Python code for exporting multiple layers?</title>
      <link>https://community.esri.com/t5/python-questions/python-code-for-exporting-multiple-layers/m-p/176945#M13612</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is the 'Contractor' field a string type? &amp;nbsp;You may want to use FieldDelimiters to be safe:&amp;nbsp;&lt;A class="link-titled" href="http://pro.arcgis.com/en/pro-app/arcpy/functions/addfielddelimiters.htm" title="http://pro.arcgis.com/en/pro-app/arcpy/functions/addfielddelimiters.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;AddFieldDelimiters—ArcPy Functions | ArcGIS for Desktop&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Something like this may work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;field = 'Contractor'
datasource = r'path to datasource'
qry = arcpy.AddFieldDelimiters(datasource, field) + " LIKE '%TLG%'‍‍‍‍‍‍"‍‍‍‍‍‍&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>Sat, 11 Dec 2021 09:06:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-code-for-exporting-multiple-layers/m-p/176945#M13612</guid>
      <dc:creator>MitchHolley1</dc:creator>
      <dc:date>2021-12-11T09:06:29Z</dc:date>
    </item>
    <item>
      <title>Re: Python code for exporting multiple layers?</title>
      <link>https://community.esri.com/t5/python-questions/python-code-for-exporting-multiple-layers/m-p/176946#M13613</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can do this entirely in model builder...without coding, but if you want to do it with coding the same concepts apply.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basic Steps:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Iterate feature classes in workspace&lt;OL&gt;&lt;LI&gt;Make Feature Class (with definition query)&lt;/LI&gt;&lt;LI&gt;Export to shapefile&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Details:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Model builder has a special tool caled Iterate Feature Classes in workspace. You access it by using Insert &amp;gt; Iterators &amp;gt; Iterate Feature Classes. It accepts a workspace as input. Then you just chain the feature class to Make Feature Layer (with definition query) and then to Feature class to feature class.&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/283302_pastedImage_1.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can set definition query in the Make feature layer tool:&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-3 jive-image" src="https://community.esri.com/legacyfs/online/283307_pastedImage_3.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can use %Name% in your parameter to access the name of the input layer:&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-2 jive-image" src="https://community.esri.com/legacyfs/online/283303_pastedImage_2.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In python you can do this with:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy
arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;env&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;workspace &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'C:/workspace'&lt;/SPAN&gt;
output_folder &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'C:/Output'&lt;/SPAN&gt;
fc_list &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ListFeatureClasses&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; fc &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; fc_list&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;MakeFeatureClass_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;fc&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; fc &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"_filtered"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; where_clause&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Contractor LIKE 'TLG%'"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;FeatureClassToShapefile&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;fc&lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"_filtered"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; output_folder&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&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;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&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>Sat, 11 Dec 2021 09:06:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-code-for-exporting-multiple-layers/m-p/176946#M13613</guid>
      <dc:creator>roemhildtg</dc:creator>
      <dc:date>2021-12-11T09:06:31Z</dc:date>
    </item>
    <item>
      <title>Re: Python code for exporting multiple layers?</title>
      <link>https://community.esri.com/t5/python-questions/python-code-for-exporting-multiple-layers/m-p/176947#M13614</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ok, I found a way to export multiple shapefiles to multiple, new shapefiles. Using "TLG" as a means of selection.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; import arcpy&lt;BR /&gt;... from arcpy import env&lt;BR /&gt;... &lt;BR /&gt;... env.workspace = "K:\Data\Estates_Services\GROUNDS MAINTENANCE\GROUP GROUNDS MAINTENANCE"&lt;BR /&gt;... arcpy.Select_analysis("LITTER_BINS.shp", "U:\Tasks\TLG_data_updates\TLG_update_14122016/LITTER_BINS.shp", '"Contractor" = \'TLG\'')&lt;BR /&gt;... arcpy.Select_analysis("AMENITY_GRASS.shp", "U:\Tasks\TLG_data_updates\TLG_update_14122016/AMENITY_GRASS.shp", '"Contractor" = \'TLG\'')&lt;BR /&gt;... arcpy.Select_analysis("AMENITY_GRASS_SHELTERED.shp", "U:\Tasks\TLG_data_updates\TLG_update_14122016/AMENITY_GRASS_SHELTERED.shp", '"Contractor" = \'TLG\'')&lt;BR /&gt;... arcpy.Select_analysis("HEDGES_1SIDE_ONLY.shp", "U:\Tasks\TLG_data_updates\TLG_update_14122016/HEDGES_1SIDE_ONLY.shp", '"Contractor" = \'TLG\'')&lt;BR /&gt;... arcpy.Select_analysis("HEDGES_1SIDE_TOP.shp", "U:\Tasks\TLG_data_updates\TLG_update_14122016/HEDGES_1SIDE_TOP.shp", '"Contractor" = \'TLG\'')&lt;BR /&gt;... arcpy.Select_analysis("HEDGES_2SIDES_TOP.shp", "U:\Tasks\TLG_data_updates\TLG_update_14122016/HEDGES_2SIDES_TOP.shp", '"Contractor" = \'TLG\'')&lt;BR /&gt;... arcpy.Select_analysis("LEAF_CLEARANCE.shp", "U:\Tasks\TLG_data_updates\TLG_update_14122016/LEAF_CLEARANCE.shp", '"Contractor" = \'TLG\'')&lt;BR /&gt;... arcpy.Select_analysis("MEADOW_GRASS.shp", "U:\Tasks\TLG_data_updates\TLG_update_14122016/MEADOW_GRASS.shp", '"Contractor" = \'TLG\'')&lt;BR /&gt;... arcpy.Select_analysis("ROUGH_GROUND.shp", "U:\Tasks\TLG_data_updates\TLG_update_14122016/ROUGH_GROUND.shp", '"Contractor" = \'TLG\'')&lt;BR /&gt;... arcpy.Select_analysis("SHELTERED_GRITTING_AREAS.shp", "U:\Tasks\TLG_data_updates\TLG_update_14122016/SHELTERED_GRITTING_AREAS.shp", '"Contractor" = \'TLG\'')&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I just copy pasted the line 10 times!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I still want to know how to make "TLG", "TLG%"... Everytime I use the %, it exports a new shapefile with no records in it!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Dec 2016 14:45:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-code-for-exporting-multiple-layers/m-p/176947#M13614</guid>
      <dc:creator>TheoFaull</dc:creator>
      <dc:date>2016-12-15T14:45:23Z</dc:date>
    </item>
    <item>
      <title>Re: Python code for exporting multiple layers?</title>
      <link>https://community.esri.com/t5/python-questions/python-code-for-exporting-multiple-layers/m-p/176948#M13615</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And someone please tell me how to insert python code into a post on these forums... &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Dec 2016 14:45:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-code-for-exporting-multiple-layers/m-p/176948#M13615</guid>
      <dc:creator>TheoFaull</dc:creator>
      <dc:date>2016-12-15T14:45:51Z</dc:date>
    </item>
    <item>
      <title>Re: Python code for exporting multiple layers?</title>
      <link>https://community.esri.com/t5/python-questions/python-code-for-exporting-multiple-layers/m-p/176949#M13616</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Check out &lt;A _jive_internal="true" href="https://community.esri.com/blogs/dan_patterson/2016/08/14/script-formatting"&gt;Code Formatting... the basics++&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Dec 2016 15:08:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-code-for-exporting-multiple-layers/m-p/176949#M13616</guid>
      <dc:creator>BrittneyWhite1</dc:creator>
      <dc:date>2016-12-15T15:08:05Z</dc:date>
    </item>
  </channel>
</rss>

