0

Below is a portion of a script that works with a ddp enabled map document using an index grid where the name is a string (examples A23, B34, etc) and the sort field (ie the page names) are simple integer values. The first portion makes a list of page numbers based on a query and the second part exports those pages as PDFs.

I'm trying to modify it for a different index grid where the sort field is the same field as the string name field so the range function doesn't work. I can get a list of all the page names that I want to export but I can't figure out how to acutally get them to export. I figure its something along the lines of "for items in names_list:...." but I can't find a list of ddp functions anywhere so I'm really stuck. Anyone know how to make this work or alternatively does anyone know where a list of ddp python functions and their use exists?

for row in arcpy.SearchCursor(grid): 

    expression = str(row.getValue(field_name))
    if expression.startswith(letter_block):
        x = row.getValue(field_num)
        range_list.append(x)

    for page_num in range(range_list[0], range_list[len(range_list)-1]+1):
        mxd.dataDrivenPages.currentPageID = page_num
        page_name = mxd.dataDrivenPages.pageRow.getValue(field_name)
        arcpy.mapping.ExportToPDF(mxd, str(page_name) + ".pdf")
2
  • I fixed the code block for easier readability. Does it look like you expect now? Jun 24, 2017 at 21:41
  • Yeah that is a lot better! It's my first time posting on here thank you. Jun 25, 2017 at 20:31

1 Answer 1

0

You can get the index using the method dataDrivenPages.getPageIDFromName.

>>> import arcpy
>>> mapFld = r"C:\Path\to\map.mxd"
>>> mxd = arcpy.mapping.MapDocument (mapFld)
>>> mxd.dataDrivenPages.getPageIDFromName (r"SJE\3413-C6")
2005

Create a set of IDs, say in variable ids, and then create a string of comma-separated IDs.

>>> idStr = ", ".join (map (str, ids))

You can now use dataDrivenPages.exportToPDF to export each map.

>>> mxd.dataDrivenPages.exportToPDF (r"C:\Project\Output\Map.pdf", "RANGE", idStr)
1
  • I forgot to comment that this helped me figure out my problem. Thanks :) Aug 28, 2017 at 0:19

Your Answer

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

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