<?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: Make new shapfile based on attributes of an existing shapefile in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/make-new-shapfile-based-on-attributes-of-an/m-p/197638#M15156</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks again Wayne. Adding to what you suggested in the last post, I tried to modify it and here how the code looks like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

import arcpy
fc = arcpy.GetParameterAsText(0)
yrs = arcpy.GetParameterAsText(1)
yrs = yrs.split(';')
subtract = ''
for yr in yrs:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where = '"arcpy.GetParameterAsText(3)" arcpy.GetParameterAsText(2) ' + str(yr) + subtract
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; subtract = ' AND "arcpy.GetParameterAsText(3)" &amp;gt; ' + str(yr)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; filename = str(arcpy.GetParameterAsText(3)) + '.shp'
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.FeatureClassToFeatureClass_conversion(fc, "arcpy.GetParameterAsText(4)", filename, where)

del yr&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I get the following error message:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;class 'arcgisscripting.ExecuteError'&amp;gt;: ERROR 999999: Error executing function.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;An invalid SQL statement was used.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;An invalid SQL statement was used.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (FeatureClassToFeatureClass).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also attaching the screenshot for properties while adding the script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]19844[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]19845[/ATTACH]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 09:52:18 GMT</pubDate>
    <dc:creator>SenthilnathanThyagarajan</dc:creator>
    <dc:date>2021-12-11T09:52:18Z</dc:date>
    <item>
      <title>Make new shapfile based on attributes of an existing shapefile</title>
      <link>https://community.esri.com/t5/python-questions/make-new-shapfile-based-on-attributes-of-an/m-p/197636#M15154</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi All,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In my last&amp;nbsp; &lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/73093-Creating-new-shapefile-based-on-its-attributes-with-python"&gt;post&lt;/A&gt;&lt;SPAN&gt; I had an issue where I wanted to create multiple shapefiles based on only one attribute field(years). How to do it was answered in that post. I want to make that tool more dynamic so that the user can select any field and any value and make a shapefile for it. Any suggestions on how to use the tool dynamic so that fields and the operator(&amp;lt;,&amp;lt;=,=&amp;gt;,&amp;gt;=) can also be defined by the user itself.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Dec 2012 03:24:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/make-new-shapfile-based-on-attributes-of-an/m-p/197636#M15154</guid>
      <dc:creator>SenthilnathanThyagarajan</dc:creator>
      <dc:date>2012-12-10T03:24:17Z</dc:date>
    </item>
    <item>
      <title>Re: Make new shapfile based on attributes of an existing shapefile</title>
      <link>https://community.esri.com/t5/python-questions/make-new-shapfile-based-on-attributes-of-an/m-p/197637#M15155</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;No one else has answered, so I'll chime in --- first of all, with the general conditions in which you want to script this, it seems your problem is more suited for a model, because you can quickly construct it out of ready-made system tools.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A simple model with Make Feature Layer and Copy Features with 3 input parameters (input fc/layer, expression, and output fc) will allow you to have the flexibility to open the Query Builder to compose and validate whatever query on the input layer you want.&amp;nbsp; Additionally, if you right-click on the model and select 'Batch...', then you can run the whole process multiple times, essentially looping on each user-defined SQL query.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;See the attached pics... should load in this order:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1- The model 'guts' containing 2 tools, MFL and Copy Features...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2- The single execution example, singleExecSetup (the default opening of the model, as you would run it once).&amp;nbsp; The Query Builder window is also shown, opens from your tool interface SQL button as shown to the right of the Expression text box.&amp;nbsp; Output fc result is already shown in map (black labels are Subdivision labels, same field queried by).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3- The multiple or 'batch' execution example, multiExecSetup (the batch opening of the model, looping on multiple input params).&amp;nbsp; The labels:&amp;nbsp; shown in black, Subdivision; shown in blue, Parcel IDs&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4- The batch result --- shows how flexible the Query Builder is - notice the result of the 3rd query (from the 3rd line entered in 'batch mode'), which creates output for an ID range.&amp;nbsp; All of these queries can be validated before the actual execution is launched, an extremely important quality I'd say.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope that helps.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-Wayne&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Dec 2012 16:38:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/make-new-shapfile-based-on-attributes-of-an/m-p/197637#M15155</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2012-12-10T16:38:23Z</dc:date>
    </item>
    <item>
      <title>Re: Make new shapfile based on attributes of an existing shapefile</title>
      <link>https://community.esri.com/t5/python-questions/make-new-shapfile-based-on-attributes-of-an/m-p/197638#M15156</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks again Wayne. Adding to what you suggested in the last post, I tried to modify it and here how the code looks like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

import arcpy
fc = arcpy.GetParameterAsText(0)
yrs = arcpy.GetParameterAsText(1)
yrs = yrs.split(';')
subtract = ''
for yr in yrs:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where = '"arcpy.GetParameterAsText(3)" arcpy.GetParameterAsText(2) ' + str(yr) + subtract
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; subtract = ' AND "arcpy.GetParameterAsText(3)" &amp;gt; ' + str(yr)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; filename = str(arcpy.GetParameterAsText(3)) + '.shp'
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.FeatureClassToFeatureClass_conversion(fc, "arcpy.GetParameterAsText(4)", filename, where)

del yr&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I get the following error message:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;class 'arcgisscripting.ExecuteError'&amp;gt;: ERROR 999999: Error executing function.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;An invalid SQL statement was used.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;An invalid SQL statement was used.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (FeatureClassToFeatureClass).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also attaching the screenshot for properties while adding the script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]19844[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]19845[/ATTACH]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:52:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/make-new-shapfile-based-on-attributes-of-an/m-p/197638#M15156</guid>
      <dc:creator>SenthilnathanThyagarajan</dc:creator>
      <dc:date>2021-12-11T09:52:18Z</dc:date>
    </item>
    <item>
      <title>Re: Make new shapfile based on attributes of an existing shapefile</title>
      <link>https://community.esri.com/t5/python-questions/make-new-shapfile-based-on-attributes-of-an/m-p/197639#M15157</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Sorry, that's a 'no go'...1st of all, that is not how the script looping mechanism works, due to the fact the very 1st parameter (a multi-value param) in the existing script was used to set up variables for your sql queries.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;On a more elementary level, you cannot quote the GetParameterAsText function because then python simply thinks it is a string.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Lastly, it is a very bad idea to set up fetching parameters within a loop....normally, you fetch all user specified params in the beginning and set up your variables accordingly, then proceed to pass them in any looping mechanism you need.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It may be at this point just a little beyond your Python expertise to understand some of the subtleties of the code, and this is in part why I suggested the approach in the last post.&amp;nbsp; Also, you would be very hard-pressed to imitate the Query Builder behavior (including the pre-run validation).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you must introduce some scripting as part of your class project, may I suggest you incorporate the model provided with the means perhaps to launch it by script - maybe call the model in a script scheduled task?&amp;nbsp; It is a very useful technique and the scripting is relatively simple.&amp;nbsp; What's more, the model component, Make Feature Layer, can be opened using ModelBuilder and setup with user input beforehand and saved - then the script can take over the launch later and perform the potentially intensive processing at a more convenient time (afterhours).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope that's the guidance you need.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Dec 2012 14:50:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/make-new-shapfile-based-on-attributes-of-an/m-p/197639#M15157</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2012-12-11T14:50:25Z</dc:date>
    </item>
  </channel>
</rss>

