I'm trying to customize a data driven page looping statement workflow and want to set a better filename to the final export. Currently the file name uses the page index (pgIndex), but I would like it to use a specific field in the attribute table.
Here is my file naming looping statement:
for pgIndex in range(1, tempDDP.pageCount + 1, 1):
# Create a name for pdf file
temp_filename = r"C:\Desktop\Test\temp_pdfs\MB_" + \
str(pgIndex) + ".pdf"
if os.path.exists(temp_filename):
os.remove(temp_filename)
Any idea how I can get the result I want? I know this is possible if you use the built in export tool for arc 10, but I need more functionality, and therefore a customized script.
-
FWIW, more readable as: for i in range(tempDDP.pageCount): label = str(i + 1)sgillies– sgillies2012年09月04日 15:02:49 +00:00Commented Sep 4, 2012 at 15:02
-
Thanks sgillies! Any idea how to change the file naming portion of the script to use a specific value in the attribute table and not the page index?Czed– Czed2012年09月04日 15:14:14 +00:00Commented Sep 4, 2012 at 15:14
1 Answer 1
Okay, I finally figured out a method using pageRow.FIELDNAME
for i in range(1, tempDDP.pageCount + 1, 1):
# Create a name for each pdf file
tempMap.dataDrivenPages.currentPageID = i
pageName = tempMap.dataDrivenPages.pageRow.Name
temp_filename = r"C:\Desktop\Test\temp_pdfs\MB_" + \
str(i) + pageName + ".pdf"