Originally I asked Why is this Python Script (using XYTabletoPoint) Deleting the target Feature Class?, but have since narrowed down the line that is deleting my target Feature Class.
Surprisingly, it turned out to be "arcpy.GetParameterAsText()".
To prove it to myself I changed the script file in the Source tab of the Tool Parameters Window to the following simplified script:
import arcpy
Target_FC = arcpy.GetParameterAsText(1)
Yes really, that's my entire script (for demonstration purposes of course).
After it runs I check the location of the Target Feature Class and sure enough it is gone.
Any ideas?
1 Answer 1
It seems that if a feature class data type parameter defined as output:
And also the output feature class already exists then the script processor from the toolbox deletes the output feature class before the script begins running.. I have tested this in ArcGIS 10.2.2 by putting a sys.exit(0)
immediately after the parameter code:
InFolder = sys.argv[1]
OutShp = sys.argv[2]
Rounding = sys.argv[3]
sys.exit(0) # Note that this is the script that matches the image
Then running the tool from ArcCatalog toolbox and (to my surprise) the nominated existing shapefile was removed.. this could be a real gotcha, if the user has specified an parameter as output intending to append or modify they may be quite upset that the tool deletes what is already in there before their code is reached.
-
1It deletes it before the script even starts. You don't have to have any
sys.argv
orGetParameter
line for the file to be deleted. And this is true of any output file, not just feature classes.Tom– Tom2018年05月24日 14:56:58 +00:00Commented May 24, 2018 at 14:56 -
That would tend to indicate that the removal is being performed by the toolbox @Tom before even importing. This is not the behavior of scripts run in CMD... worth knowing though.Michael Stimson– Michael Stimson2018年05月24日 22:29:05 +00:00Commented May 24, 2018 at 22:29
Explore related questions
See similar questions with these tags.
pass
. That's it; four characters. I surmise that when you set an output parameter, Arc tools go ahead and delete any existing files at that location, and the only way around it is to set it as an input parameter instead. Script validation won't save you either, unless you replace the path of an existing file with some other path, but that's probably not what you want either.import time
andtime.sleep(10000)
. During that pause, you'll see that the file is already gone.