Select to view content in your preferred language

Button in ArcGIS Pro with ArcPy?

2068
3
11-05-2020 06:20 AM
anyry
by
Occasional Contributor

Hello, 

is it possible to create button in ArcGIS Pro with ArcPy? I have a script that I run directly from the command line, but I need to modify it to a button directly in ArcGIS Pro. I know it can be achieved with SDK but is it possible with ArcPy?

Thanks

0 Kudos
3 Replies
JoshuaBixby
MVP Esteemed Contributor

Unfortunately, The pythonaddins module—ArcMap | Documentation has not, and likely won't be, ported over to ArcGIS Pro.  So, you are left looking to non-Esri/ArcGIS packages.

There are several options to present messages boxes, dialog boxes, etc... in Python:  tkinter, ctypes, pywin32, and others.  Normally I would suggest tkinter because it is cross-platform and the standard/default with Python, but Esri has done something under the hood to break standard tkinter syntax within ArcGIS Pro application.  I like ctypes, but it is a bit more involved for people who aren't used to working with it, so I suggest pywin32:

import win32ui
import win32con

response = win32ui.MessageBox("Message", "Title", win32con.MB_YESNOCANCEL)
anyry
by
Occasional Contributor

Thanks so much for the tip, I will try it.

0 Kudos
DuncanHornby
MVP Notable Contributor

You say you currently run your script from the command line this indicates you don't interact with the map, something that a tool button would allow. As @JoshuaBixby  says the pythonaddin has not been ported to ArcPro. Why not run your script as a tool instead? You wire up your script to a tool interface and then you can run it from a toolbox, it has the look, feel and behaviour of any other tool. This would provide an interface to your script to allow a user to change the input parameters.

0 Kudos