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?

  • 3
    Is your model parameter an output parameter? if so the processor is likely to be removing the feature class ready to make a new one with the same name. Do you have a custom script validator? if so, what's in that? – Michael Stimson May 21 '18 at 22:20
  • Watch out. I had a nearly identical question deleted about a year ago, because people insisted that my script must have been doing something. My entire script was literally 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. – Tom May 21 '18 at 22:26
  • I should clarify that your script isn't deleting the file; when you press OK on the tool, that's when the deletion takes place. You can verify this by starting off the script with import time and time.sleep(10000). During that pause, you'll see that the file is already gone. – Tom May 21 '18 at 22:33
  • @MichaelStimson - The problem was indeed that it was set as an output parameter. I assumed that since my original script was converting a CSV into a FC, then the "Target_FC" would be a new product, and that by definition that should be "Output". Thanks all. – Waterman May 21 '18 at 22:41
  • @MichaelStimson I think it'd be worth adding a short answer around your comment above that @ Waterman had already instated was the answer to this problem. – Midavalo May 22 '18 at 0:38

It seems that if a feature class data type parameter defined as output:

enter image description here

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.

  • 1
    It deletes it before the script even starts. You don't have to have any sys.argv or GetParameter line for the file to be deleted. And this is true of any output file, not just feature classes. – Tom May 24 '18 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 May 24 '18 at 22:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.