I am fine tuning a 'snap by attribute' python script. It takes points in one layer and snaps them to points in another layer based on unique attribute. I keep running into an 'invalid expression' error for the first 'SelectLayerByAttribute' line of code. I can't seem to find anything wrong with the expression I am writing.
Please note that this is a heavily modified version of an existing template and not made from scratch. Code is below:
import arcpy
arcpy.env.workspace = r"C:\Users\X2NAKUNK\Snap Attribute Test\Snap_Attribute_Test.gdb"
point_layer = arcpy.MakeFeatureLayer_management("Linked_Child_Meters", "Child_Meters_lyr")
field_points = "SERV_PIPE_KEY_ID_TXT"
#the name of the field for point selection
pipes_layer = arcpy.MakeFeatureLayer_management("Service_End_Points", "ServiceEnds_lyr")
field_pipes = "SERV_PIPE_KEY_ID_TXT"
#the name of the field for the pipes selection with same names as in point layer
#creating cursor for a list of all the names in point layer
cursor_points = arcpy.SearchCursor(point_layer)
#empty list for point names
list_point_names = []
#filling the list with names from point layer
for row in cursor_points:
list_point_names .append(row.getValue(field_points))
#another empty list for storing only unique names from list_point_names
s = []
for i in list_point_names :
if i not in s:
s.append(i)
#selecting points and pipes by name:
for name in s:
layer1 = arcpy.management.SelectLayerByAttribute(point_layer , "NEW_SELECTION", "points=" +"'"+name+"'")
layer2 = arcpy.management.SelectLayerByAttribute(pipes_layer , "NEW_SELECTION", "pipes=" +"'"+name+"'")
arcpy.Snap_edit(layer1, [layer2, "VERTEX", "5000 feet"])
arcpy.management.SelectLayerByAttribute(point_layer , "CLEAR_SELECTION")
arcpy.management.SelectLayerByAttribute(pipes_layer , "CLEAR_SELECTION")
arcpy.SearchCursor
is far too ancient to be used for reference. I'd suggest starting over with aarcpy.da.SearchCursor
template