check to see if workspace is being edited

674
5
Jump to solution
01-22-2013 07:25 AM
AdamCox1
Occasional Contributor II
Hello, just a quick thing that I'd really like to add to a ToolValidator script:

Is there a way to see if a geodatabase that I have as an input parameter is currently being edited?  I'm running Python 2.6.6 and 10.0 SP5.  It looks like I'd be able to do this with 10.1 and the arcpy.da module, but maybe there's a way with what I have..

Thanks,
Adam
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
KevinBell
Occasional Contributor III
>>> import glob  >>> if glob.glob(r'C:\Users\bk6128\Documents\ArcGIS\solarTest.gdb\*.lock'): ...     print True


???

View solution in original post

0 Kudos
5 Replies
KevinBell
Occasional Contributor III
>>> import glob  >>> if glob.glob(r'C:\Users\bk6128\Documents\ArcGIS\solarTest.gdb\*.lock'): ...     print True


???
0 Kudos
AdamCox1
Occasional Contributor II
Hi Kevin, thanks for the reply.

It will return true no problem, but after I stop the editing session, it still returns true...
0 Kudos
AdamGuo
New Contributor II
FYI- If you have an instance of ArcMap or ArcCatalog thats pointing to the database, then there is always a lock file. Try closing your instances of ArcMap/ Catalog and run the script again.
0 Kudos
AdamCox1
Occasional Contributor II
OK, making progress.  When run from IDLE, with or without ArcMap open, it works with a slight modification: using *.ed.lock instead of *.lock.  There are a bunch of lock files in there, but when an edit session is started, a file is created for each layer ending in ".ed.lock".  No problem to search for those.

However, I'm not able to get it to run correctly from ToolValidator.  It won't return an error when it should.  In the updateMessage class I have
import os.path, glob
if self.params[0].altered:
  if glob.glob(str(self.params[0].value) + '*.ed.lock'):
    self.params[0].setErrorMessage("Close edit session in Target Geodatabase before continuing.")

I have also tried with hardcoding the .gdb path instead of using str(self.params[0].value).

When run from here, perhaps it will not recognize individual files within a .gdb, only feature classes, etc?  I also tried os.path.isfile instead of glob.glob but with no luck...
0 Kudos
AdamCox1
Occasional Contributor II
I just revisited this, and figured out that my problem was just a silly little detail and glob is perfect after all; I forgot to add "\\" in my string.  So, this is all the code I need to put into ToolValidator to test whether an input file geodatabase is in an edit session:

import glob
if glob.glob(str(self.params[0].value) + '\\*.ed.lock'):
    self.params[0].setErrorMessage("Close edit session.")


Now I'm going to use it in all my tools...
Thanks for the help!
0 Kudos