Python code showing communication between python tool and a c/c++ library.
Python C++ Objective-C C
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is even with ghisprince:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
my-lib
.gitignore
LICENSE
README.md
arcpy-cpp-interop.Tool.pyt.xml
arcpy-cpp-interop.example1.pyt.xml
arcpy-cpp-interop.pyt
arcpy-cpp-interop.pyt.xml
gptool_script.py
tool.png

README.md

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).

Basic flow of code

  1. gptool_script.py calls my_cpp_function in the dll with two arguments
  2. a string to show passing argument from python to the dll
  3. a callback function for the dll to push feedback to python
  4. my-lib.dll my_cpp_function calls back into python to
  5. push messages (strings)
  6. move the progress bar
  7. query if arcpy.env.isCancelled is True (user has cancelled operation)

To use with ArcMap

  1. open my-lib.sln with Visual Studio
  2. in the BUILD menu, select Configuration Manager...
  3. set the Active solution configuration to Release
  4. set the Active solution platform to Win32
  5. build my-lib.dll
  6. run gptool_script.py using python27 (to test)
  7. Open ArcGIS Pro
  8. add arcpy-cpp-interop.pyt to the project
  9. run the 'cpp interop example' tool (note progress & messaging)

To use with ArcGIS Pro

  1. open my-lib.sln with Visual Studio
  2. in the BUILD menu, select Configuration Manager...
  3. set the Active solution configuration to Release
  4. set the Active solution platform to x64
  5. build my-lib.dll
  6. run gptool_script.py using python34 (to test)
  7. Open ArcGIS Pro
  8. add arcpy-cpp-interop.pyt to the project
  9. run the 'cpp interop example' tool (note progress & messaging)

Tool progress and messages

Notes

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.

Reference