DataDrivenPages exporting a selection

584
2
Jump to solution
12-13-2012 12:20 PM
JonPedder
Occasional Contributor II
I'm working through the examples in the online help, example #3 shows how to export a selection of records rather than everything.
import arcpy mxd = arcpy.mapping.MapDocument(r"C:\Project\ParcelAtlas.mxd") ddp = mxd.dataDrivenPages indexLayer = ddp.indexLayer arcpy.SelectLayerByAttribute_management(indexLayer, "NEW_SELECTION",                                           '"PageNumber" >= 1 AND "PageNumber" <= 10') for indexPage in ddp.selectedPages:   ddp.currentPageID = indexPage   ddp.exportToPDF(r"C:\Project\Output\Page" + str(indexPage) + ".pdf", "CURRENT")  del mxd


I have DDP setup on a mxd and when I run the script it always exports ALL the records. The changes I made to the script only pertain to the mxd patch, destination path and field name that is the index layer.

import arcpy mxd = arcpy.mapping.MapDocument(r"C:\MapSAR\New_Incident_Z11\Map_Templates\MapSAR_ANSI_A_8x11_Letter_Landscape_DDP.mxd") ddp = mxd.dataDrivenPages indexLayer = ddp.indexLayer arcpy.SelectLayerByAttribute_management(indexLayer, "NEW_SELECTION",'"Assignment_Number" > 1 AND "Assignment_Number" < 3') for indexPage in ddp.selectedPages:   ddp.currentPageID = indexPage   ddp.exportToPDF(r"C:\MapSAR\New_Incident_Z11\Products\page" + str(indexPage) + ".pdf", "CURRENT")  del mxd


can anyone either point out what I'm doing incorrectly or even better if there's other code examples I might learn from.

Thanks

Jon
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JonPedder
Occasional Contributor II
Thanks Jeff.

I found the issue. The FC are Joined so I need complete joined field name assignments.assignment_number

Jon

View solution in original post

0 Kudos
2 Replies
JeffBarrette
Esri Regular Contributor
I just copy/pasted your second code snippet, made minor path and query changes, and ran it just fine in 10.1 sp1.  Here is the code I used.

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Temp\Untitled.mxd")
ddp = mxd.dataDrivenPages
indexLayer = ddp.indexLayer
arcpy.SelectLayerByAttribute_management(indexLayer, "NEW_SELECTION", "\"State_Name\" = 'Rhode Island'")
#arcpy.SelectLayerByAttribute_management(indexLayer, "NEW_SELECTION", '"SHAPE_AREA" > 0')
for indexPage in ddp.selectedPages:
  ddp.currentPageID = indexPage
  ddp.exportToPDF(r"C:\Temp\\" + str(indexPage) + ".pdf", "CURRENT")
del mxd


Comment out your SelectLayerByAttribute line and run the code.  Nothing should get exported unless you have saved features in your MXD.

Jeff
0 Kudos
JonPedder
Occasional Contributor II
Thanks Jeff.

I found the issue. The FC are Joined so I need complete joined field name assignments.assignment_number

Jon
0 Kudos