UrbisMelbourne

ArcPy script works in script window, but fails as a script tool due to locks

Discussion created by UrbisMelbourne on Jun 4, 2012
Latest reply on Jun 6, 2012 by mzcoyle
This one's got me stumped - there are lots of instances out there of people having issues with locks, but I couldn't find a solution for the specific problem I'm having.

ArcMap 10.0.

I've got a Python script which does a number of things, writing temporary shapefiles and layers to C:\TEMP\ before eventually outputting a shapefile to a user-specified directory.  It works perfectly if I paste it into the Python window within ArcMap, except of course there's no provision for the user to specify their output folder. 

The problem is that it throws up "exclusive schema lock" errors when I set it up as a script tool (so the output folder can be passed in as a parameter), and try to run it from a toolbox.  If I clean up the C:\TEMP directory and run it, it falls over when trying to do a "arcpy.AddXY_management" to a shapefile which has just been copied into C:\TEMP.  If I then run it again without cleaning out C:\TEMP, it hits the same error even sooner, on the very first shapefile it tries to copy into C:\TEMP (which already exists in C:\TEMP.)

One think I've noticed is that when running it through the Python window (successfully), it adds each of these shapefiles to the table of contents as it goes.  It doesn't seem to be doing this when I run it as a script tool, although the shapefiles are definitely being created.

Any ideas?

Outcomes