My script is sometimes removing data from my map. I have developed a script to check a key field in several feature classes for duplicates. The script does work sometimes, but other times, it throws an error, error 000732. This mainly happens to 2 feature classes, one in which duplicates are found, and the other is the one that needs to test 2 different fields. Before running the script, I verified the layer was in the TOC and on the map. However, it was gone when I checked the TOC after the error. The strange thing is it can run the find identical in the loop fine without error, but it throws the error when it comes to the add join function. This also happens with the layer in which I need to check two fields. The find identical for the first field runs fine, but the find identical on the 2nd field can return the error. Any insights would be appreciated.
my code is:
F=("Sanitary Sewer Manholes","Water Network Structures","Water Fittings","Water System Valves","Water Service Connections","Water Hydrants","Sewer Gravity Mains","Sewer Pressurized Mains","Storm Drain Pipes", "Water Lateral Lines", "Water Mains")
b =0
for e in F:
a=F[b]
s=str(a).replace(" ", "_")
o= "C:\\Users\\lconner\\Documents\\ArcGIS\\Projects\\edit_map6\\edit_map6.gdb\\" +s+"_findidencal"+str(9)
m="C:\\Users\\lconner\\Documents\\ArcGIS\\Projects\\edit_map6\\edit_map6.gdb\\MBID_duplicate" + str(1)
arcpy.management.FindIdentical(
in_dataset= a,
out_dataset=o,
fields="FACILITYID",
xy_tolerance=None,
z_tolerance=0,
output_record_option="ONLY_DUPLICATES")
count_result = arcpy.management.GetCount(o)
count = int(count_result[0])
if count > 0:
print("Duplicate entries in "+str (a) )
print(f"Number of duplicates found: {count}")
arcpy.management.AddJoin(
in_layer_or_view=a,
in_field="OBJECTID",
join_table=o,
join_field="IN_FID",
join_type="KEEP_ALL",
index_join_fields="NO_INDEX_JOIN_FIELDS",
rebuild_index="NO_REBUILD_INDEX",
join_operation="JOIN_ONE_TO_FIRST"
)
arcpy.management.SelectLayerByAttribute(
in_layer_or_view= a,
selection_type="NEW_SELECTION",
where_clause="IN_FID IS NOT NULL",
invert_where_clause=None
)
else:
print("no Duplicate in " + str(a) )
b=b+1
arcpy.management.SelectLayerByAttribute(
in_layer_or_view="Water Service Connections",
selection_type="NEW_SELECTION",
where_clause="MBID IS NOT NULL",
invert_where_clause=None
)
arcpy.management.FindIdentical(
in_dataset="Water Service Connections",
out_dataset=m,
fields="MBID",
xy_tolerance=None,
z_tolerance=0,
output_record_option="ONLY_DUPLICATES"
)
if count > 0:
print("Duplicate MBID in Meters " )
print(f"Number of duplicates found: {count}")
arcpy.management.AddJoin(
in_layer_or_view="Water Service Connections",
in_field="OBJECTID",
join_table=m,
join_field="IN_FID",
join_type="KEEP_ALL",
index_join_fields="NO_INDEX_JOIN_FIELDS",
rebuild_index="NO_REBUILD_INDEX",
join_operation="JOIN_ONE_TO_FIRST"
)
arcpy.management.SelectLayerByAttribute(
in_layer_or_view= "Water Service Connections",
selection_type="NEW_SELECTION",
where_clause="IN_FID IS NOT NULL",
invert_where_clause=None
)
else:
print("no Duplicate MBIDs ")
Pro 3.5.1
data source: enterprise geodata base