0

I need to select a layer with all attributes while the selection comes from a table. With my code I get only empty feature classes and emtey Excel files. The tab_list Elements are the selection value. If Name2 = Name1 the selection should starting.

 field = ["SHAPE_Length", "SHAPE_Area"]

arcpy.MakeFeatureLayer_management(workspace + "\\" + gdb + "\\" + "Verknuepfung", "selectlayer")

bet_tab_v_list = [row[0] for row in arcpy.da.SearchCursor(convert_table, ["Name1"])]
s_cur = arcpy.da.SearchCursor("selectlayer", ["Name2"])

tab_list = set(bet_tab_v_list)

counter = 1 
for elm in tab_list:
    arcpy.SelectLayerByAttribute_management("selectlayer", "NEW_SELECTION", "Name2 =' {}  '")
    arcpy.CopyFeatures_management("selectlayer", speicherpfad + "\\" + gdb + "\\" + text_pruefung(elm))
    arcpy.TableToTable_conversion(workspace + "\\" + gdb + "\\" + text_pruefung(elm), workspace + "\\" + gdb,"var")
    arcpy.DeleteField_management(workspace + "\\" + gdb + "\\" + "var", field)
    arcpy.TableToExcel_conversion(workspace + "\\" + gdb + "\\" + "var", workspace + "\\" + elm + ".xls")
    arcpy.Delete_management(workspace + "\\" + gdb + "\\" + "var")
    arcpy.AddMessage("Round" + str(counter))
    counter+=1  

1 Answer 1

2

This line is selecting for all values {} in field Name2.

arcpy.SelectLayerByAttribute_management("selectlayer", "NEW_SELECTION", "Name2 =' {} '")

Try this:

arcpy.SelectLayerByAttribute_management("selectlayer", "NEW_SELECTION", "Name2 ='{}'".format (elm))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.