I am using arcpy.da.SearchCursor. I want to add a confirm dialog box in arcpy to proceed further. Can I apply this in arcpy?
Solved! Go to Solution.
If this is a standalone script that is run manually, then the solution from @Tom_Laue should work. Another option to consider is a script tool or Python toolbox.
I add something like this if I want to remind myself that I'm about to edit or overwrite critical data...
answer = input("Do you want to continue? (yes/no): ").lower()
if answer == "yes" or answer == "y":
print("Continuing...")
# Add your code here for further execution
else:
print("Exiting...")
sys.exit()
If this is a standalone script that is run manually, then the solution from @Tom_Laue should work. Another option to consider is a script tool or Python toolbox.
Thanks for the reply @BlakeTerhune,
I am using Python toolbox, in that I need a confirm dialog box in between running the script, is that possible?
Python toolboxes are able to run validation logic and have appropriate messaging before the script is allowed to excecute. When I find myself in a situation like this where I want the user to be sure everything is correct, I define some initial parameters for validation. In my case, I will check the number of selected records and prevent them from running the tool if there's less than 1 or more than 1000. You can make these checks in the updateMessages() method.
Python toolbox messages—ArcGIS Pro | Documentation
If you really need more than a simple warning tooltip next to the input parameter or can't predefine the logic for checking if the situation seems valid, first consider how often people will be using this tool. If regularly, maybe the messaging is enough. You don't want to make a confirmation become a reflexive habit. If you're still looking for a way to slow them down, well, there's not really a good way. You could have a check box at the bottom of the inputs that says something like, "I understand this tool will permanently modify the input data, etc., etc." Then, in the updateMessages() method, put an error message tooltop on it, which prevents the tool from executing.