I am new to using ArcPy/Python and I'm running into problems with a script I'm trying to write.
I'm using IDLE Python 3.6.8 ArcGIS Pro 2.4.0
Here is what I'm trying to do - I have 2 feature classes: 1. Water Mains, 2. Multi Ring buffer.
Within the Water Mains attribute table there is a "CriticalityScore" field. This is an integer value that is assigned based on the diameter(inches) of the pipe. Small diameter pipes = low value, larger diameter pipes receive higher values.
I am tasked with writing a script that will calculate this score for newly added pipes. I created a coded domain for a field called "Participation" to indicated "Yes/No". New pipes that are added into the attribute table by default receive "No."
What I have done so far is to assign if diameter = x then criticality score will = y.
Here's how the scores might look
- 2" = (score of) 5
- 4" = 9
- 10" = 15 etc..
What I'm struggling with now is:
- Only updating "CriticalityScore" if "Participation" = "No"
Here's what I have so far
#set your workspace, where is this pulling data from? (gdb file path)
ws = env.workspace = r"H:\Python Scripts & Tools\Script Tester - Crit Scoring.gdb"
#set the name of the shapefile path with which you're working (water main .shp)
fclass = r"H:\Python Scripts & Tools\Script Tester - Crit Scoring.gdb\Water_Mains.shp"
buffers = r"L:\Engineering\Brice\CriticalityScoringwPipeTestBrice.gdb\BufferParcelEmergancyResponceFac"
#The third item in "fields" (index position [2])should be the Yes/No field in the feature class
fields = ["Diameter", "CriticalityScore", "Participation"]
with arcpy.da.UpdateCursor(fclass, fields) as cursor:
while row[2] == No:
for row in cursor:
if row[0] == 2:
row[1] = "5"
elif row[0] == 3:
row[1] = "7"
elif row[0] == 4:
row[1] = "9"
elif row[0] == 6:
row[1] = "11"
elif row[0] == 8:
row[1] = "13"
elif row[0] == 10:
row[1] = "15"
elif row[0] == 12:
row[1] = "17"
elif row[0] == 16:
row[1] = "20"
else:
row[1] = "22"
cursor.updateRow(row)
print("The script has finished.")
The script was working before I added the "While row[2] statement. As of right now it will run through the script and give me the ending print statement, but the .aprx/attribute table is never actually updated.