arcpy.SaveToLayerFile_Management 999999 Error

1712
13
01-17-2019 06:53 AM
ZacharyHart
Occasional Contributor III

I'm seeing some different behavior here in ArcGIS Pro.

In this particular case I'm using

arcpy.SaveToLayerFile_management(in_layer,out_layer)

[Curiously, this works in the python command window but fails in a script tool].

When I try

arcpy.management.SaveToLayerFile(in_layer, out_layer)

in the python window with the same parameters the tool fails with an 000622 error. I tried to supply the other optional parameters but it still failed.

0 Kudos
13 Replies
JoshuaBixby
MVP Esteemed Contributor

I'm still curious what the difference between arcpy.mangement.{tool} vs arcpy.{tool}_management

Both point back to the same compiled code.  There should not be a difference in how they handle the inputs.  If there is a difference, it is likely a bug.

>>> import arcpy
>>> 
>>> # both reference same memory location
>>> arcpy.SaveToLayerFile_management
<function SaveToLayerFile at 0x7f9237a9bb70>
>>> arcpy.management.SaveToLayerFile
<function SaveToLayerFile at 0x7f9237a9bb70>
>>> 
>>> # so both have same Python id
>>> id(arcpy.SaveToLayerFile_management)
140265975823216
>>> id(arcpy.management.SaveToLayerFile)
140265975823216
>>> 
ZacharyHart
Occasional Contributor III

Joshua Bixby‌ this is very helpful from a diagnostic perspective. Thanks a bunch!

0 Kudos
ZacharyHart
Occasional Contributor III

Joshua BixbyDan PattersonDarren Wiens

Hi everyone, I wanted to thank you for your help and also give you a bit of an update. Here's what I know to date:

  • Today Esri Support verified there was a bug for this tool.

    BUG ID: BUG-000117445
    Synopsis: The Save To Layer File management tool fails and returns Error 999999 when run from the Python IDLE window in ArcGIS Pro.
    Status: New

  • We confirmed that this tool also fails when used in a script tool
  • The current ArcGIS Pro documentation is still outdated and referencing working with .lyr files.
  • I was able to find a workaround using 'saveACopy' as part of the arcpy mapping module layer class.
  • Here is a quick example:
#Import Modules
import arcpy, os

#Variables
Date = time.strftime("%m%d%Y")
OutputFolder = "D:\\TEMP"
LayerName = "SoilsMUID_" + Date + ".lyrx"
ExportLayer = os.path.join(OutputFolder, LayerName)

#Setup Map Document Info
aprx = arcpy.mp.ArcGISProject("Path to your aprx file")
map = aprx.listMaps("Soils")[0]
SoilsLyr = map.listLayers('SoilsMUID')[0] ##This layer's data source is a shapefile

#Export Layer File
arcpy.AddMessage("Exporting Layer File to {0}".format(ExportLayer))
SoilsLyr.saveACopy(ExportLayer)
JoshuaBixby
MVP Esteemed Contributor

Thanks for the update, this is useful not just to those who commented here, but anyone in the future who finds this thread. 

0 Kudos