I am trying to save a layer from an MXD to a lyrx file in a geodatabase using ArcGIS Pro.

mlist = aprx.listMaps()
infra_layers = mlist[0].listLayers()
arcpy.SaveToLayerFile_management(infra_layers[0].name, new_file_name, 'ABSOLUTE')

I am getting the following error:

ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Layer: Dataset active_infrastructure_projects does not exist or is not supported
Failed to execute (SaveToLayerFile).

So the name exists and the layer is being imported.

Why can't it save the layer?

  • 1
    Did you try just infra_layers[0] instead of infra_layers[0].name in the SaveToLayerFile ? – KHibma Oct 9 '19 at 18:12
  • interesting. I got this error: ExecuteError: ERROR 999999: Something unexpected caused the tool to fail. Contact Esri Technical Support (http://esriurl.com/support) to Report a Bug, and refer to the error help for potential solutions or workarounds. Failed to execute (SaveToLayerFile). Does that field take a name or a layer object? – Steve Scott Oct 9 '19 at 19:51
  • Well, if you were in the app, using the Python window, the name should work. But it looks like you’re running stand alone, thus my suggestion to use the layer object. But an arcpy mapping layer object isn’t equal to a layer object created by say a tool output. I can’t remember what times what works with what...the answer of using MFL will probably work. – KHibma Oct 10 '19 at 0:25

Make a featurelayer out of infra_layers[0] and pass that to SaveLayerFile_management():

fl = arcpy.MakeFeatureLayer_management(infra_layers[0], "fl")
arcpy.SaveToLayerFile_management(fl, new_file_name, "ABSOLUTE")
| improve this answer | |
  • That worked! Could you explain why it didn't work before? What is the difference between a layer and a feature layer? – Steve Scott Oct 10 '19 at 13:53
  • A FeatureLayer is a type of Layer. Other layer types include GroupLayer and RasterLayer. The documentation for SaveToLayerFile() says the input layer data type is Layer, so I would have guessed using the layer as-is from the map would work, but often it seems that Esri's arcpy documentation needs to be taken with a grain of salt. pro.arcgis.com/en/pro-app/arcpy/mapping/layer-class.htm – Dan Jurgella Oct 10 '19 at 16:02

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.