I have a python addin tool that looks for layers in the TOC using ArcMap. I need to be able to replace these layers with new layers of the same name in the same workspace. I'm working with shapefiles. The lock file is not releasing when I remove the layer. I use arcpy.mapping.RemoveLayer(), then with the os module, go into workspace where the layer was located and use os.remove() to delete the files. Unfortunately this keeps failing due to the schema lock. Is there a way for ArcMap to release the lock. The lock is released if I right-click the shapefile and remove it from the TOC, but I need to wrap this functionality within the addin tool using python.
layerPath = layer.workspacePath layerName = layer.name arcpy.mapping.RemoveLayer(df, layer) arcpy.RefreshActiveView() for file in os.listdir(layerPath): if file.startswith(layerName): os.remove(os.path.join(layerPath, file))
How do I remove the schemalock?