HOW TO
In ArcGIS Pro, the Validate Network Topology and Update Subnetwork geoprocessing tools are used to manually validate features with dirty areas in the network topology and update subnetworks in ArcGIS Utility Network. This article describes a workflow to iterate these operations using ArcPy in ArcGIS Pro, enabling them to be executed repeatedly by applying iteration in the Python code.
Note: • Ensure the ArcGIS Utility Network license is assigned to the organization to enable ArcGIS Utility Network functionality. • Ensure the ArcGIS Pro user license is Standard or Advanced. Refer to ArcGIS Pro: ArcGIS Pro license levels for more information.

import arcpy
arcpy.env.workspace = (
r"C:<geodatabase_path>"
)
fc = "utility network feature class" # Utility network feature class containing lifecyclestatus field field_name = "lifecyclestatus" # field to toggle oid_to_update = Object_ID # OBJECTID of the Utility Network feature to update (in number)
aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.activeMap
utility_network = m.listLayers("Utility_Network_Name")[0]
print(f"Using Utility Network layer: {utility_network.name}")
domain_network = "domain_network" tier_name = "tier" subnetwork_name = "subnetwork_name"
for iteration in range(1): # this range of iteration depends on the user's testing requirements, the range number is flexible
# Toggle lifecycle status on the selected switch
with arcpy.da.UpdateCursor(
fc,
[field_name],
f"OBJECTID = {oid_to_update}"
) as cursor:
for row in cursor:
# Toggle between two valid lifecycle values
row[0] = 4 if row[0] == 0 else 0
cursor.updateRow(row)
print(f"Iteration {iteration + 1}: lifecycle status updated")
# Validate Network Topology
arcpy.un.ValidateNetworkTopology(
utility_network,
"DISPLAY"
)
print("Network topology validated")
try:
arcpy.un.UpdateSubnetwork(
in_utility_network=utility_network,
domain_network=domain_network,
tier=tier_name,
all_subnetworks_in_tier="SPECIFIC_SUBNETWORK",
subnetwork_name=subnetwork_name,
continue_on_failure="STOP_ON_FAILURE"
)
print(f"Subnetwork '{subnetwork_name}' updated")
except arcpy.ExecuteError:
# Expected case when the subnetwork is already clean
print(f"Subnetwork '{subnetwork_name}' is already clean (not dirty)")
print("-" * 50)
print("All iterations completed successfully.")
The following code shows a sample of the full script.
import arcpy
# Set workspace to the Utility Network file geodatabase
arcpy.env.workspace = (
r"C:\Users\george\Documents\ArcGIS\Packages\Electric Utility Network_000\commondata\electric_utility_network.gdb"
)
# Utility Network feature class and field used to stimulate an edit
fc = "Electric Junction Object" # base UN class
field_name = "lifecyclestatus" # field to toggle
oid_to_update = 51 # chosen Switch OBJECTID
# Access the current ArcGIS Pro project and active map
aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.activeMap
# Get the Utility Network layer from the map by name
utility_network = m.listLayers("ElectricNetwork Utility Network")[0]
print(f"Using Utility Network layer: {utility_network.name}")
# Details of the subnetwork to be updated
domain_network = "Electric"
tier_name = "Electric Distribution"
subnetwork_name = "Essential 003"
# Loop through repeated edit and subnetwork update operations
for iteration in range(5): # start small
# Toggle the lifecycle status to introduce and edit
with arcpy.da.UpdateCursor(
fc,
[field_name],
f"OBJECTID = {oid_to_update}"
) as cursor:
for row in cursor:
# Toggle between two valid lifecycle values
row[0] = 4 if row[0] == 0 else 0
cursor.updateRow(row)
print(f"Iteration {iteration + 1}: lifecycle status updated")
# Validate the Utility Network Topology
arcpy.un.ValidateNetworkTopology(
utility_network,
"DISPLAY"
)
print("Network topology validated")
# Update the specified subnetwork
try:
arcpy.un.UpdateSubnetwork(
in_utility_network=utility_network,
domain_network=domain_network,
tier=tier_name,
all_subnetworks_in_tier="SPECIFIC_SUBNETWORK",
subnetwork_name=subnetwork_name,
continue_on_failure="STOP_ON_FAILURE"
)
print(f"Subnetwork '{subnetwork_name}' updated")
except arcpy.ExecuteError:
# Display message if subnetwork is not dirty
print(f"Subnetwork '{subnetwork_name}' is already clean (not dirty)")
print("-" * 50) # print 50 hyphens (only to improve readability)
print("All iterations completed successfully.")
The output displays each iteration of the network topology validation and subnetwork update processes, as shown below.

Article ID: 000038698
Get help from ArcGIS experts
Start chatting now