This may be off base, but how about clipping to the current extent of the data driven page? You can include all layers within the clip so it'll clip vector and raster data.
import arcpy, os ... mxd = arcpy.mapping.MapDocument(r'C:\GIS\PROJECT\FrustratingArcPy.mxd') ... idxLyr = arcpy.mapping.ListLayers(mxd, 'MapBook_OCT09')[0] # The DDP index FC ... Group = arcpy.mapping.ListLayers (mxd) ... df = arcpy.mapping.ListDataFrames(mxd, 'MapBook')[0] # The Data Frame name ... pageNameField = "Page_Title" #DDP Index Field ... ... rows = arcpy.UpdateCursor(idxLyr) ... ... for row in rows: ... pageName = row.getValue(pageNameField).encode('ascii') ... pageID = mxd.dataDrivenPages.getPageIDFromName(pageName) ... mxd.dataDrivenPages.currentPageID = pageID ... if str(pageName) == str(Group): ... print str(Group) + str(" ") + str(pageName) ... else: ... print str(Group) ... del mxd, row, rows
import arcpy, os ... from arcpy.mapping import * #Brings in entire functionality of the mapping module ... mxd = arcpy.mapping.MapDocument(r'C:\GIS\PROJECT\FrustratingArcPy.mxd') ... layerlist = arcpy.mapping.ListLayers(mxd) ... for lyr in layerlist: ... if lyr.isGroupLayer: ... lyr.visible = True ... print str(lyr) ... else: ... lyr.visible = False ... arcpy.RefreshTOC() ... del mxd
import arcpy mxd = arcpy.mapping.MapDocument(r"c:\Temp\test.mxd") ddp = mxd.dataDrivenPages for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1): mxd.dataDrivenPages.currentPageID = pageNum fieldValue = mxd.dataDrivenPages.pageRow.GroupLayerName for lyr in arcpy.mapping.ListLayers(mxd): if lyr.name == fieldValue: lyr.visible = True arcpy.mapping.ExportToPDF(mxd, r"C:\\Temp\\" + fieldValue + ".pdf") lyr.visible = False del mxd
I think the following script will do what you need. Make sure to save the MXD with ALL group layers checked off (and all layers within the group layer checked on). See attached screen shot. A field was added to the index layer called "GroupLayerName". It has the values "GroupLayer1, GroupLayer2, etc). After exporting to PDF, the script then turns the group layer back off again before going to the next DDP page.... <edited>Jeff
Tracey,A couple of comments:- I don't see an mxd.save() in your code so how is it that you expect to see changes?- If you are running this from the Python window, use "CURRENT" instead of the path to the file on disk.- it would be much easier to read your code if you posted it withing tags. Its the # button. You want to preserve indents. Jeff
tags. Its the # button. You want to preserve indents. Jeff
I think the following script will do what you need. Make sure to save the MXD with ALL group layers checked off (and all layers within the group layer checked on). See attached screen shot. A field was added to the index layer called "GroupLayerName". It has the values "GroupLayer1, GroupLayer2, etc). After exporting to PDF, the script then turns the group layer back off again before going to the next DDP page. import arcpy mxd = arcpy.mapping.MapDocument(r"c:\Temp\test.mxd") ddp = mxd.dataDrivenPages for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1): mxd.dataDrivenPages.currentPageID = pageNum fieldValue = mxd.dataDrivenPages.pageRow.GroupLayerName for lyr in arcpy.mapping.ListLayers(mxd): if lyr.name == fieldValue: lyr.visible = True arcpy.mapping.ExportToPDF(mxd, r"C:\\Temp\\" + fieldValue + ".pdf") lyr.visible = False del mxd
import arcpy mxd = arcpy.mapping.MapDocument(someMXDpath) for lyr in arcpy.mapping.ListLayers(mxd): lyr.visible = False for lyr in arcpy.mapping.ListLayers(mxd): lyr.visble = True arcpy.mapping.ExportToPDF(mxd, somePDFpath) lyr.visble = False
Susan,I don't know why this is not working for you but I have never tried duplicate index features like you are. This is definately a creative way to use DDP but I don't think this is the correct approach. You are trying to create a thematic map - extent remains the same but different layers or themes are displayed for each page.The approach I would take is to not use DDP and use arcpy.mapping only. Lets say you have 14 different pages because there are 14 different images. To makes things really easy, I would order the images in the TOC the way I want them to be exported. Image 1 / Page 1 at the top, image 14 / page 14 at the bottom of the TOC.Then I would do something like: import arcpy mxd = arcpy.mapping.MapDocument(someMXDpath) for lyr in arcpy.mapping.ListLayers(mxd): lyr.visible = False for lyr in arcpy.mapping.ListLayers(mxd): lyr.visble = True arcpy.mapping.ExportToPDF(mxd, somePDFpath) lyr.visble = False The code obviously needs more logic if there are multiple data frames, sets of layers that are always visible, etcJeff
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.