I am trying to create a feature layer from the current selection. The selection can be one feature or multiple features. I have an ERROR 000358: Invalid expression on line 9. I am assuming my where clause is wrong?
ptSelection = "points"
parcel = 'TaxParcels'
PF = "memory\PointFeat"
selected_features = arcpy.Describe(ptSelection).FIDSet
where_clause="OBJECTID = {}".format(selected_features)
arcpy.MakeFeatureLayer_management(ptSelection, PF, where_claus
Solved! Go to Solution.
The format SQL expects for a list is
<FIELD> IN (LIST,OF,VALUES)
According to the Docs, FIDSet returns a string in the format:
"LIST;OF;VALUES"
So to properly format that query, you'd need to do this:
selected_features = arcpy.Describe(selection).FIDSet
query_list = f"({','.join([val for val in selected_features.split(';')])})"
where_clause = f"OBJECTID IN {query_list}"
It also appears according to the docs that the TableView Describe object has a "whereClause" property that returns the exact query string used in the table view, so hypothetically you could just:
#...
where_clause = arcpy.Describe(selection).whereClause
arcpy.MakeFeatureLayer(ptSelection, PF, where_clause)
Try using IN instead of = and see if that fixes it.
Also, not to be that guy, but line 9 is cut off.
The format SQL expects for a list is
<FIELD> IN (LIST,OF,VALUES)
According to the Docs, FIDSet returns a string in the format:
"LIST;OF;VALUES"
So to properly format that query, you'd need to do this:
selected_features = arcpy.Describe(selection).FIDSet
query_list = f"({','.join([val for val in selected_features.split(';')])})"
where_clause = f"OBJECTID IN {query_list}"
It also appears according to the docs that the TableView Describe object has a "whereClause" property that returns the exact query string used in the table view, so hypothetically you could just:
#...
where_clause = arcpy.Describe(selection).whereClause
arcpy.MakeFeatureLayer(ptSelection, PF, where_clause)
Thank you, that worked