17

I'm writing a python script, I've got an mxd and its workspace is a geodatabase file with all the files I need into. The problem I'm encountering in testing and writing code is that, despite of the command:

arcpy.env.overwriteOutput=True

all the files contained in geodatabase fail to overwrite. There's a way to work around this?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Annalisa Minelli
  • 517
  • 2
  • 5
  • 15
  • In ArcMap, did you check the "Overwrite the outputs of geoprocessing operations" in Geoprocessing>Geoprocessing Options? – Baltok Oct 04 '12 at 15:25
  • yes, I did. But didn't work. – Annalisa Minelli Oct 04 '12 at 15:43
  • 3
    Are you aware of any schema locks on your data? That can prevent overwriting as well. File and Personal Geodatabases are particularly sensitive to this, because if one feature class has a lock, it locks the whole geodatabase. – Baltok Oct 04 '12 at 16:03
  • 2
    When you say that "all the files contained in the geodatabase fail to overwrite", do you mean the script fails or it completes but just does not overwrite the featureclasses which it should? – Chad Cooper Oct 04 '12 at 16:20
  • try to run your code from a python IDE like PyScripter, then close ArcMap. – geogeek Oct 04 '12 at 20:10
  • Further to Baltok's comment, if there is a topology, parcel fabric, or a geometric network on your geodatabase, this will prevent overwriting. There are others if you have different extensions enabled. – Fezter Oct 05 '12 at 02:11
  • Thanks all, really interesting all of your answers: @Baltok : THANKS, now I understand. ChadCooper : no, the script exits with the error saying that the file exists and cannot be overwritten geogeek : I'll try.. but my script has to run with an mxd opened (where other files, belonging to the same geodatabase file, are opened - and locked I suppose..) Fezter : I don't know what you mean for "geometric network" but if you meant geometrical features or built topology.. yes, these elements are present in my gdb file.. – Annalisa Minelli Oct 05 '12 at 07:48
  • If this needs to be progressed then I think the next step is to edit your question to include a code snippet that demonstrates the error, and the exact error message that you receive. – PolyGeo Nov 13 '14 at 09:25
  • also be sure there are no locks on the FC, that will prevent it as well – NULL.Dude Mar 30 '18 at 11:54

3 Answers3

20

If I recall correctly there are certain situations for which overwriteOutput won't work. In that case use the following code prior to writing out new files:

if arcpy.Exists(fileInQuestion):
    arcpy.Delete_management(fileInQuestion)
PolyGeo
  • 65,136
  • 29
  • 109
  • 338
bluefoot
  • 3,100
  • 19
  • 31
2

Make sure the file geodatabase is not compressed i.e., read only.

user12711
  • 1,620
  • 3
  • 16
  • 26
0

I was also having this problem and the comment about the schema locks really helped. If you have an mxd with that feature class on it, it locks that feature class so it cannot be deleted. If you just exit the mxd that contains that feature class and run the same overwrite code, it seems to work.

JJay
  • 1