HOW TO

Iterate network topology validation and subnetwork update using ArcPy in ArcGIS Pro

First Published: October 22, 2025
Last Published: April 22, 2026

Summary

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.

Procedure

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.
  1. Open the ArcGIS Utility Network project in ArcGIS Pro.
  2. On the View ribbon tab, in the Windows group, click Python Window.
The Python Window button in the Windows group
  1. In the Python window, copy and paste the code below to automate the validation of network topology and update of subnetwork for ArcGIS Utility Network using ArcPy.
  1. Set the workspace to the geodatabase that contains the utility network dataset used in the project.
import arcpy
arcpy.env.workspace = (
    r"C:<geodatabase_path>"
)
  1. Select a feature class from the utility network.
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)
  1. Retrieve the current project and active map.
aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.activeMap
  1. Match the utility network name with the utility network layer in the Contents pane.
utility_network = m.listLayers("Utility_Network_Name")[0]
print(f"Using Utility Network layer: {utility_network.name}")
  1. Specify the domain network, tier, and subnetwork to be updated.
domain_network = "domain_network"
tier_name = "tier"
subnetwork_name = "subnetwork_name"
  1. Validate the network topology.
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")
  1. Update the 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"
        )
  1. Display the console output for each iteration.
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.")
  1. Press Enter twice to execute the Python code.

The output displays each iteration of the network topology validation and subnetwork update processes, as shown below.

The successful iteration of network topology validation and subnetwork update processes

Article ID: 000038698

Software:
  • ArcGIS Pro
  • ArcGIS Utility Network

Get support with AI

Resolve your issue quickly with the Esri Support AI Chatbot.

Start chatting now

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Start chatting now

Go to download options