Hello, I have a script that uses a search cursor to go to a selected feature in a table called SplicePoints_test, that is selected based on it intersecting with some fibercable. After that I use the selected feature and extract the last 2 digits of the string of the selected entry in the SplicePoints_test layer. However when I use the searchcursor to extract the closure_name row, it iterates through all splice points and only appends the last one in the table. I used a break statement to get it to stop iterating, but it only goes to the first one instead, any ideas on how I might get the search cursor to only acknowledge the selected feature?
with arcpy.da.SearchCursor("Fibercable_Test", ['comments']) as cursor:
# Iterate through the rows
for row in cursor:
arcpy.management.SelectLayerByLocation(
in_layer="SplicePoints_test",
overlap_type="INTERSECT",
select_features="Fibercable_test",
search_distance=None,
selection_type="NEW_SELECTION",
invert_spatial_relationship="NOT_INVERT"
)
#iterate through the selected splice point, and split the last digit
with arcpy.da.SearchCursor("SplicePoints_Select", ['closure_name']) as cursor:
for row in cursor:
last_2 = row[0].split('_')[3]
arcpy.AddMessage(last_2)
# add split string to the end of the comments field
expr = "'{}{}{}'".format(entry, '.', last_2)
arcpy.management.CalculateField(
in_table="Fibercable_test",
field="comments",
expression=expr,
expression_type="PYTHON3",
code_block="",
field_type="TEXT",
enforce_domains="NO_ENFORCE_DOMAINS"
)