Select to view content in your preferred language

When exporting data driven pages, is there a way to append the name/page

2131
5
04-26-2018 02:38 PM
HeathEisele
New Contributor

Looking for assistance on how to export many maps under a file name without just appending the name at the end.

For example -

Right now it would save something as:

WetlandsMap_Tract_1

Need it to save as:

Tract_1_WetlandsMap

Hoping there is a way that I can change up the location of the page/number when saving.

Thanks in advance for your help.

0 Kudos
5 Replies
DarrenWiens2
MVP Honored Contributor

I'd say your best bet is to export as usual, then change the file name, using the method of your choice, but here's how you can do it in Python:

import os

folder = 'example' # folder of files
files = os.listdir(folder) # list of files

for f in [f for f in files if f.startswith('WetlandsMap')]: # loop through matching files
    old_name, extension = os.path.splitext(f) # [file name, extension]
    old_parts = old_name.split('_') # list split by '_'
    new_name = '_'.join([old_parts[1], old_parts[2], old_parts[0]]) # construct new name
    os.rename(
        os.path.join(folder, f),
        os.path.join(folder, ''.join([new_name,extension]))
    ) # rename the old file with the new name
    print(old_name, new_name)

Output:
('WetlandsMap_Tract_1', 'Tract_1_WetlandsMap')
('WetlandsMap_Tract_2', 'Tract_2_WetlandsMap')
0 Kudos
DavidWatkins
Esri Contributor

Darren has the right idea.  Unfortunately, there isn't a way to do this from the User Interface. The alternative is to use the arcpy.mapping Python module to write a script.   You can use Python to export the pdf files directly and give them your unique naming convention.  I would recommend starting with this help topic starting with the Export to PDF examples:  Getting started with arcpy.mapping tutorial—Help | ArcGIS Desktop 

HeathEisele
New Contributor

Thank you for the link to the tutorial.  Very helpful, as I'm just learning about Python and its capabilities.

Unfortunately, it wasn't clear how I could export numerous pdf's created from data driven pages.

Trying to create maps of 3500+ different parcels, with multiple layers (for example imagery, transportation, property boundaries, and wetlands).  Would like to be able to save individual property maps as Tract_1_WetlandsMap, Tract_2_WetlandsMap, etc.

Should I be thinking of Data Driven Pages as one method and Python scripting as another?  Or will they work together?

0 Kudos
DarrenWiens2
MVP Honored Contributor

There are two options: 1.) export the DDPs as usual, then change the file names (you could do it manually if you want, but can automate as above using Python), or 2.) automate the DDP export using Python and save the outputs as the file names of your choice.

0 Kudos
ZackaryKing
New Contributor II

Hi Heath,

I have had my struggles with Data Driven Pages as well. That is how I got into using python scripting, definitely the best technical decision I have made in my career.

If you find you are needing to do this process frequently I would definitely recommend taking the time to write a python script using arcpy. However, there are non python alternatives. I have used Microsoft excel and .bat files to quickly rename the files in a folder and there are batch rename utilities out there such as this one: http://www.bulkrenameutility.co.uk/Main_Intro.php.

The excel/.bat file method is difficult to explain on here, but if you are interested in it I can try walking you through it.

0 Kudos