Development Steps:
1. Tool: Read database connections
- Reads all MXDs
- Each layer’s database connection
- Remove duplicates for connection info: per feature class
- Load into spreadsheet
2. Manual: Repath database connections
- Open spreadsheet
- Change paths of data to UN data
- Need to figure out AssetGroup and how that effects data connection string
- Save spreadsheet
3. Tool: Convert MXDs
- Reads database connection spreadsheet into dictionary
- Configuration: Need a list of each FROM layer, path TO layer
- Converts each MXD to APRX file
- Repaths each layer to new UN
- Saves APRX files
# File Name: ConvertMXDs_StandAloneScript.py
# Author: Lucas Broyles
# Date Created: 2/4/2019
# Date Modified: 2/5/2019
# Python Version: 3.6.9
# Script requirements:
# 1) arcpy python module
# 2) all input MXDs within a single folder
# 3) blank APRX file (no maps, print templates, etc)
# 4) write access to output conversion folder
# Comments:
# - Script will not repath or fix data sources
# - Script will convert mxds to Maps
# - Script will convert print templates to Layouts
# - When opening APRX files, navigate in Catalog to Maps and/or Templates to see conversion result
# Begin Code
import arcpy, os
from shutil import copyfile
print("Begin MXD Conversion Script")
#----- Input Parameters -----
# Script needs a blank APRX file. Use the Pro version you intend on creating all projects
blankAPRX = r"C:\\lbroyles\\blank.aprx"
# Output folder to save all the converted Pro Projects
conversionFolder = r"C:\\lbroyles\\UN MXD Examples\\Convert\\"
# Input folder that hosts all the MXD files to be converted
mxdFolder = r"C:\\lbroyles\\UN MXD Examples\\"
#----- ArcPy Functions -----
# Loads all MXDs in mxdFolder to listFiles
arcpy.env.overwriteOutput = True
arcpy.env.workspace = mxdFolder
listFiles = arcpy.ListFiles("*.mxd")
num = 0
#----- Loop through MXD Files and convert to Pro Projects -----
for files in listFiles:
try:
print("Converting input MXD: " + files)
# copies blank APRX file each time to create one converted APRX for each input MXD
filename = (conversionFolder + str(os.path.splitext(files)[0] + ".aprx"))
inputAPRX2 = copyfile(blankAPRX, filename)
aprx = arcpy.mp.ArcGISProject(inputAPRX2)
inputMXD = os.path.join(mxdFolder, files)
aprx.importDocument(inputMXD)
aprx.save()
num = num + 1
except:
print("Conversion Error for filename: " + files)
pass
print("")
print(str(num) + " total MXD files were converted to: " + conversionFolder)
print("Finished Script")
RSS - Posts