Save To Layer File "Dataset does not exist or is not supported" error

775
3
03-08-2012 08:45 AM
CalvinGordon
New Contributor
I'm fairly new to python and arcpy. I'm picking it up quickly, but I've hit a wall on a script I'm working on. Here's the issue:

I'm trying to write a script to loop through each record in a feature class, export each record as a layer, save the layer as a layer file (so I can symbolize it), and then symbolize it.

I've got this working fine in my "test" mode (without using variables); however, when I add variables to act as parameters for the tools I'm using, I run into a problem. Specifically, it's the SaveToLayerFile_management() tool that's giving me this error:

...[previous code, see attachment for full code]...
arcpy.MakeFeatureLayer_management(srcFeature, inLayer, whereClause) #creates the layer based on crop type
arcpy.SaveToLayerFile_management("\"" + inLayer + "\"", "\"" + inLayer + "_layer\"") #should save the layer as croptype_layer. Syntax is fine as far as I can tell.
Runtime error <class 'arcgisscripting.ExecuteError'>: ERROR 000732: Input Layer: Dataset "Corn" does not exist or is not supported

"Corn" does exist! When I enter this into the python window...
arcpy.SaveToLayerFile_management("Corn", "Corn_layer")
...it recognizes "Corn" and runs it fine.

Any help would be very much appreciated. This is driving me crazy!

-Cal

p.s. I'm running this code in the Python Window in ArcMap 10, if that matters.
Tags (2)
0 Kudos
3 Replies
CalvinGordon
New Contributor
Turns out it was a syntax problem. I had the following:

        arcpy.SaveToLayerFile_management("\"" + inLayer + "\"", "\"" + inLayer + "_layer\"")

...but this turned out to be correct:

        arcpy.SaveToLayerFile_management(inLayer, inLayer) #Left off the '_layer' at the end

Much simpler, no?

-Cal
0 Kudos
MathewCoyle
Frequent Contributor
You don't need any of those quotes except around the "_layer". The below is all you need as long as your workspace is set.
arcpy.SaveToLayerFile_management(inLayer, inLayer + "_layer")
0 Kudos
AndrewChapkowski
Esri Regular Contributor
In you SaveToLayerFile(), you do not specify an output directory:
arcpy.SaveToLayerFile_management("\"" + inLayer + "\"", "\"" + inLayer + "_layer\"")

Try the following:
arcpy.SaveToLayerFile_management(inLayer, "C:/output/studyquadsLyr.lyr", "ABSOLUTE")


That might fix your issue.
0 Kudos