I was looking for a work-around for a problem I am having with regards to a script I am developing. At the moment, I create a temp file, from which I perform the various geoprocessing tasks. This works out fine, until I have to restart the process.
This temp file needs to be deleted, so that if a user wishes to run the script at a new location they can. In ArcMap 9.3 and VBA I was able to use the "Kill("C:\test.*")" which would then delete all trace of that file so that everything could run again, without the fear of something being overwritten and causing an error.
In ArcMap 10 and in VB.Net, there is a LOCK file which prevents this shapefile from being deleted - even if it is removed from the active ArcMap session. Now I do not want to have to shut down and restart ArcMap for each iteration of this script. Is there a way to stop the LOCK file from being generated, or is there a way to release the file from the cache?
I assume you are creating a "temp" by using MakeFeautreLayer or MakeTableView. In 10.x, you often have to delete that "temp" before the next iteration by using Delete_managment() or you'll get a lock error.
As you could possibly tell, your suggention worked.
I created the add-in and it worked great with regards to deleting the temp file on each iteration. I have since moved onto my next project - almost identical - and I am getting into the same problem.
I am using the "GP.Execute("delete_management", parameters, Nothing)" to delete the temp file that was generated on the first iteration. This removes all trace (except for two LOCK files?). When i then try and intersect the temp file with another, it bombs Arcmap and I have to re-open the mxd and load the add-in.
Obviously once Arcmap crashes the LOCK is gone and the script can be re-run, this is not acceptable. Is there any other solution to this problem?
Just to answer my own question, there is a way to allow a geoprocessor to overwrite a file, this can be done by adding
GP.OverwriteOutput = True
When bringing in the geoprocessor.
But, for me the problem was with the intersect, I was using a Basic Geoprocessor. I am new to this, so I am unsure as to why a Geoprocessing tool can overwrite files, but a Basic Geoprocessing tool cannot.
So, using a method I found here: http://forums.esri.com/Thread.asp?c=93&f=993&t=218041 I created a temp directory in the working directory, then for each time the tool is run, I create a new shp with the iteration as the new name, I then copy the file from the temp directory to the directory it needs to be in and then carry on with the rest of the processes that need to run. Once that is completed I delete the temp files and release all the GP and BGPs.