I'm looking for a way to check for writing access to an mxd upon the initiation of a python AddIn tool. My tool should only be enabled if the user has writing access to the mxd. I thought there was a way to check for read/write access using
arcpy (or maybe
os?) but it's lost on me now. I tried the following as a work-around (saving upon initiation):
class ToolClass2(object): def __init__(self): mxd = arcpy.mapping.MapDocument ("CURRENT") try: mxd.save () except IOError: pythonaddins.MessageBox ("The map document is locked.", "Map file locked", 0) self.enabled = False
However, this doesn't produce an
IOError. Instead I get a warning box (below) from ArcMap and the
try is successful and the
except is ignored.
I've also tried making use of
os.access, but without results (
os.access (mapPath, os.W_OK) returns
mapPath = mxd.filePath if not os.access (mapPath, os.W_OK): pythonaddins.MessageBox ("The map document is locked.", "Map file locked", 0) self.enabled = False
I've now realized that I was thinking of
arcpy.TestSchemaLock, but according to the help this is only for feature classes, tables, and feature datasets.
Developing with version 10.4 but the end users will be 10.1.