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.
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
>>>
Joshua Bixby this is very helpful from a diagnostic perspective. Thanks a bunch!
Joshua Bixby Dan Patterson Darren 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:
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
#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)
Thanks for the update, this is useful not just to those who commented here, but anyone in the future who finds this thread.