I want to create a layer file from a shapefile.

When I do...

arcpy.SaveToLayerFile_management('123.0_NYC_PARKS',value+"_"+"NYC_PARKS.lyr", "ABSOLUTE")

it works because I have this file opened in the table of contents, but when I do

arcpy.SaveToLayerFile_management("C:/ArcGIS/Projects/Value/"+value+"/"+value+"_"+NYCPARKS", value+ "_NYC_PARKS.lyr", "ABSOLUTE")

I get told that the file does not exist

ERROR 000732: Input Layer: Dataset C:/ArcGIS/Projects/Value/123.0/123.0_NYCPARKS does not exist or is not supported Failed to execute (SaveToLayerFile).


Because the function is expecting a Layer object not a Layer File as the first parameter.

From the documentation:


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



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 (.lyr) to be created.         Layer File

If you want to copy an existing Layer File, use the arcpy.Copy_management method.

arcpy.Copy_management(in_layer_file_path, out_layer_file_path)

If you want to create a layer file from a feature class, you need to create a Layer first.

feature_class = "C:/path/to/shapefile.shp"
layer_file = "C:/path/to/shapefile.lyr"
arcpy.SaveToLayerFile_management("new_lyr", layer_file, "ABSOLUTE")
  • Though i was able to create a file, when i try to add it onto the map I get "the selected layer file is not valid" – user35131 Jun 11 '20 at 2:31
  • So i did arcpy.Copy_management(Parks, value+"_NYC_PARKS.lyr") then the .lyr file showed up in file path. However when I wanted to move it over to the map from catalog i got that message. – user35131 Jun 11 '20 at 3:07
  • What is "Parks"? Layer or Layer File? – user2856 Jun 11 '20 at 3:30
  • "Parks" is a shape file. I want to create a layer file out of a shapefile. – user35131 Jun 11 '20 at 3:37
  • That won't work, you'll copy the shapefile to a new shapefile. Suggest you edit your question to say exactly what you're trying to achieve. – user2856 Jun 11 '20 at 3:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.