Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Using python, how can one save all layers in the Arcmap (v10) table of contents pane to layer files on disk?

share|improve this question
1  
The arcpy.mapping module documentation should have examples on how to do this. –  blah238 Nov 3 '11 at 0:53
    
Hello I'm trying to do the same thing but I have and error with layer from server, how can I pick only .shp files in my mxd? Thanks a lot Luca –  Luca Moiana Jun 14 '12 at 14:07
    
Hi @Luca, I'm not sure. The exact error message would be likely useful in figuring that out. Might be worth posting as a separate question? –  matt wilkie Jun 14 '12 at 16:16
add comment

1 Answer

up vote 4 down vote accepted

Untested since I'm not in front of ArcGIS at the moment, but you should be able to use the Layer.saveACopy(path) method. For example:

import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
for lyr in arcpy.mapping.ListLayers(mxd):
    lyr.saveACopy(lyr.name + ".lyr")
share|improve this answer
1  
that works, thank you! Two caveats: env.workspace is ignored, the layer files are saved in the same folder as the .mxd, and group layers are ignored (though their contents are still saved, individually) –  matt wilkie Nov 3 '11 at 21:14
    
glad to hear it! Strange that it doesn't export group layers though. –  om_henners Nov 6 '11 at 4:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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