1

I have to export about 250 layers in one mxd File to maps in ArcGIS 10.

I found a script on this site at Exporting each layer in map to separate image using ArcPy?:

mxd = arcpy.mapping.MapDocument("CURRENT")  
df = arcpy.mapping.ListDataFrames(mxd, '')[0] # assuming there is only 1 df you're interested in

#Read input parameters from script tool
allLayers = arcpy.GetParameterAsText(0) # Must be a multivalue in script tool params
lyrList = allLayers.split(";")

PNGPath = arcpy.GetParameterAsText(1)

#Turn of all lyrs in list
for lyr in arcpy.mapping.ListLayers(mxd, '', df):
for layer in lyrList:
    if lyr.name == layer:
        lyr.visible = False
arcpy.RefreshActiveView()

# Loop through each layer, turn it on and export map as PNG
for lyr in arcpy.mapping.ListLayers(mxd, '', df):
for layer in lyrList:
    if lyr.name == layer:
        lyr.visible = True
        arcpy.RefreshActiveView() # May want to test without this -- ArcMap might export correctly without need for refresh active view
        arcpy.mapping.ExportToPNG(mxd, PNGPath+"\\" + lyr.name + ".png")
        lyr.visible = False

I never before handled Python.

I opened Geoprocessing -> Python in ArcGIS and copied the code wihtout changes. So far as I understand it nothing happened... Which part of the code do I have to change or add to make it run on my computer?

1

This script includes the following lines:

allLayers = arcpy.GetParameterAsText(0) # Must be a multivalue in script tool params
lyrList = allLayers.split(";")

PNGPath = arcpy.GetParameterAsText(1)

The arcpy.GetParameterAsText() functions are asking for two parameters from a tool dialog that you need to configure separately. They indicate that the script is designed to be run as a Python script tool.

I recommend reading up on writing and using Python script tools in the ArcGIS Online Help.

0

I'll try to expand PolyGeo's answer in order for you to understand more easily:

The script lines arcpy.GetParameterAsText() show that these code lines are normally run similarly to a tool from the ArcGIS toolbox. The script requires an "interface" where you enter the required parameters. You could substitute these lines with a path to your data, as in:

PNGPath = r'C:Path\to\your\data'

However, since the script requires a list of data as input (you want to process all layers in your .mxd...) you'd have to modify the script with additional code. So, the easiest way to get this code to work properly is to build a script tool with it. You can find help for this task here.

Additional information:

In order to create a multi variable input parameter in a script tool, activate it through the drop down menu option (see screen shot).

multivariableinput

  • Thank you very much, that already helped a lot. I managed to make the script tool. But what data typ are the two parameters? I'm lost again... – Barbara Jun 29 '16 at 11:11
  • @Barbara: Try "layer" for the first input and "workspace" for the second. Make sure you set the first input as a multi value (see my edit in the answer). You then run the script tool from your MXD, drag and drop the layers to the list of the script interface. – dru87 Jun 29 '16 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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