Error when using arcpy.SaveToLayerFile_management in 10.4

3208
9
Jump to solution
03-01-2016 10:24 AM
MarcoBoeringa
MVP Regular Contributor

Hi all,

I just today upgraded from 10.3.1 to 10.4. Now all of a sudden, arcpy.SaveToLayerFile_management in one of my vital scripts, throws an arcpy.ExecuteError. I can catch the error with  a "try... except arcpy.ExecuteError:" block, but using print(arcpy.GetMessages(2)) in the except doesn't return a thing. There is no message, the tool just fails.

Anyone else who has problems with arcpy.SaveToLayerFile after upgrading?

Marco

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
MarcoBoeringa
MVP Regular Contributor

I should have known... The typical "not enough sleep / overlook the obvious". The 10.4.x install reset the geoprocessing environment, and of course, although I did adjust quite a lot after the install, including a look at the geoprocessing options, I did not check the "Overwrite the output of geoprocessing operations". Since I am currently mainly tied up in the middle of coding, and hardly use the tools directly, I was to much focused on some coding / bug issue, instead of the obvious. What didn't help either, is that I wasn't getting back any error message in the progress dialog. Instead of having an arcpy.ExecuteError thrown without any useful error message, it would have been kind of helpful had the tool returned a warning about the impossibility to overwrite existing data due to geoprocessing environment settings (note that I construct the output filename programmatically, so there is no parameter capable of giving of a direct warning for existing data on the tool).

View solution in original post

0 Kudos
9 Replies
MarcoBoeringa
MVP Regular Contributor

I have decided to re-install and downgrade to 10.3.1. Now my tools run fine again. It may be that the 10.4 installation somewhere failed, or something else caused the issue, but for now I will stick with 10.3.1 as I don't have the time to look into this further. I noticed at least one other issue as well, that the familiar "scripts" and "tools" icons were not displaying as well in models, so an install fail may actually be likely (although I was able to run tools). Anyway, once 10.4.1 or so is out, I may revisit this and try re-installing 10.4.

MarcoBoeringa
MVP Regular Contributor

Now upgraded to 10.4.1, as it became available, and I am running in the same issue, this is really frustrating.

Anyone else having issues with this?~!

0 Kudos
MarcoBoeringa
MVP Regular Contributor

I have solved it by switching to the lyr.saveACopy() method of a layer. I still think this is a bug introduced in the 10.4.x line of ArcGIS for Desktop. The arcpy.SaveToLayerFile_management tool should be callable from arcpy, and worked without issue prior to 10.4.x.

0 Kudos
MarcoBoeringa
MVP Regular Contributor

;-( My 'solution' breaks the ability to save a layer file with relative paths, as is possible with the arcpy.SaveToLayerFile_management tool. I need this... The lyr.save() and lyr.saveACopy() methods seem to completely ignore current map document settings for relative or absolute paths.

0 Kudos
DanPatterson_Retired
MVP Emeritus

You should report it so that it can be verified.  There is nothing on the past and current bug lists indicating that this is an issue.  http://downloads.esri.com/support/downloads/other_/1041-IssuesAddressedList.pdf

0 Kudos
MarcoBoeringa
MVP Regular Contributor

Hi Dan,

Well, I am even more baffled as to what is going on. The code definitely worked in 10.3.x and below. But now, I am even more confused, because when I attempt to run the arcpy.SaveToLayerFile_management tool directly by either opening the tool from ArcToolbox, or by typing the command in the Python window of ArcMap, it just works... no issue at all!

I have no clue why the same code, without making any changes at all but only upgrading ArcGIS from 10.3.1 to 10.4.1 (I also previously tried 10.4 as you noted in the older post), makes the code go bust upon running it in the new version.

I have attempted many things by now, and verified the objects / variables going into the command, but don't see anything wrong up to now.

0 Kudos
DanPatterson_Retired
MVP Emeritus

I don't know either Marco, sometimes 'issues' just seem to vanish as you can tell from the list I sent there is absolutely no mention of anything related to your problem.  I still think it would be worth a note to them with your code so that they can at least acknowledge the issue because, invariably in the future, this may rise again when someone is mid-version.  Good luck

0 Kudos
MarcoBoeringa
MVP Regular Contributor

I should have known... The typical "not enough sleep / overlook the obvious". The 10.4.x install reset the geoprocessing environment, and of course, although I did adjust quite a lot after the install, including a look at the geoprocessing options, I did not check the "Overwrite the output of geoprocessing operations". Since I am currently mainly tied up in the middle of coding, and hardly use the tools directly, I was to much focused on some coding / bug issue, instead of the obvious. What didn't help either, is that I wasn't getting back any error message in the progress dialog. Instead of having an arcpy.ExecuteError thrown without any useful error message, it would have been kind of helpful had the tool returned a warning about the impossibility to overwrite existing data due to geoprocessing environment settings (note that I construct the output filename programmatically, so there is no parameter capable of giving of a direct warning for existing data on the tool).

0 Kudos
DanPatterson_Retired
MVP Emeritus

Go rest ...

image.png

0 Kudos