AnsweredAssumed Answered

Using a Value from a list in a Query Clause

Question asked by MikeEdwards on Oct 17, 2017
Latest reply on Oct 17, 2017 by xander_bakker


I'm trying to export the errors from a Topology Validation. Multiple features are being validated at once and right now the output is three feature classes (poly, line, point) containing the errors from every feature class that has been validated.

I'm trying to change the export to be one for each feature class geometry type combination (stripping out the errors from each individual feature class and exporting them as their own.

What I have right now keeps ending with an Invalid Expression error (ExecuteError: ERROR 000358: Invalid expression
Failed to execute (SelectLayerByAttribute).).

Can anyone give me a hand figuring out what I'm doing wrong?


import arcpy
from arcpy import env

arcpy.env.overwriteOutput = True

env.workspace = "C:\Temp\Test_Data.gdb"

table = r"C:\Temp\Test_Data.gdb\TOPOLOGY\ArcGIS_Errors_line"
field = "OriginObjectClassName"

with arcpy.da.SearchCursor(table, field) as cursor:
   myValues_List = sorted({row[0] for row in cursor})
   for FeatureClassValue in myValues_List:
      queryClause = '"' + 'OriginObjectClassName = ' + "'" + FeatureClassValue.strip('\n') + "'" + '"'
      arcpy.SelectLayerByAttribute_management("FEATURE_SELECTION", "NEW_SELECTION", queryClause)
      arcpy.CopyFeatures_management("FEATURE_SELECTION", env.workspace + FeatureClassValue + "_Errors")