Data Driven Pages Naming Issue

364
3
10-17-2018 08:09 AM
LieslDe_Swardt1
New Contributor III

Hi All, 

I am new to python, and have been using data driven pages to export multiple maps. However, I would like to change the way I'm naming my maps. Currently it is the custom name + the page name that is linked to the data driven pages.See script below:

mxd = arcpy.mapping.MapDocument("CURRENT")
... df = arcpy.mapping.ListDataFrames(mxd)[0]
...
... in_folder = arcpy.GetParameterAsText(0)
... file_name = arcpy.GetParameterAsText(1)
...
... for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
... mxd.dataDrivenPages.currentPageID = pageNum
... pageName = mxd.dataDrivenPages.pageRow.Name
... arcpy.mapping.ExportToJPEG(mxd, r"C:\Users\LiesldeSwardt\Maps\NR Maps\2D_" + pageName + ".jpeg", resolution=250)
... del mxd
... del df

So basically it currently names: 2D_Pretoria of which Pretoria is the pageRow and 2D is my custom name whereas I would like it to name as: Pretoria_2D. I hope this makes sense, any help would be appreciated.

0 Kudos
3 Replies
DanPatterson_Retired
MVP Emeritus

is this a folder?

r"C:\Users\LiesldeSwardt\Maps\NR Maps\2D_"

If not, then strip the 2D_ part off

If it is, then do you want

r"C:\Users\LiesldeSwardt\Maps\NR Maps\2D_" + "\\" + pageName + "_2D.jpeg"

LieslDe_Swardt1
New Contributor III

Sorted!! Thank you so much Dan.

0 Kudos
DanPatterson_Retired
MVP Emeritus

glad it worked out

0 Kudos