Save To Layer File (Data Management)

Summary

Creates an output layer file (.lyr) that references geographic data stored on disk.

Usage

Syntax

SaveToLayerFile_management (in_layer, out_layer, {is_relative_path})
ParameterExplanationData Type
in_layer

The in-memory layer, layer file stored on disk, or feature layer in ArcMap to be saved to disk as a layer file (.lyr).

Layer
out_layer

The output layer file (.lyr) to be created.

Layer File
is_relative_path
(Optional)

Determines if the output layer file (.lyr) will store a relative path to the source data stored on disk, or an absolute path.

  • ABSOLUTEThe output layer file will store an absolute path to the source data stored on disk. This is the default.
  • RELATIVEThe output layer file will store a relative path to the source data stored on disk. If the output layer file is moved, its source path will update to where the source data should be in relation to the new path.
Boolean

Code Sample

SaveToLayerFile Example (Python Window)

The following Python Window script demonstrates how to use the SaveToLayerFile tool in immediate mode.

import arcpy
arcpy.env.workspace = "C:/data"
arcpy.SaveToLayerFile_management("studyquadsLyr", "C:/output/studyquadsLyr.lyr", "ABSOLUTE")
SaveToLayerFile Example (stand-alone Python script)

The following Python script demonstrates how to use the SaveToLayerFile tool in a stand-alone script.

# Name: SaveToLayerFile_Example2.py
# Description: Saves an inMemory layer to a file on disk
# Author: ESRI

# Import system modules
import arcpy
from arcpy import env

# Set workspace
env.workspace = "C:/data"

# Set local variables
in_layer = "studyquadsLyr"
out_layer = "studyquadsLyr.lyr"

#MakeFeatureLayer variables
in_features = "study_quads.shp"
out_layer0 = "studyquadsLyr"
where_clause = '"NAME" = 'LA MESA''
workspace = "C:/output"

try:
    # Execute MakeFeatureLayer
    arcpy.MakeFeatureLayer_management(in_features, out_layer0, where_clause, workspace)

    # Execute SaveToLayerFile
    arcpy.SaveToLayerFile_management(in_layer, out_layer, "ABSOLUTE")
except:
    print arcpy.GetMessages()

Environments

Related Topics

Licensing Information

ArcView: Yes
ArcEditor: Yes
ArcInfo: Yes

10/27/2014