You are here: > ESRI Forums > arcgis desktop discussion forums > Thread Replies

ArcGIS Desktop Discussion Forums

ArcGIS Desktop - Geoprocessing Scripting (Python, JavaScript, VB) forum

python: Failed to execute (AddField).   Simone Caschili May 08, 2009
Re: python: Failed to execute (AddField).   Simone Caschili May 08, 2009
Re: python: Failed to execute (AddField).   Mike Hunter May 09, 2009
Re: python: Failed to execute (AddField).   Simone Caschili May 09, 2009
Re: python: Failed to execute (AddField).   Simone Caschili May 12, 2009
Re: python: Failed to execute (AddField).   Tim Leach May 29, 2009
Re: python: Failed to execute (AddField).   Tim Leach May 29, 2009
Re: python: Failed to execute (AddField).   Simone Caschili Jun 02, 2009
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject python: Failed to execute (AddField). 
Author Simone Caschili 
Date May 08, 2009 
Message Hi!

I'm trying to implement a python script into ArcGIS 9.2

My script reads some network data from a text file and it would convert that into two shapefiles: a point shapefile (the network's nodes) and polyline shapefile (the network's links).

What I'm doing is to create the two shapefiles using the function 'CreateFeatureclass()' and to add a field to each of those shapefiles trough the function 'addfield()'.

It looks like the function 'addfield' can't be executed for both shapefiles because the first shapefile locks the second one. So it is like the operation can be executed for the first shapefile but not for the second one.

The error I get is this:

Cannot get exclusive schema lock. Either being edited or in use by another application.
Failed to execute (AddField).

Any idea how to solve this issue?
thanks
Simone 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: python: Failed to execute (AddField). 
Author Simone Caschili 
Date May 08, 2009 
Message I forgot to add a small sample of the script I am running. It may be more explanatory than my words !

 
 
#EDIT the script has been edited in order to correct a typo

import string, os, sys, locale, arcgisscripting
gp = arcgisscripting.create()
gp.overwriteoutput = 1


try:
	inputTxtFile = open(sys.argv[1])
	
	outputFC = sys.argv[2]#polyline feature class
	outputFC2 = sys.argv[3]#point feature class
	outputSR = sys.argv[4]
	gp.toolbox = "management"
	gp.CreateFeatureclass(os.path.split(outputFC)[0], os.path.split(outputFC)[1], "Polyline", "#", "ENABLED", "ENABLED", outputSR)
	
	gp.CreateFeatureclass(os.path.split(outputFC2)[0], os.path.split(outputFC2)[1], "point", "#", "ENABLED", "ENABLED", outputSR)

	idfield = "Attrib"
	gp.addfield(outputFC, idfield, "TEXT", "20")
	idfield1 = "label"
	gp.addfield(outputFC2, idfield1, "TEXT", "20")

#from here some iterations run
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: python: Failed to execute (AddField). 
Author Mike Hunter 
Date May 09, 2009 
Message It looks like you are setting both the outputSR and outputFC2 variables to sys.argv[3]. That may have something to do with your problem.
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: python: Failed to execute (AddField). 
Author Simone Caschili 
Date May 09, 2009 
Message Thanks for the answer. I was wrong typing here but the script i am running is correct. 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: python: Failed to execute (AddField). 
Author Simone Caschili 
Date May 12, 2009 
Message After some days of research on internet and trying to solve this issue I couldn't really figure out how to solve it!
I've just arranged my script spliting it in two scripts in which there is just one AddField function per time.

I hope someone can give me a hint about this even next days or months !! Just a matter of "why" ??? 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: python: Failed to execute (AddField). 
Author Tim Leach 
Date May 29, 2009 
Message I have recently experienced a similar problem. My code block is very complex (so I prefer not to post it all). The way I solved it is to delete and reestablish the geoprocessing object.
 
 
# First AddField..

del gp
gp = arcgisscripting.create()

# Second AddField.

 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: python: Failed to execute (AddField). 
Author Tim Leach 
Date May 29, 2009 
Message By the way, my experience with the schema lock was only on code referencing shapefiles within folders/directories.

The original code worked fine with feature classes and datasets and did not require the extra lines to delete and reestablish the gp object.

NOTE: I have updated my email address since my last post (it was old and won't work). 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: python: Failed to execute (AddField). 
Author Simone Caschili 
Date Jun 02, 2009 
Message Tim,

thanks for posting your solution. Actually I thought to have already tested it before. But eventually I didn't (or not properly) since now it works perfectly. It solves my issue!

Simone