Select to view content in your preferred language

Problem in SaveToLayerFile_management

3097
2
10-14-2014 02:40 AM
H_A_D_Padmasiri
Deactivated User

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
Honored 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
Deactivated User

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