Did you read up on the Editor in the help? It would be best to run your functionality from a tool in arctoolbox, to ensure or validate that you are in an edit session than relying on the user getting into an edit session manually
Dan, I was thinking along the lines of the format I have below. This way users wouldn't have to turn editor on manually but just have to simply click yes or no. Would this work?
if isEditing == True: run tool elif isEditing == False: dialogue box pops up informing user to be in edit session and ask if they want script to turn it on for them: if yes: arcpy.startEditing() elif no: quit
I would just bail .... totally untested of course.
# -*- coding: UTF-8 -*- import sys import os import arcpy #edit_me = sys.argv fc = r"C:\GIS\array_projects\data\Pro_base.gdb\Line" workspace = os.path.dirname(fc) edit = arcpy.da.Editor(workspace) if edit.isEditing: print("you are in an edit session") else: print("you aren't in an edit session") sys.exit
Good idea, unfortunately it doesn't seem to work. I just tested a file and enterprise geodatabase, and arcpy.da.Editor appears to only be aware of itself, i.e., isEditing() only returns True if the instantiated editor object starts an edit session.
Yea we ran into this question a couple weeks ago where the Map Document and the arcpy Editor object aren't aware of each others editting status and their isn't a way to pythonicly check if an edit session is going on in the map document without using ArcObjects. I pointed them to the below post but I'm not sure if they got anywhere with it or not.
So I believe doing it this way may actually work in a sense to get the Message Box using the python add-ins module. However, one issue I am having is doing the check to see which value from the message box the user selected. This is the first thing that happens when the user selects to use this tool. This is an add-in portion of the tool. Any help on figuring out how to call on the value in the Message Box will be helpful. The mb_type here is 4 so that the message box type is yes/no. Other mb_types and information about python add-ins can be found here. So my issue is figuring out how to see if the Message Box value the user selected was a yes or a no.
import arcpy import pythonaddins import os toolPath = r'path to toolboox.tbx' workspace = 'some workspace' editor = arcpy.da.Editor(workspace) if editor.isEditing == 'true': pythonaddins.GPToolDialog(toolPath, 'CustomExportTool') elif editor.isEditing == 'false': pythonaddins.MessageBox("You must be in an edit session to run the Custom Export Tool. If you wish to turn an edit session on, please click 'yes'. If you do not wish to turn an edit session on, please click 'no'.", "Turn Editor On?", 4) if MessageBox == 'yes': editor.startEditing(False, False) pythonaddins.GPToolDialog(toolPath, 'CustomExportTool') elif MessageBox == 'no': quit
The message box function returns a string, so provide a variable for the return string to get stored in:
msg = pythonaddins.MessageBox("You must be in an edit session to run the Custom Export Tool. If you wish to turn an edit session on, please click 'yes'. If you do not wish to turn an edit session on, please click 'no'.", "Turn Editor On?", 4)
Then check the value stored in the variable.