Select to view content in your preferred language

Exporting Layers to PNG using Python

4495
2
Jump to solution
04-11-2014 01:13 AM
AqeelAhmed
New Contributor
Hi guys!

I'm pretty new to python and have a question about an automation i'm trying to achieve. Is it possible to export several layers to a specific file format (the module offers several) using python. For instance if i have two layers in my data frame (a point feature and a line feature) and i want to export these to PNG separately, I would normally turn off one layer and export the other. Then i would repeat the process again for the remaining layer. Hypothetically if I had 20 layers which I wanted to export this way it would be useful if I had the process automated. Is it possible to write a script that does this? I acknowledge the fact this might be comprehensive, but if it is possible then any "kickstarters" of code in the right direction would be appreciated.
Thank you:)
Tags (2)
1 Solution

Accepted Solutions
AmyKlug
Frequent Contributor
Use export to png:

http://resources.arcgis.com/en/help/main/10.1/index.html#//00s30000002s000000

this thread will help you, be sure and read the last thread:

http://forums.arcgis.com/threads/17136-Turn-layers-off-w-arcpy.mapping

You will also need to set the extent inside the loop (you will need to save and close the mxd with all layers turned off):
I have not tested this so you might have to tinker with it.

  mxd = arcpy.mapping.MapDocument(r"C:\Maps\MakeMaps.mxd") df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] #df name is "Layers" in this example for lyr in arcpy.mapping.ListLayers(mxd):     lyr.visible = True       ext = lyr.getExtent()     df.extent = ext     arcpy.mapping.ExportToPNG(mxd, r"C:\Maps\Exports\"  + lyr + ".png")

View solution in original post

0 Kudos
2 Replies
AmyKlug
Frequent Contributor
Use export to png:

http://resources.arcgis.com/en/help/main/10.1/index.html#//00s30000002s000000

this thread will help you, be sure and read the last thread:

http://forums.arcgis.com/threads/17136-Turn-layers-off-w-arcpy.mapping

You will also need to set the extent inside the loop (you will need to save and close the mxd with all layers turned off):
I have not tested this so you might have to tinker with it.

  mxd = arcpy.mapping.MapDocument(r"C:\Maps\MakeMaps.mxd") df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] #df name is "Layers" in this example for lyr in arcpy.mapping.ListLayers(mxd):     lyr.visible = True       ext = lyr.getExtent()     df.extent = ext     arcpy.mapping.ExportToPNG(mxd, r"C:\Maps\Exports\"  + lyr + ".png")
0 Kudos
AqeelAhmed
New Contributor
Use export to png:

http://resources.arcgis.com/en/help/main/10.1/index.html#//00s30000002s000000

this thread will help you, be sure and read the last thread:

http://forums.arcgis.com/threads/17136-Turn-layers-off-w-arcpy.mapping

You will also need to set the extent inside the loop (you will need to save and close the mxd with all layers turned off):
I have not tested this so you might have to tinker with it.

 
mxd = arcpy.mapping.MapDocument(r"C:\Maps\MakeMaps.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] #df name is "Layers" in this example
for lyr in arcpy.mapping.ListLayers(mxd):
    lyr.visible = True  
    ext = lyr.getExtent()
    df.extent = ext
    arcpy.mapping.ExportToPNG(mxd, r"C:\Maps\Exports\"  + lyr + ".png")


Thanks! I'll give it a run 🙂
0 Kudos