<?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: How to iteratively select by unique field values and create new feature in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-iteratively-select-by-unique-field-values/m-p/1019650#M36327</link>
    <description>&lt;P&gt;Thank you very much&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/215600"&gt;@DanPatterson&lt;/a&gt;&amp;nbsp;for pointing me in the right direction. I cannot believe I've never used that tool, very useful!&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Penelope&lt;/P&gt;</description>
    <pubDate>Mon, 25 Jan 2021 15:12:25 GMT</pubDate>
    <dc:creator>PenelopeMitchell2</dc:creator>
    <dc:date>2021-01-25T15:12:25Z</dc:date>
    <item>
      <title>How to iteratively select by unique field values and create new feature</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-iteratively-select-by-unique-field-values/m-p/1019284#M36249</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am trying to iteratively select by attribute&amp;gt;create feature layer&amp;gt; create new feature class(es) from the selections. But I am getting errors in the Make Feature Layer process.&amp;nbsp; Any suggestions?&lt;/P&gt;&lt;P&gt;Thanks, Penelope&amp;nbsp;&lt;/P&gt;&lt;P&gt;Update: Edited for code formatting--thanks for the tip.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#obtain unique values

values = [row[0] for row in arcpy.da.SearchCursor(SortiesLnFP, 'RS_Name')]
uniqueValues = set(values)

print(uniqueValues)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#create where clause for .makefeaturelayer using unique Values
#use where query to make a feature layer from selection then convert to feature class

OutPath = wkspc
for value in uniqueValues:
    OutFile = wkspc + os.sep + str(value)
    query = "\"RS_Name = '{}'\"".format(value)
    #query = "RS_Name = " + str(value)
    sortieLayer = arcpy.management.MakeFeatureLayer(SortiesLnFP, OutFile, query)
    arcpy.conversion.FeatureClassToFeatureClass(sortieLayer, wkspc, str(value))
    arcpy.managementDelete(sortieLayer)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markdown"&gt;#Output of query
"RS_Name = 'Pink_PM'"
"RS_Name = 'Pink2'"
#i've tried w/ the "" and without, get the same error either way-- I saw another post including those for the same purpose so thought I would try it (https://community.esri.com/t5/arcgis-api-for-python-questions/select-unique-values-from-field-using-selectbyattribute/td-p/825616/page/2)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class="ansi-red-fg"&gt;---------------------------------------------------------------------------&lt;/SPAN&gt;
&lt;SPAN class="ansi-red-fg"&gt;ExecuteError&lt;/SPAN&gt;                              Traceback (most recent call last)
In  &lt;SPAN class="ansi-blue-fg"&gt;[67]&lt;/SPAN&gt;:
Line &lt;SPAN class="ansi-blue-fg"&gt;6&lt;/SPAN&gt;:     sortieLayer = arcpy.management.MakeFeatureLayer(SortiesLnFP, OutFile, query)

File &lt;SPAN class="ansi-blue-fg"&gt;C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py&lt;/SPAN&gt;, in &lt;SPAN class="ansi-green-fg"&gt;MakeFeatureLayer&lt;/SPAN&gt;:
Line &lt;SPAN class="ansi-blue-fg"&gt;8668&lt;/SPAN&gt;:  &lt;SPAN class="ansi-blue-fg"&gt;raise&lt;/SPAN&gt; e

File &lt;SPAN class="ansi-blue-fg"&gt;C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py&lt;/SPAN&gt;, in &lt;SPAN class="ansi-green-fg"&gt;MakeFeatureLayer&lt;/SPAN&gt;:
Line &lt;SPAN class="ansi-blue-fg"&gt;8665&lt;/SPAN&gt;:  retval = convertArcObjectToPythonObject(gp.MakeFeatureLayer_management(*gp_fixargs((in_features, out_layer, where_clause, workspace, field_info), &lt;SPAN class="ansi-blue-fg"&gt;True&lt;/SPAN&gt;)))

File &lt;SPAN class="ansi-blue-fg"&gt;C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py&lt;/SPAN&gt;, in &lt;SPAN class="ansi-green-fg"&gt;&amp;lt;lambda&amp;gt;&lt;/SPAN&gt;:
Line &lt;SPAN class="ansi-blue-fg"&gt;511&lt;/SPAN&gt;:   &lt;SPAN class="ansi-blue-fg"&gt;return&lt;/SPAN&gt; &lt;SPAN class="ansi-blue-fg"&gt;lambda&lt;/SPAN&gt; *args: val(*gp_fixargs(args, &lt;SPAN class="ansi-blue-fg"&gt;True&lt;/SPAN&gt;))

&lt;SPAN class="ansi-red-fg"&gt;ExecuteError&lt;/SPAN&gt;: ERROR 000358: Invalid expression
Failed to execute (MakeFeatureLayer).&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2021 23:29:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/how-to-iteratively-select-by-unique-field-values/m-p/1019284#M36249</guid>
      <dc:creator>PenelopeMitchell2</dc:creator>
      <dc:date>2021-01-22T23:29:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to iteratively select by unique field values and create new feature</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-iteratively-select-by-unique-field-values/m-p/1019291#M36251</link>
      <description>&lt;P&gt;&lt;A href="https://community.esri.com/t5/python-blog/code-formatting-the-community-version/ba-p/1007633" target="_blank" rel="noopener"&gt;Code formatting ... the Community Version - GeoNet, The Esri Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;will help make your code more readable&amp;nbsp;&lt;/P&gt;&lt;P&gt;BTW&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;sortieLayer&lt;/STRONG&gt; = arcpy.management.MakeFeatureLayer(SortiesLnFP, OutFile, query)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.conversion.FeatureClassToFeatureClass(&lt;STRONG&gt;SortieLayer&lt;/STRONG&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;case difference !&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2021 21:37:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/how-to-iteratively-select-by-unique-field-values/m-p/1019291#M36251</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-01-22T21:37:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to iteratively select by unique field values and create new feature</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-iteratively-select-by-unique-field-values/m-p/1019307#M36252</link>
      <description>&lt;P&gt;Agreed, the code is very hard to read and unformatted.&lt;/P&gt;&lt;P&gt;No idea if the rest is any good, but it seems that your query is enclosed in another set of quotes, remove those and it should be valid (if value is a string, if its a number - remove the single quotes also).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;query = "RS_Name = '{}'".format(value)&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 22 Jan 2021 22:33:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/how-to-iteratively-select-by-unique-field-values/m-p/1019307#M36252</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-01-22T22:33:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to iteratively select by unique field values and create new feature</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-iteratively-select-by-unique-field-values/m-p/1019340#M36254</link>
      <description>&lt;P&gt;of course there is always&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/analysis/split-by-attributes.htm" target="_blank"&gt;Split By Attributes (Analysis)—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jan 2021 01:16:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/how-to-iteratively-select-by-unique-field-values/m-p/1019340#M36254</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-01-23T01:16:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to iteratively select by unique field values and create new feature</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-iteratively-select-by-unique-field-values/m-p/1019650#M36327</link>
      <description>&lt;P&gt;Thank you very much&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/215600"&gt;@DanPatterson&lt;/a&gt;&amp;nbsp;for pointing me in the right direction. I cannot believe I've never used that tool, very useful!&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Penelope&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jan 2021 15:12:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/how-to-iteratively-select-by-unique-field-values/m-p/1019650#M36327</guid>
      <dc:creator>PenelopeMitchell2</dc:creator>
      <dc:date>2021-01-25T15:12:25Z</dc:date>
    </item>
  </channel>
</rss>

