ArcGIS geoprocessing tools have rich support for messaging and reporting progress within the ArcGIS family of applications. With script tools implemented with python the coding patterns are well established and documented.
The code within this repo shows how to call from python to a C/C++ library (dll) and have the dll drive the ArcGIS application progressor, pass messages to the app, and query if the user has cancelled the operation (in order to cancel processing and gracefully exit the dll).
- gptool_script.py calls my_cpp_function in the dll with two arguments
- a string to show passing argument from python to the dll
- a callback function for the dll to push feedback to python
- my-lib.dll my_cpp_function calls back into python to
- push messages (strings)
- move the progress bar
- query if arcpy.env.isCancelled is True (user has cancelled operation)
- open my-lib.sln with Visual Studio
- in the BUILD menu, select Configuration Manager...
- set the Active solution configuration to Release
- set the Active solution platform to Win32
- build my-lib.dll
- run gptool_script.py using python27 (to test)
- Open ArcGIS Pro
- add arcpy-cpp-interop.pyt to the project
- run the 'cpp interop example' tool (note progress & messaging)
- open my-lib.sln with Visual Studio
- in the BUILD menu, select Configuration Manager...
- set the Active solution configuration to Release
- set the Active solution platform to x64
- build my-lib.dll
- run gptool_script.py using python34 (to test)
- Open ArcGIS Pro
- add arcpy-cpp-interop.pyt to the project
- run the 'cpp interop example' tool (note progress & messaging)
At Pro 1.1 (planned for ArcGIS 10.4) the arcpy.env.autoCancelling and
arcpy.env.isCancelled have been added. By setting
arcpy.env.autoCancelling = False
the code in the dll is able to
run code based on the user having hit cancel on the operation
arcpy.env.isCancelled = True
.
Before Pro 1.1/ArcGIS 104, the properties mentioned above are missing progress and messaging will work, but the callback will fail if user has cancelled the tool, this failure with the Callback could be trapped for as indication of a cancel situation.