SaveToLayerFile_management accepts only features save on disk

780
2
06-06-2013 03:20 AM
RanaMahmoud
New Contributor II
I'm trying to use SaveToLayerFile_management to save layers (in an mxd) pointing to features in the server "Internet", but it doesn't work

When I use ArcToolbox (SaveToLayerFile) it doesn't work neither. However, I can save it manually by right-clocking on the feature and save it as...

Is there a Python command that allowes me to save such layers? If it's not possible, how can I skip those layers and save the rest of the layers in the mxd file?

This is my code:
    for lyr in lyrs:
        l_name = lyr.longName
        layer_name = l_name.replace("_"," ")
        layer_name = layer_name.replace("\\","_")
        arcpy.SaveToLayerFile_management(lyr,ws + '\\' + layer_name + '.lyr', "RELATIVE")
Thank you
Tags (2)
0 Kudos
2 Replies
JimCousins
MVP Regular Contributor
use the Try...Except
Code will enter the try block and attempt to execute. If an error occurs, the try block execution is stopped, and transferred to the exception block. The exception can be coded to simply move on to the next item in the list if you wish.
Regards,
Jim
0 Kudos
RanaMahmoud
New Contributor II
Thank you Jim, that should do it...
0 Kudos