Problem in SaveToLayerFile_management

2998
2
10-14-2014 02:40 AM
H_A_D_Padmasiri
New Contributor

Dear sir!

 

When I tried to create a .lyr file, The following error message come. I cant understand what's wrong with my script.

Please help me to solve it.

import arcpy

from arcpy import env

env.workspace = r"J:\Gampaha\51027202\CM51027202.gdb\CM51027202"

arcpy.MakeFeatureLayer_management("PCL_PG", "ASD")

arcpy.SaveToLayerFile_management("ASD", "AMD.lyr", "ABSOLUTE")

 

Traceback (most recent call last):

  File "<pyshell#10>", line 1, in <module>

    arcpy.SaveToLayerFile_management("ASD", "AMD.lyr", "ABSOLUTE")

  File "C:\Program Files\ArcGIS\Desktop10.2\arcpy\arcpy\management.py", line 6640, in SaveToLayerFile

    raise e

ExecuteError: ERROR 999999: Error executing function.

Failed to execute (SaveToLayerFile).

 

Thanks

 

Padmasiri

Tags (1)
0 Kudos
2 Replies
IanMurray
Frequent Contributor

I think your issue is that you are trying to save the .lyr files to a geodatabase, someone correct me if I'm wrong, but I don't think you can save .lyr files to a gdb.  You will need to save the layer files to a different workspace.

0 Kudos
H_A_D_Padmasiri
New Contributor

Dear Sir

Thanks to reply me.

I can understand what you said. In generally .lyr file cannot save within a geodatabase. it can be save in a folder.

Then I tried this way.

import arcpy

from arcpy import env

env.workspace = r"J:\Gampaha\51027202\CM51027202.gdb\CM51027202"

workspace = os.path.dirname(env.workspace)

arcpy.MakeFeatureLayer_management("PCL_PG", "ASD", "", workspace)

arcpy.SaveToLayerFile_management("ASD", "AMD.lyr", "ABSOLUTE")

Same error occurred.

Thanks

Padmasiri

0 Kudos