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:
- Copy the following script into any Python IDE and save with the .py extension.
- Start ArcGIS Pro with a new blank project or an existing project.
- Add a new toolbox, or in the Catalog pane, click Project and use the default project toolbox under Toolboxes.
- Right-click this toolbox and click New > Script.
- 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.
- 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.
- Click OK. The Script Tool dialog box closes.
To run the script tool, complete the following steps:
- Expand the toolbox and double-click the tool to open it.
- 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,
- Specify the Output Folder parameter—that is, browse to and select the output folder where you want to export the template definition files.
- 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