Problem - LOCK Files - Scripting

700
7
07-05-2011 04:24 AM
KeaganAllan
New Contributor III
Hi all,

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?

Thanks for your help!

K
0 Kudos
7 Replies
RDHarles
Occasional Contributor
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.
0 Kudos
KeaganAllan
New Contributor III
Thanks for your reply.

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?

Thanks,
K
0 Kudos
RDHarles
Occasional Contributor
Instead of deleting it, you could overwrite it each time putting this at the top of your script:

arcpy.overwriteOutput = True
0 Kudos
KeaganAllan
New Contributor III
Thanks for that.
I am using vb.net, so I dont think using the arcpy syntax would work.
Is there a similar command in VB that could be used?

thanks again,
I appreciate the help.
0 Kudos
RDHarles
Occasional Contributor
Sorry, no idea about VB.net
0 Kudos
KeaganAllan
New Contributor III
Bugger...

:)

Oh well...back to the ol' drawing board.

Thanks for replying!
0 Kudos
KeaganAllan
New Contributor III
Ok...

I found a solution.

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.

It works, its not pretty, but it works.

If there is an easier way, please post it here.

Thanks,

K
0 Kudos