Tuesday 29 January 2019

arcgis 10.2 - Why is "arcpy.GetParameterAsText" deleting Target Feature Class?


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?



Answer



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.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...