# Running Python script that includes ArcPy functions?

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?

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'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.