Select to view content in your preferred language

Python ate my work - it was supposed to deliver me a text file!

1419
2
11-04-2011 10:46 AM
by Anonymous User
Not applicable
Original User: timothieb

Yes I'm a beginner Python user.

I created more or less my first script tool which simply outputs a text file describing a feature class (name, shapetype, feature count, field names, field alias, field data type and length and domain name if used).

The script was working but I discovered it was not using the output provided by the user, instead it was placing it in the same folder where the script was located (in my tests I was selecting this same location so didn't realize it was not obeying my orders until, on a whim, I changed the output location!)

In an attempt to remedy this I tried a few things - eventually a colleague pointed out that I was not actually adding the output path to the text file.

However one of the things I tried before this was to change a property of my script tool. Under the parameters tab I changed the Direction property to be 'output' instead of 'input'. When I ran the tool I got a little yellow error triangle and a message telling me that the location already existed. Of course it exists, I thought, it's an existing folder where I want the text file to be created. So I ignored the error, ran the tool, and it deleted the whole folder which had a ton of other stuff and really upset me! I was a little surprised that ArcGIS Toolbox/ Python would let me do this to myself!

Anyway I added the pathname to the output textfile, changed the parameter direction back to input and everything is working happily ....except I am a little afraid to press the buttons now!

Can anyone enlighten me as to what happened?

I have attached my scripts - in case anyone want to take a peek. Apart from the pathname issue the other small change is that originally I was taking the user input to set the workspace environment. Now I am just taking the user input as a folder path and not setting the workspace environment at all. Don't know if this has any relevance - I am assuming not?

Finally if anyone has any suggestions to improve my script I'd be happy to hear them.
0 Kudos
2 Replies
LoganPugh
Frequent Contributor
I think this is a by-design (a bad design IMO) "feature" of "Output" parameters -- if the output already exists, the geoprocessing framework automatically deletes it (if you have the "overwrite outputs" option enabled). It does this before the script even runs, so you have no control over the actual deletion of existing outputs. The answer is to not use Output parameters for what are really Input parameters. You are inputting a location used by your script as an argument. The actual output is some text file, not a folder path.
0 Kudos
by Anonymous User
Not applicable
Original User: timothieb

aahh I see this option in ArcMap> Geoprocessing>Geoprocessing Options!

So it was some combination of...
1. the 'overwrite output' setting
2. an erroneous reference to the text file location in my script
3. and the tool parameter property 'direction' which I set to 'output'
...that caused it to blow up and wipe out a whole folder. Scary.

The folder was restored for me within hours so I guess I am over it and ready for my next misadventure...

Thanks for responding Logan.
0 Kudos