Hello,
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.MakeFeatureLayer_management("TC:\Temp\Test_Data.gdb\TOPOLOGY\ArcGIS_Errors_line","FEATURE_SELECTION")
arcpy.SelectLayerByAttribute_management("FEATURE_SELECTION", "NEW_SELECTION", queryClause)
arcpy.CopyFeatures_management("FEATURE_SELECTION", env.workspace + FeatureClassValue + "_Errors")
Solved! Go to Solution.
Your query contains additional double quotes that shouldn't be there. Try this instead:
queryClause = "OriginObjectClassName = '{0}'".format(FeatureClassValue)
The other thing that I am wondering... is there really an enter after the featureclass name?
Have you tried printing the query to verify the syntax? If so, what does it look like?
Printing the query gives me:
"OriginObjectClassName = 'BUILDINGS'"
"OriginObjectClassName = 'PARKS'"
"OriginObjectClassName = 'ROADS'"
If I substitute any of those with queryClause it works fine for that one feature.
Try putting an 'r' in front of all paths. Check below
#what you have
arcpy.MakeFeatureLayer_management("TC:\Temp\Test_Data.gdb\TOPOLOGY\ArcGIS_Errors_line","FEATURE_SELECTION")
#what I think it should be
arcpy.MakeFeatureLayer_management(r"C:\Temp\Test_Data.gdb\TOPOLOGY\ArcGIS_Errors_line","FEATURE_SELECTION")
Your query contains additional double quotes that shouldn't be there. Try this instead:
queryClause = "OriginObjectClassName = '{0}'".format(FeatureClassValue)
The other thing that I am wondering... is there really an enter after the featureclass name?
Thanks guys, I'll give that a shot.
The TC:\ was a typo, I was just shortening the path names for posting on here.
It may have been a typo, but the comment made by mitchh300 still is valid. Your \T will convert into a TAB and create an invalid path. Please read this blog by Dan_Patterson : /blogs/dan_patterson/2016/08/14/filenames-and-file-paths-in-python
That worked!
Thank you very much to both of you.
Great that worked. If it was the suggestion made by mitchh300 that helped you resolve the problem, could you mark his comment as the correct answer?