Friday 14 February 2020

arcpy - Changing output name when exporting data driven pages to JPG?


Is there a way to save the output JPG, changing the output file name to the page name, instead of page number?


I mean changing the script found in this post?


import_path = r"..."   # Path of .mxd
export_path = r"..." # Path of output file
field_name = "Name" # Name of field used to sort DDP


mxd = arcpy.mapping.MapDocument(import_path)
for i in range(1, mxd.dataDrivenPages.pageCount + 1):
mxd.dataDrivenPages.currentPageID = i
row = mxd.dataDrivenPages.pageRow
print row.getValue(field_name)
arcpy.mapping.ExportToJPEG(mxd, export_path + "." + row.getValue(field_name) + ".jpg")
del mxd

Answer



If you define a new variable: pageName = mxd.dataDrivenPages.pageRow.Name You can then include the variable in the export path: str(pageName)


import_path = r"..."   # Path of .mxd

export_path = r"..." # Path of output file
field_name = "Name" # Name of field used to sort DDP

mxd = arcpy.mapping.MapDocument(import_path)
for i in range(1, mxd.dataDrivenPages.pageCount + 1):
mxd.dataDrivenPages.currentPageID = i
row = mxd.dataDrivenPages.pageRow

pageName = mxd.dataDrivenPages.pageRow.Name


print row.getValue(field_name)
arcpy.mapping.ExportToJPEG(mxd, export_path + "." + row.getValue(field_name) + str(pageName) +".jpg")
del mxd

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...