AnsweredAssumed Answered

Copy Features - Recieveing Catch All Error Message

Question asked by rralbritton1981 on Oct 16, 2012
Latest reply on Oct 16, 2012 by rralbritton1981
I am writing a python code to select features from a feature layer then copying the selected feature(s) to a new feature class. The code succeeds at selecting the features but when it goes to copy these features I get a catch-all error message:

ERROR 000210: Cannot create output CountyBoundary_Selection.shp
Failed to execute (CopyFeatures).
Failed at Tue Oct 16 14:34:23 2012 (Elapsed Time: 0.00 seconds)

I have read this ESRI article, and have made sure that there is not a lock on any files and have tried to save the new feature class to a new location. Any other suggestions?

Also if I use the feature class to feature class tool instead of the Copy Features tool the script works. So I'll go with this for now but it would be nice to know for the future.

import arcpy, os  workspace = "C:/Temp"  print "Workspace set to:", workspace arcpy.AddMessage("Workspace set to: "+workspace)                   arcpy.env.overwriteOutput=True  def whereClause(table, field, values):     """Takes a semicolon-delimited list of values and constructs a SQL WHERE     clause to select those values within a given field and table."""      # Add field delimiters     fieldDelimited = arcpy.AddFieldDelimiters(arcpy.Describe(table).path, field)      # Split multivalue at semicolons and strip quotes     valueList = [value[1:-1]                  if (value.startswith("'") and value.endswith("'"))                  else value for value in values.split(';')]      # Determine field type     fieldType = arcpy.ListFields(table, field)[0].type      # Add single-quotes for string field values     if str(fieldType) == 'String':         valueList = ["'%s'" % value for value in valueList]      # Format WHERE clause in the form of an IN statement     whereClause = "%s IN (%s)"%(fieldDelimited, ', '.join(valueList))     return whereClause  def outName(input,post="Out",fileExtension="shp"):     """Returns output name."""     outName=os.path.basename(input).split(".")[0]+post+"."+fileExtension     return outName   #Make Feature Layer from County Boundary Feature Class InputFC = "C:\Project\ToolData\CountyBoundary.shp" OutputFL = outName(InputFC,"_Layer","lyr")  try:     arcpy.MakeFeatureLayer_management(InputFC, OutputFL) except:     arcpy.GetMessages()      #Select Attributes from County Boundary Layer Field = "CO_NAME" Counties = arcpy.GetParameterAsText(0) SQL = whereClause(OutputFL, Field, Counties)  try:     arcpy.SelectLayerByAttribute_management(OutputFL,"NEW_SELECTION", SQL)     count = int(arcpy.GetCount_management(OutputFL).getOutput(0))     print '\n',"There are", count, "counties selected from County Boundary layer.",'\n'      except:     print arcpy.GetMessages()  #Copy Selected Feature Layer to new Feature Class OutputFC = outName(InputFC,"_Selection","shp")  try:     arcpy.CopyFeatures_management(OutputFL, OutputFC)      except:     print arcpy.GetMessages()