import arcpy mxd = arcpy.mapping.MapDocument(r"C:\Project\ParcelAtlas.mxd") df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] rasLyrFile = arcpy.mapping.Layer(r"C:\Project\Data\Basemap.lyr") for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1): mxd.dataDrivenPages.currentPageID = pageNum arcpy.mapping.AddLayer(df, rasLyrFile, "BOTTOM") #You can use InsertLayer for more precise placement mxd.dataDrivenPages.exportToPDF(r"C:\Project\Output\Page" + str(pageNum) + ".pdf", "CURRENT") arcpy.mapping.RemoveLayer(df, rasLyrFile) del mxd
Unfortunately arcpy.mapping can't work with the stretched renderer. Rather than the raster being a permanent layer in the MXD, what if you tried adding and deleting it with each page? Below is a sample snippet of code from the arcpy.mapping DDP Class help topic that I modified to add/remove your raster between DDP pages. It just requires that you save your raster out as a layer file. import arcpy mxd = arcpy.mapping.MapDocument(r"C:\Project\ParcelAtlas.mxd") df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] rasLyrFile = arcpy.mapping.Layer(r"C:\Project\Data\Basemap.lyr") for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1): mxd.dataDrivenPages.currentPageID = pageNum arcpy.mapping.AddLayer(df, rasLyrFile, "BOTTOM") #You can use InsertLayer for more precise placement mxd.dataDrivenPages.exportToPDF(r"C:\Project\Output\Page" + str(pageNum) + ".pdf", "CURRENT") arcpy.mapping.RemoveLayer(df, rasLyrFile) del mxdJeff
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.