Save To Layer File (Data Management)

Summary

Creates an output layer file (.lyrx) from a map layer. The layer file stores many properties of the input layer such as symbology, labeling, and custom pop-ups.

Usage

  • In addition to map layers, this tool also accepts layers created by tools such as Make Feature Layer or Make XY Event Layer.

  • If the input layer has a selection applied to it, the output layer file will maintain this selection.

Parameters

LabelExplanationData Type
Input Layer

The map layer that will be saved to disk as a layer file.

Layer; Table View
Output Layer

The output layer file (.lyrx) that will be created.

Layer File
Store Relative Path
(Optional)

Specifies whether the output layer file will store a relative path to the source data stored on disk or an absolute path.

  • Unchecked—The output layer file will store an absolute path to the source data stored on disk. This is the default.
  • Checked—The 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
Layer Version
(Optional)

Specifies the version of the output layer file.

  • CurrentThe current version. This is the default.
Legacy:

This parameter is no longer supported. It remains only for the backward compatibility of scripts and models.

Layer files created in a particular release are supported in all minor releases of the same series. For example, a layer file saved in ArcGIS AllSource 3.1 can be used in all ArcGIS AllSource 3.x releases.

To save a layer and its properties to a different major release of ArcGIS AllSource, use the Package Layer tool.

String

arcpy.management.SaveToLayerFile(in_layer, out_layer, {is_relative_path}, {version})
NameExplanationData Type
in_layer

The map layer that will be saved to disk as a layer file.

Layer; Table View
out_layer

The output layer file (.lyrx) that will be created.

Layer File
is_relative_path
(Optional)

Specifies whether the output layer file 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)

Specifies the version of the output layer file.

Legacy:

This parameter is no longer supported. It remains only for the backward compatibility of scripts and models.

Layer files created in a particular release are supported in all minor releases of the same series. For example, a layer file saved in ArcGIS AllSource 3.1 can be used in all ArcGIS AllSource 3.x releases.

To save a layer and its properties to a different major release of ArcGIS AllSource, use the Package Layer tool.

  • CURRENTThe current version. This is the default.
String

Code sample

SaveToLayerFile example 1 (Python window)

The following Python window script demonstrates how to use the SaveToLayerFile function in immediate mode.

import arcpy
arcpy.env.workspace = "C:/data"
arcpy.management.SaveToLayerFile("studyquads.shp", "C:/output/studyquadsLyr.lyrx", "ABSOLUTE")
SaveToLayerFile example 2 (stand-alone Python script)

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

# Description: Save a layer to a file on disk

# Import system modules
import arcpy

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

# Set local variables
in_features = "study_quads.shp"
where_clause = '"NAME" = \'LA MESA\''
in_layer = "studyquadsLyr"
out_layer_file = "studyquadsLyr.lyrx"

# Run MakeFeatureLayer
arcpy.management.MakeFeatureLayer(in_features, "study_quads_lyr", where_clause)

# Run SaveToLayerFile
arcpy.management.SaveToLayerFile("study_quads_lyr", out_layer_file, "ABSOLUTE")