I'm trying to find a way to determine whether a feature class is locked before trying to alter it.
In one database I want to remove a feature class completely, and in another I want to add extra fields. I can't do either if they're locked.
I was expecting to find something in arcpy.Describe()
but haven't found anything. Something like
if arcpy.Describe(myFC).isLocked:
print "Can't proceed - feature class is locked"
else:
arcpy.Delete_management(myFC)
Is there a way to check feature class locks using arcpy?
2 Answers 2
Found it - I was using incorrect terminology in my searches.
There is a tool called Test Schema Lock which will return True
or False
based on whether a lock can be applied or not. So my code would be:
if not arcpy.TestSchemaLock(myFC):
print "Can't proceed - feature class is locked"
else:
arcpy.Delete_management(myFC)
Because it returns True
if the feature class isn't locked (i.e. a lock can be applied), an if not
needs to be used to find where it returns False
(it is locked).
-
1Does this work on the entire gdb as well as individual feature classes? What about shapefiles?Craig T– Craig T2017年04月19日 13:57:31 +00:00Commented Apr 19, 2017 at 13:57
-
1@CraigT it's only 4 lines, have you tried it? I suspect it will work for shapefiles as well, but I haven't tried. I don't know about entire gdb - locks are usually per feature class so I'm not sure if a gdb reports it is locked. You could loop through each feature class to determine which is locked and which isn't2017年04月19日 14:05:18 +00:00Commented Apr 19, 2017 at 14:05
This syntax is outdated now.
You can use arcpy.testSchemaLock() instead.
Link to Doc. https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/testschemalock.htm
-
What syntax is outdated? Your suggested solution is the same as the accepted answer2023年09月08日 19:53:29 +00:00Commented Sep 8, 2023 at 19:53
Explore related questions
See similar questions with these tags.