1

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?

2
  • Could you post screenshots of modelbuilder? How familiar are you with python? I think what you're looking for is an iterator. You can definitely accomplish this in model builder and/or python
    – GISHuman
    Commented Jun 26, 2014 at 15:44
  • I know very little about python, I read through the arcpy.mapping module and I only know how to deal with individual datafram, edit its properties and turnning and exporting it to only 1 pdf, I barely know how to manipulate the presents and visibility of multiple layers in the dataframe.
    – user32885
    Commented Jun 26, 2014 at 16:54

1 Answer 1

1

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)
3
  • Firstly, thank you so much, these codes worked perfectly. However, is there anyway to maintain the name of the PDF files same as each layer's name? In that enumerate function part, am I able to change the function to assign the i value exactly the same name such as 11_A, 11_B..etc.?
    – user32885
    Commented Jun 26, 2014 at 21:26
  • Sure. Replace the line: arcpy.mapping.ExportToPDF(mxd, r"d:\temp\2\print_%i.pdf" % i) with: arcpy.mapping.ExportToPDF(mxd, r"d:\temp\2\%s.pdf" % lyr.name)
    – Matej
    Commented Jun 27, 2014 at 12:59
  • Any chance that this can be updated? I'm getting Attribute Error: module 'arcpy' has no attribute 'mapping'. Thanks.
    – Bowen Liu
    Commented Dec 17, 2018 at 20:04

Your Answer

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

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