2

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?

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked May 21, 2018 at 22:17
6
  • 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? Commented May 21, 2018 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. Commented May 21, 2018 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. Commented May 21, 2018 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. Commented May 21, 2018 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. Commented May 22, 2018 at 0:38

1 Answer 1

4

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.

answered May 22, 2018 at 22:24
2
  • 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. Commented 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. Commented May 24, 2018 at 22:29

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.