A previous post shared five Python code snippets to automate mapping tasks in ArcMap. This post walks you through how to accomplish those same tasks using the ArcGIS Pro Python window.
In ArcGIS Pro, the mapping module is called arcpy.mp. To try the snippets below for yourself, make a copy of an ArcGIS Pro project file (APRX) and move it somewhere for testing purposes. You don’t have to be an experienced Python scripter—simply enter the code below into the Python window and check out the results.
You’ll soon see how a few Python tricks can speed up map management.
Snippet 1: Check Layer Definition Queries
Suppose you need to check if any of the layers in your ArcGIS Pro project have a definition query applied, and if so, view the definition queries. Opening the Layer Properties dialog box for each layer in each map is a pain.
Solution: Open the Python window instead and run the code below. The name and definition query of all the layers will be “printed” (i.e., displayed in the Python window).
Code Breakdown
Snippet 2: Fix Broken Links
At some point, you have probably moved map data from one workspace to another. Have you ever seen the dreaded red exclamation marks?
If the path to map layers has changed, with just a few lines of code you can quickly find the old workspace path and replace it with the new workspace path for all layers and tables in your project at once. Run the following lines of code in the Python window (be sure to update the paths to reflect your old and new workspaces).
Code Breakdown
Snippet 3: Identify Layers with a Broken Data Source
Speaking of those red exclamation marks, you can also use arcpy.mp to print out the layers that have broken links using the code below.
Code Breakdown
Snippet 4: Inventory Layer Data Sources
If you need to know the data source for all the layers in your project, but don’t want to open the Layer Properties dialog box for each, simply run the lines of code below in the Python window to print out the names and data sources of the layers.
Code Breakdown
Snippet 5: Combine PDF Documents
Maybe you’re creating a map book or maybe you have a few PDF documents you need to combine (like your expense report and receipts). You can use arcpy.mp and the PDFDocument class to manipulate PDF documents. Run the code below to combine two PDF documents.
Code Breakdown
Want to learn more?
If you’d like to learn more about working with the ArcGIS Pro Python window or migrating Python scripts from ArcMap to ArcGIS Pro, check out these resources:
This post was contributed by Esri instructor Brittney White. Based in Washington, D.C., Brittney’s passion is helping customers learn about and apply Esri technology to their own work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.