python code for "export map"

597
2
12-09-2013 02:25 AM
ElaineKuo
Occasional Contributor
Dear all,

System: Windows Vista
ArcGIS 9.3 Workstation
Python 2.5

I want to know any python code for ???Export Map??? (under file tab) to TIF in ArcMap.
I want to save time for doing it for 100 shape files.
Thank you.

Elaine
Tags (2)
0 Kudos
2 Replies
JoshuaChisholm
Occasional Contributor III
Hello Elaine,

I'm not sure if this will work in 9.3, but this script works for me (10.1).

The script will zoom to the given layers (using the targetLayers variable) then export them to TIF files.

import arcpy

mxd=arcpy.mapping.MapDocument("C:\\Path\\To\\Your\\Map.mxd") #path to your MXD

targetLayers=["Alberta","Ontario","Nova Scotia"] #Layer names as they appear in TOC

df=arcpy.mapping.ListDataFrames(mxd)[0] #if you are not using the first dataframe in the MXD, change '0' to the 0-based index of whichever dataframe use wish to use

allLayers=arcpy.mapping.ListLayers(df)

for targetLayer in targetLayers:
    for lyr in allLayers:
        if targetLayer==lyr.name:
            #Zoom to layer:
            ext=lyr.getExtent()
            df.extent=ext
            #Export TIF:
            arcpy.mapping.ExportToTIFF(mxd, "C:\\Path\\To\\TIFs\\"+targetLayer+".tif") #path to desired location and filename of TIF file

del mxd
del allLayers
del lyr #this line will error if you supply an empty MXD

print "Completed Successfully!"


Let me know if it gives you any trouble or you need anything different.

Good luck!!
~Josh
0 Kudos
TimBarnes
Occasional Contributor III
Arcpy.Mapping was only introduced at version 10.? so it wont work under the older geoprocessor. I think that before arcpy.mapping was around you needed to do it in a VBA macro- Perhaps the old arcscripts may have something?
0 Kudos