3

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
  • Finally I found what I´m was looking for, and made some modification on the scrip to save pdf files, however I get the next error message: AttributeError: Invalid destination path I don't understand where is the mistake – Victor Quiroz Barrientos Dec 1 '16 at 18:19
  • This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. You can also add a bounty to draw more attention to this question once you have enough reputation. - From Review – nmtoken Dec 1 '16 at 18:45
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review – John Powell Dec 1 '16 at 19:05
  • Victor, i have a script that does exactly the same, but for a PDF format. contact me, i send it to you. – raphael Dec 4 '16 at 15:53
3

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
  • Let me know if it works. I didn't test it on my machine. – Steve Apr 28 '15 at 16:02
  • Steve, thanks. I saw not your answer, when i was comming here to say that que original script was already saving the way i need. I dont know what happend yestarday, but today is working fine! – raphael Apr 28 '15 at 19:57
0

If you define a field name attribute and call it like below: you will be able to use the Page name when exporting to PDF

field_name = "***Insert Field Name here****"

page_name = mxd.dataDrivenPages.pageRow.getValue(field_name)
str(page_name) + ".pdf")
arcpy.mapping.ExportToPDF(mxd, ***Path to output folder*** + str(page_name) + ".pdf")

That worked for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.