Save To Layer File (Data Management)

License Level:BasicStandardAdvanced

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}, {version})
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
version
(Optional)

The version of layer file the output will be saved as. The default is CURRENT.

  • CURRENT
  • 10.1
  • 10
  • 9.3
  • 9.2
  • 9.1
  • 9.0
  • 8.3
String

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

ArcGIS for Desktop Basic: Yes
ArcGIS for Desktop Standard: Yes
ArcGIS for Desktop Advanced: Yes
5/7/2015