[GIS] Exporting set of layers into multiple PDF (or Adobe Illustrator) files, one at a time

arcgis-desktopexportmodelbuilderpython

I am completely NEW to PYTHON(only took a 3-hr entry course in ESRI tutorial. I have a dataset contains files named as "1_A, 1_B, 1_C….12_A,12_B, 12_c,….200_A, 200_B, 200_C..etc." I need to export each feature layer, one at a time , to a PDF or AI file through a COMPLETELY AUTOMATED process.

I tried to use Addlayer and Removelayer tool in Model Builder but they all run for one single feature layer once at a time. I coudl not connect the add and remove process to each other, nor could I connect the process through Iterator to the script tool anyway.

This means although I use model builder or write python script, I have to change the layers (or the name of layers) hundreds of times and save every layer into a new MXD file and export then to pdfs.

I was thinking about turning on one of the layers at a time, export a .ai file with that layer visible, then turn that layer off and move on to the next layer in the list. I'm wondering if you have any suggestion about building the model or the scripts?

Pic1: I know I can iterate feature classes, but the exporting PDF only work with .mxd files, How can I save each shapefile into different mxd through iterator, before I export them to pdfs? will the export pdfs works in batch process for multiple mxd files?

Best Answer

Try something like this:

import arcpy

def turn_off_layers(mxd, df):
    for lyr in arcpy.mapping.ListLayers(mxd, "", df):
         lyr.visible = False
    mxd.save()

def print_layers(mxd,df):
    for i,lyr in enumerate(arcpy.mapping.ListLayers(mxd, "", df)):
         lyr.visible = True
         mxd.save()
         arcpy.mapping.ExportToPDF(mxd, r"d:\temp\2\print_%i.pdf" % i)
         lyr.visible = False
         mxd.save()

if __name__ == "__main__":
    mxd = arcpy.mapping.MapDocument(r"d:\temp\2\print.mxd")
    df = arcpy.mapping.ListDataFrames(mxd, "")[0]
    turn_off_layers(mxd, df)
    print_layers(mxd,df)
Related Question