Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save FurnasAZ/efdcdf9eb9505919d250ae33522afa40 to your computer and use it in GitHub Desktop.
Save FurnasAZ/efdcdf9eb9505919d250ae33522afa40 to your computer and use it in GitHub Desktop.

Revisions

  1. @TheBryanMac TheBryanMac created this gist Oct 30, 2017.
    22 changes: 22 additions & 0 deletions ArcMapLayersToLYRFiles.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    #Name: ArcMap Layers to LYR Files with Python
    #Author: Bryan McIntosh
    #Description: Iterate through an ArcMap MXD, and export all layers to LYR files.

    import arcpy, os
    #Set the working directory to where the Python file is stored
    cwd = os.getcwd()
    #Set the location of the MXD file
    mxdPath = os.path.join(cwd,"MyMap.mxd")
    #Set the location to store LYR files
    layersOutPath = os.path.join(cwd,"export")

    #Get the MXD and layers
    mxd = arcpy.mapping.MapDocument(mxdPath)
    layers = arcpy.mapping.ListLayers(mxd)
    for layer in layers:
    if str(layer.name) == str(layer.longName):
    tempOutName = str(layer.name).replace("/","-")
    tempOutName = str(tempOutName).replace(":","-")
    fn = os.path.join(layersOutPath, str(tempOutName) + ".lyr")
    layer.saveACopy(fn)
    print "LYR Extraction Complete"