0

I am running ArcGIS 10.2.2 Version 10.2.2.3552, using ArcMap.

I have searched and haven't found anything on this or if it is even possible. I'm trying to add something to my script that allows the user to define what pages to export themselves, so if they export the maps each week and only need 3 or so pages, they can input this themselves. I tried throwing something together but anything i throw in there isn't working. i think this is as close as i get:

Can someone offer me a hint or a nudge if i am in the right direction?

import arcpy
mxd = arcpy.mapping.MapDocument(r"E:\User Folders\Recreation.mxd")
ddp = mxd.dataDrivenPages
pageNumbers = raw_input("Enter Page/s:")
for pageNum in pageNumbers:
    ddp.currentPageID = pageNum
    pageName = mxd.dataDrivenPages.pageRow.Name
    a = ddp.pageRow.getValue('COUNTY_NAM')
    b = ddp.pageRow.getValue('RECREATION')
    arcpy.mapping.ExportToPDF(mxd, r"E:\User Folders\PDFs\\" + a + " " + "(" + b + ")     "+".pdf", image_quality="FASTEST", resolution = "100")
del mxd

Its getting hung up on "The attribute currentPageID is not supported on this instance of DataDrivenPages - even though i have used it successfully in the past.

1
  • You might have realized by now that raw_input doesn't work in a tool. You can put the page numbers in as a script argument or run it on command line but you cannot use input or raw_input in ArcGis. Commented Mar 31, 2015 at 1:32

1 Answer 1

2

You need to make sure the pageNum is an integer, and you need to split the input values. For this example, you'll need to enter the pages like 1, 2, 3 with spaces. Give this a try:

import arcpy

mxd = arcpy.mapping.MapDocument("E:\\User Folders\\Recreation.mxd")
ddp = mxd.dataDrivenPages

pageNumbers = raw_input("Enter Page/s: ")

for pageNum in pageNumbers.split(", "):
    ddp.currentPageID = int(pageNum)
    pageName = ddp.pageNameField.name

    a = ddp.pageRow.getValue("COUNTY_NAM")
    b = ddp.pageRow.getValue("RECREATION")

    arcpy.mapping.ExportToPDF(mxd, "E:\\User Folders\\PDFs\\" + str(a) + " " + "(" + str(b) + ")" + ".pdf", image_quality="FASTEST", resolution="100")

del mxd

Also, you aren't using the pageName variable anywhere, so you can remove it.

4
  • you could use the string .replace method to remove spaces on pageNumbers first so it wouldn't matter if the user had spaces or not. Then your split would just be pageNumbers.split(",").
    – Fezter
    Commented Mar 31, 2015 at 5:56
  • Yeah, that would probably be best.
    – ianbroad
    Commented Mar 31, 2015 at 6:04
  • This worked great, thank you! Is there a way, using this script to export them all as well?
    – Joey Carl
    Commented Mar 31, 2015 at 13:26
  • Isn't that what the ExportToPDF part is doing? Make sure that file path actually exists.
    – ianbroad
    Commented Mar 31, 2015 at 14:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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