Select to view content in your preferred language

Trace Geometric Network got ERROR 000366 only with arcpy

164
1
Jump to solution
11-06-2024 06:33 AM
TeresaBartolomei
New Contributor

Hi, I've created a tool that selects some layers by attribute and others by location, then in the end it makes a Trace Geometric Network. When I run the tool by "Edit Mode" everything is okay , the group layer is created and added to the map.

But when I export the python script (because I need to modify it later) and just copy and paste it  inside the python window of geoprocessing section, it breaks at the final step, the Trace Geometric Network, with the error: "Failed to execute. Parameters are not valid. ERROR 000366: Invalid geometry type Failed to execute (TraceGeometricNetwork)."

 

This is the last line of the script, that throws the error: 

# Process: Trace Geometric Network
arcpy.TraceGeometricNetwork_management(RETEAD_BT_Net__2_, GruppoCS_75460, Interruttori_BT__2_, "FIND_CONNECTED", "", "", "", "", "", "NO_TRACE_ENDS", "NO_TRACE_INDETERMINATE_FLOW", "", "", "AS_IS", "", "", "", "AS_IS")
0 Kudos
1 Solution

Accepted Solutions
TonyAlmeida
Frequent Contributor

Try referencing the layer directly by name instead of by group. Group layer  may not translate correct.

Try this, there is some debugging parameters to check for empty geometries.

 

import arcpy

# Define your inputs
RETEAD_BT_Net__2_ = "in_geometric_network"
GruppoCS_75460 = "group_layer" #out_network_layer
Interruttori_BT__2_ = "switches_layer" #in_flags

try:
    # Describe the inputs to check their geometry types
    desc_network = arcpy.Describe(RETEAD_BT_Net__2_)
    desc_group = arcpy.Describe(GruppoCS_75460)
    desc_switches = arcpy.Describe(Interruttori_BT__2_)

    print(f"Network Geometry Type: {desc_network.shapeType}")
    print(f"Group Layer Geometry Type: {desc_group.shapeType}")
    print(f"Switches Layer Geometry Type: {desc_switches.shapeType}")

    # Ensure the inputs are not empty
    network_count = int(arcpy.GetCount_management(RETEAD_BT_Net__2_).getOutput(0))
    group_count = int(arcpy.GetCount_management(GruppoCS_75460).getOutput(0))
    switches_count = int(arcpy.GetCount_management(Interruttori_BT__2_).getOutput(0))

    print(f"Network Feature Count: {network_count}")
    print(f"Group Layer Feature Count: {group_count}")
    print(f"Switches Layer Feature Count: {switches_count}")

    if network_count == 0 or group_count == 0 or switches_count == 0:
        raise ValueError("One or more input layers are empty.")

    # Process: Trace Geometric Network
    arcpy.TraceGeometricNetwork_management(
        RETEAD_BT_Net__2_, GruppoCS_75460, Interruttori_BT__2_, 
        "FIND_CONNECTED", "", "", "", "", "", 
        "NO_TRACE_ENDS", "NO_TRACE_INDETERMINATE_FLOW", "", "", 
        "AS_IS", "", "", "", "AS_IS"
    )

    print("Trace Geometric Network completed successfully.")

except arcpy.ExecuteError:
    print(f"Geoprocessing error: {arcpy.GetMessages(2)}")
except Exception as e:
    print(f"An error occurred: {e}")

 

 

 

View solution in original post

1 Reply
TonyAlmeida
Frequent Contributor

Try referencing the layer directly by name instead of by group. Group layer  may not translate correct.

Try this, there is some debugging parameters to check for empty geometries.

 

import arcpy

# Define your inputs
RETEAD_BT_Net__2_ = "in_geometric_network"
GruppoCS_75460 = "group_layer" #out_network_layer
Interruttori_BT__2_ = "switches_layer" #in_flags

try:
    # Describe the inputs to check their geometry types
    desc_network = arcpy.Describe(RETEAD_BT_Net__2_)
    desc_group = arcpy.Describe(GruppoCS_75460)
    desc_switches = arcpy.Describe(Interruttori_BT__2_)

    print(f"Network Geometry Type: {desc_network.shapeType}")
    print(f"Group Layer Geometry Type: {desc_group.shapeType}")
    print(f"Switches Layer Geometry Type: {desc_switches.shapeType}")

    # Ensure the inputs are not empty
    network_count = int(arcpy.GetCount_management(RETEAD_BT_Net__2_).getOutput(0))
    group_count = int(arcpy.GetCount_management(GruppoCS_75460).getOutput(0))
    switches_count = int(arcpy.GetCount_management(Interruttori_BT__2_).getOutput(0))

    print(f"Network Feature Count: {network_count}")
    print(f"Group Layer Feature Count: {group_count}")
    print(f"Switches Layer Feature Count: {switches_count}")

    if network_count == 0 or group_count == 0 or switches_count == 0:
        raise ValueError("One or more input layers are empty.")

    # Process: Trace Geometric Network
    arcpy.TraceGeometricNetwork_management(
        RETEAD_BT_Net__2_, GruppoCS_75460, Interruttori_BT__2_, 
        "FIND_CONNECTED", "", "", "", "", "", 
        "NO_TRACE_ENDS", "NO_TRACE_INDETERMINATE_FLOW", "", "", 
        "AS_IS", "", "", "", "AS_IS"
    )

    print("Trace Geometric Network completed successfully.")

except arcpy.ExecuteError:
    print(f"Geoprocessing error: {arcpy.GetMessages(2)}")
except Exception as e:
    print(f"An error occurred: {e}")