I'm using ArcGIS desktop 10.6 and executing an arcpy script.
I'm creating a script that checks an input shapefiles field values against a set of rules. To do so I've created 2 lists with unique values of 2 fields within my input shapefile.
These are the UniqueDispTypeValues list and RelUnqID list.
I also have created a list of allowable values to check against.
This is the DispTypeValues list.
I created an if else statement to check a basic rule (If only RTF value exists the Rel_Unq_ID must be 0), however I want to check the current value of the field after the if statement(kind of validating a field value, or passing a rule in my case) instead of just the print statement.
Here is a screenshot of the attribute table:
Here is the code:
# Importing necessary modules
import arcpy, os
arcpy.env.overwriteOutput = True
# Setting path to mxd and Data Frame
mxd = arcpy.mapping.MapDocument(r"CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
# Assign the OneSTOP shapefile to a variable
shp = r"P:\JOBS\2020\20-1095\Outgoing_Information\OneSTOP\Disposition.shp"
#Create the unique list of allowable Disposition Types
def DTV(CHK_TABLE , Disp_Type):
with arcpy.da.SearchCursor(CHK_TABLE, [Disp_Type]) as cursor:
return sorted({row[0] for row in cursor})
DispTypeValues = DTV(r'Q:\GIS\OneSTOP\OneSTOP2.gdb\Checklist' , 'Disp_Type')
print (DispTypeValues)
#Create the unique list of Disposition Types in the input shapefile
def UDTV(shp , Disp_Type):
with arcpy.da.SearchCursor(shp, [Disp_Type]) as cursor:
return sorted({row[0] for row in cursor})
UniqueDispTypeValues = UDTV(shp , 'Disp_Type')
print (UniqueDispTypeValues)
#Create the unique list of Rel_Unq_ID in the input shapefile
def RUID(shp , Rel_Unq_ID):
with arcpy.da.SearchCursor(shp, [Rel_Unq_ID]) as cursor:
return sorted({row[0] for row in cursor})
RelUnqID = UDTV(shp , 'Rel_Unq_ID')
print (RelUnqID)
length = len(UniqueDispTypeValues)
print (length)
for value in UniqueDispTypeValues:
if value == 'RTF' and length == 1:
print "Rel_Unq_ID must be 0"
else:
print "Rel_Unq_ID must be non zero"