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. Layer files saved from ArcGIS Pro cannot be used in ArcMap.
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.
Syntax
arcpy.management.SaveToLayerFile(in_layer, out_layer, {is_relative_path}, {version})
Parameter | Explanation | Data Type |
in_layer | The map layer to be saved to disk as a layer file. | Layer |
out_layer |
The output layer file (.lyrx) to be created. | Layer File |
is_relative_path (Optional) | Determines if the output layer file will store a relative path to the source data stored on disk, or an absolute path.
| Boolean |
version (Optional) | The version of the output layer file.
| String |
Code sample
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("studyquads.shp", "C:/output/studyquadsLyr.lyr", "ABSOLUTE")
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
# 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.lyr"
# Execute MakeFeatureLayer
arcpy.MakeFeatureLayer_management(in_features, "study_quads_lyr", where_clause)
# Execute SaveToLayerFile
arcpy.SaveToLayerFile_management("study_quads_lyr", out_layer_file, "ABSOLUTE")
Environments
Licensing information
- Basic: Yes
- Standard: Yes
- Advanced: Yes