Get Diagram Template Names (Network Diagram)

Summary

Returns the names of all diagram templates related to a network.

Usage

  • This tool is not supported when working with a utility network or trace network service. You must use either a utility network or trace network in a file or mobile geodatabase, or a database connection to a utility network or trace network in an enterprise geodatabase. When working with an enterprise geodatabase the following are requirements:

  • This tool is mainly used to loop on diagram templates when running in ModelBuilder or Python.

Parameters

LabelExplanationData Type
Input Network

The utility network or trace network to which the diagram template names are related.

Utility Network; Trace Network

Derived Output

LabelExplanationData Type
Output Diagram Templates

The output diagram template names.

String

arcpy.nd.GetDiagramTemplateNames(in_utility_network)
NameExplanationData Type
in_utility_network

The utility network or trace network to which the diagram template names are related.

Utility Network; Trace Network

Derived Output

NameExplanationData Type
out_template_names

The output diagram template names.

String

Code sample

GetDiagramTemplateNames example (workflow)

Export definitions of all diagram templates related to a given network.

The following script tool retrieves the list of the diagram templates related to a network and exports the definitions for each template into .ndbd and .ndld files in a given folder.

To add and configure this script tool, complete the following steps:

  1. Copy the following script into any Python IDE and save with the .py extension.
  2. Start ArcGIS Pro with a new blank project or an existing project.
  3. Add a new toolbox, or in the Catalog pane, click Project and use the default project toolbox under Toolboxes.
  4. Right-click this toolbox and click New > Script.
  5. Complete the General tab as follows:
    • Name—Type ExportAllDiagramTemplateDefinitions.
    • Label—Type Export All Diagram Template Definitions.
    • Script File—Browse to and select the .py file created in step 1.
  6. Complete the Parameters tab as follows:
    • 1st parameter
      • Label—Type Input Network.
      • Name—Keep the default name, Input_Network.
      • Data Type—Select Utility Network and Trace Network.
      • Type—Select Required.
      • Direction—Select Input.
    • 2nd parameter
      • Label—Type Definition Files Export Folder.
      • Name—Keep the default name Definition_Files_Export_Folder.
      • Data Type—Select Folder.
      • Type—Select Required.
      • Direction—Select Input.
  7. Click OK. The Script Tool dialog box closes.

To run the script tool, complete the following steps:

  1. Expand the toolbox and double-click the tool to open it.
  2. Specify the Input Network parameter—that is, browse to and select the database connection file or the file or mobile geodatabase referencing the network from which you want to export all the template definitions,
  3. Specify the Output Folder parameter—that is, browse to and select the output folder where you want to export the template definition files.
  4. Click Run.

# Name: ExportAllDiagramTemplateDefinitions.py
# Description: Export definitions of all diagram templates related to a given network.

# Import system modules
import arcpy
import os
import re

# Initialize variables
msgInputsErr = "Invalid arguments."
msgScriptErr = "Error during script operation."
ndbd_ext = ".ndbd"
ndld_ext = ".ndld"

# Set overwrite option
arcpy.env.overwriteOutput = True

# Decodes parameters
try:
    input_Network = arcpy.GetParameterAsText(0)
    input_Folder = arcpy.GetParameterAsText(1)

    if input_Network == "" or input_Folder == "" :
        raise Exception()

except Exception:
    arcpy.AddError(msgInputsErr)
    raise

# Main code
try:
    arcpy.AddMessage("Retrieving the templates list...")
    output_TemplateNames = arcpy.GetDiagramTemplateNames_nd(input_Network)
    templateNamesList = re.split(';', str(output_TemplateNames))
    arcpy.AddMessage("Looping on each template...")
    for template in templateNamesList:
        message = "Exporting template: {}".format(template)
        arcpy.AddMessage(message)
        arcpy.ExportDiagramTemplateDefinitions_nd(input_Network, template, 
                                                  os.path.join(input_Folder, template + ndbd_ext), 
                                                  os.path.join(input_Folder, template + ndld_ext))

except Exception:
    arcpy.AddError(msgScriptErr)
    raise

Environments

This tool does not use any geoprocessing environments.

Licensing information

  • Basic: No
  • Standard: Yes
  • Advanced: Yes

Related topics