AnsweredAssumed Answered

How to make a loop work?

Question asked by jramirez@irvineco on Aug 20, 2019
Latest reply on Aug 26, 2019 by jramirez@irvineco

Hi, 

I have a survey made from survey 123, I have a point layer representing assets. The goal is to complete the survey for every asset. I have a field in my points layer called CompleteY_N, by default the attribute is 'Not Completed'. I want the attribute to change to 'complete' as a survey it summited and loop through until all assets say complete in the CompleteY_N field. 

I wrote a script that selects by location and then uses UpdateCursor to change the attribute to complete. I have also used field calculate to change the selected features to complete ( not sure which way is better). 

I am not sure how to do a loop like this, or if I have even explained what I am trying to do correctly.  

Here is my script. 

import arcpy

# Input property
inPropertypntfc = r"G:\GIS\ESRI\Staging\Survey123\Testing\New File Geodatabase.gdb\propertypnts"
print(inPropertypntfc)

# input survey feature class
inSurveyfc = r"G:\GIS\ESRI\Staging\Survey123\Testing\New File Geodatabase.gdb\retailpt2"
print(inSurveyfc)

# Make feature layer of feature classes to allow selection
arcpy.MakeFeatureLayer_management(inPropertypntfc, "Propertypntlyr")
arcpy.MakeFeatureLayer_management(inSurveyfc, "Surveylyr")


# select intersecting points
arcpy.SelectLayerByLocation_management("Propertypntlyr", "INTERSECT", "Surveylyr")
print ("select")

# Update Cursor for point layer
cursor = arcpy.da.UpdateCursor("Propertypntlyr", ["CompleteY_N"])
print (cursor)
for row in cursor:
    cursor.updateRow(["Completed"])
print ("Done")

del row
del cursor

Outcomes