Using python to Validate Network Topology in a version

1592
18
Jump to solution
09-15-2023 04:44 AM
jclarke
Occasional Contributor

Hi all,

I am trying to write a standalone python script that does something like this

arcpy.ChangeVersion_management('unnetworklayer','BRANCH', version_name, '#', 'INCLUDE')
arcpy.ValidateNetworkTopology_un('unnetworklayer', 'DEFAULT')
 
The documentation says both these tools accept a "Utility Network Layer" as input. But how can I make one? I have tried MakeFeatureLayer etc.
0 Kudos
18 Replies
RobertKrisher
Esri Regular Contributor

Instead of directly accessing the internal variable that holds the version manager (_version) you should go through the front door. Here is how I get the version manager, default version, and un object in most of my scripts:

# Get the version and Utility Network reference
messages.addMessage(f"Connecting to {version_service_url}")
version_manager = VersionManager(version_service_url, gis=gis, flc=feature_layer_collection)
messages.addMessage(f"Connecting to version: {version_name}")
default_version = version_manager.get(version_name)
utility_network_manager = default_version .utility
 
0 Kudos
KevinPiraino2
Regular Contributor

Unfortunately, I tried something similar when troubleshooting earlier and still was unsuccessful. In both my earlier attempts and using the code block you provided, I still received the following error: 

Exception: Unable to resume a service session.
(Error Code: 0)

 

0 Kudos
RobertKrisher
Esri Regular Contributor

Before you start reading/writing data with the version, make sure you call either start_reading or start_editing  to establish a shared or exclusive lock with the version. When your script finishes/cleans up make sure you stop reading/editing in order to release locks.

KevinPiraino2
Regular Contributor

Unfortunately, no I have a different error and I am unable to start an edit session using the start_editing() method (can start reading though). Maybe its something with my UN configuration or how I am trying to instantiate the VersionManager object.

Exception: The operation is not supported by this implementation.
(Error Code: 0)

 

0 Kudos
RobertKrisher
Esri Regular Contributor

Try just using start_reading

KevinPiraino2
Regular Contributor

That seemed to work at least for the "update is connected" and "update subnetwork" methods. The "validate topology" method still produced an error, but its unclear to me if that is an expected error if no recent edits were performed or any dirty areas are present in the UN.

Exception: A dirty area is not present within the validate network topology input extent. A validate network topology process did not occur.
(Error Code: 0)
0 Kudos
RobertKrisher
Esri Regular Contributor

That's the expected error you get when you try and validate without checking to see if there are dirty areas that need validating in the extent. You should check for dirty areas that need validating before calling that method. Just like you should check for dirty subnetworks before calling update subnetwork. Running update isconnected is not necessary if you run UpdateSubnetwork, since subnetworks manage the isconnected field.

KevinPiraino2
Regular Contributor

I appreciate all of the help you have provided, but I'm not sure how to go about querying for dirty areas. I am unable to find any Objects in the API documentation that that would grant that this capability. As far as I can tell there aren't any methods using the VersionManager, Version, or UtilityNetworkManager Objects that provides access to any properties related to dirty areas. Would you mind pointing me in the correct direction?

0 Kudos
RobertKrisher
Esri Regular Contributor

It is a layer, like any other in your feature service. Look at your feature service, get its layer id, and use the query method to find dirty areas with a status value that indicates they need to be validated.

RobertKrisher_0-1727107954252.png

 

0 Kudos