<?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: Using CopyFeatures for python script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/using-copyfeatures-for-python-script/m-p/225227#M17410</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you for your remarks. I think, using a list could indeed solve the problem. The CopyFeature function obviously doesn't work with the searchCursor object. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;But finally I just used the Select function and created a loop for the SQL expression. This script works fine now and copies each row of my feature class to a new seperate file:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Set local variables
in_features = "cities_mexico"

searchCursor = arcpy.SearchCursor(in_features)
row = searchCursor.next()

for i in range(36):
&amp;nbsp;&amp;nbsp;&amp;nbsp; cityName = row.CITY_NAME

&amp;nbsp;&amp;nbsp;&amp;nbsp; # create output path name
&amp;nbsp;&amp;nbsp;&amp;nbsp; out_feature_class = os.path.join(env.workspace, cityName)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; where_clause = '"OBJECTID"='+str(i+1)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Execute Select
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Select_analysis(in_features, out_feature_class, where_clause)
&amp;nbsp;&amp;nbsp;&amp;nbsp; row = searchCursor.next() &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 10:58:48 GMT</pubDate>
    <dc:creator>SimoneEhrenberger</dc:creator>
    <dc:date>2021-12-11T10:58:48Z</dc:date>
    <item>
      <title>Using CopyFeatures for python script</title>
      <link>https://community.esri.com/t5/python-questions/using-copyfeatures-for-python-script/m-p/225225#M17408</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi, I tried to write a small scritp which copies each row of a feature class to a new file. I wanted to use the CopyFeatures function to create the new files, but when I run the modul I get this error message back:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;AttributeError: 'NoneType' object has no attribute 'CopyFeatures_management'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am not sure what the problem exactly is and how to solve it. Any suggestions?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is the code I wrote:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
# Import arcpy module
import arcpy
from arcpy import env
import os

env.workspace = r"C:\ArcGIS\Mexico.gdb"

# Load required toolboxes
arcpy.ImportToolbox("C:\Programme\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Data Management Tools.tbx")

# Local variables:
cities_mexico = "cities_mexico"

searchCursor = arcpy.SearchCursor(cities_mexico)
row = searchCursor.next()

while row &amp;lt;&amp;gt; None:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Copy Features&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; outFeature = os.path.join(env.workspace, row.CITY_NAME)
&amp;nbsp;&amp;nbsp;&amp;nbsp; print outFeature
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures_management(row, outFeature)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Mar 2011 13:42:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-copyfeatures-for-python-script/m-p/225225#M17408</guid>
      <dc:creator>SimoneEhrenberger</dc:creator>
      <dc:date>2011-03-22T13:42:44Z</dc:date>
    </item>
    <item>
      <title>Re: Using CopyFeatures for python script</title>
      <link>https://community.esri.com/t5/python-questions/using-copyfeatures-for-python-script/m-p/225226#M17409</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You would have to trap for a null record when there is a null value for cityname.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;while row : 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Copy Features 
&amp;nbsp;&amp;nbsp;&amp;nbsp; try:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outFeature = os.path.join(env.workspace, row.CITY_NAME)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print outFeature
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures_management(row, outFeature)
&amp;nbsp;&amp;nbsp;&amp;nbsp; except arcpy.ExecuteError:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "failed to write"
&amp;nbsp;&amp;nbsp;&amp;nbsp; row = searchCursor.next()
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;[You do not have to add toolboxes for system tools. This comes from generating a script from Modelbuilder where this redundant and non-portable line is added.]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Geoprocessing tools are designed to work on a whole featureclass or layer, not inside a cursor.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Your script will only write one feature to a new featureclass, overwriting any previous featureclass. Is this what you intend?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you want more than one feature written out you would have to rewrite the process to select all the rows that meet an expression as a layer and then copy the layer to a new featureclass. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You would need a list of citynames from either running a cursor to collect them or maybe Frequency and then open a cursor to get the list. There is no need to set the output path if you have set the workspace.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.env.overwriteOutput = True
arcpy.Frequency_management(cities_mexico,"in_memory/citList","CITY_NAME")

for row in arcpy.SearchCursor("in_memory/citList"):
&amp;nbsp; arcpy.MakeFeatureLayer(cities_mexico,"temp_lay","CITY_NAME = '"+row.CITY_NAME+"'")
&amp;nbsp; arcpy.CopyFeatures("temp_lay",city)&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;(I have not run this in a Python window so there may be syntax and case errors in this)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:58:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-copyfeatures-for-python-script/m-p/225226#M17409</guid>
      <dc:creator>KimOllivier</dc:creator>
      <dc:date>2021-12-11T10:58:46Z</dc:date>
    </item>
    <item>
      <title>Re: Using CopyFeatures for python script</title>
      <link>https://community.esri.com/t5/python-questions/using-copyfeatures-for-python-script/m-p/225227#M17410</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you for your remarks. I think, using a list could indeed solve the problem. The CopyFeature function obviously doesn't work with the searchCursor object. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;But finally I just used the Select function and created a loop for the SQL expression. This script works fine now and copies each row of my feature class to a new seperate file:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Set local variables
in_features = "cities_mexico"

searchCursor = arcpy.SearchCursor(in_features)
row = searchCursor.next()

for i in range(36):
&amp;nbsp;&amp;nbsp;&amp;nbsp; cityName = row.CITY_NAME

&amp;nbsp;&amp;nbsp;&amp;nbsp; # create output path name
&amp;nbsp;&amp;nbsp;&amp;nbsp; out_feature_class = os.path.join(env.workspace, cityName)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; where_clause = '"OBJECTID"='+str(i+1)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Execute Select
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Select_analysis(in_features, out_feature_class, where_clause)
&amp;nbsp;&amp;nbsp;&amp;nbsp; row = searchCursor.next() &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:58:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-copyfeatures-for-python-script/m-p/225227#M17410</guid>
      <dc:creator>SimoneEhrenberger</dc:creator>
      <dc:date>2021-12-11T10:58:48Z</dc:date>
    </item>
    <item>
      <title>Re: Using CopyFeatures for python script</title>
      <link>https://community.esri.com/t5/python-questions/using-copyfeatures-for-python-script/m-p/225228#M17411</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you for your remarks. I think, using a list could solve the problem. The CopyFeature function obviously doesn't work with searchCursor objects.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But finally I simply used the Select function and created a loop for the SQL expression. This script works fine now and copies each row of my input feature class to a separate file:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Set local variables
in_features = "cities_mexico"

searchCursor = arcpy.SearchCursor(in_features)
row = searchCursor.next()

for i in range(36):
&amp;nbsp;&amp;nbsp;&amp;nbsp; cityName = row.CITY_NAME

&amp;nbsp;&amp;nbsp;&amp;nbsp; # create output path name
&amp;nbsp;&amp;nbsp;&amp;nbsp; out_feature_class = os.path.join(env.workspace, cityName)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; where_clause = '"OBJECTID"='+str(i+1)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Execute Select
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Select_analysis(in_features, out_feature_class, where_clause)
&amp;nbsp;&amp;nbsp;&amp;nbsp; row = searchCursor.next()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:58:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-copyfeatures-for-python-script/m-p/225228#M17411</guid>
      <dc:creator>SimoneEhrenberger</dc:creator>
      <dc:date>2021-12-11T10:58:51Z</dc:date>
    </item>
  </channel>
</rss>

