Skip to content

Debugging

Amit Jain edited this page Apr 1, 2017 · 5 revisions

Debugging Python Raster Types

Python Raster types can be debugged using several methods. Here is one method that works within an IDE.

Python Tools for Visual Studio (PTVS)

This method is applicable only if you have Visual Studio installed on your machine. We used Visual Studio 2013 when debugging in the ArcMap environment and Visual Studio 2015 when debugging within the Pro environment. The following instructions may vary slightly depending on which version of Visual Studio you are using.

You can download Python Tools for Visual Studio from here. Once you have installed PTVS, navigate to the following link. Download the symbols and follow the steps outlined in the document to register the symbols in Visual Studio. If you are using ArcGIS 10.5.1, the Python version is 2.7.13. If you are using ArcGIS Pro, the Python version is 3.5.2.

Steps to debug Python Raster Types:

  1. After you have installed and setup PTVS, open Visual studio and open the Python raster type script that you wish to debug. Insert a break point(s) in the method that you want to debug into, the builder's build() method for example.

  2. Open ArcMap.

  3. Go back to Visual Studio and click on the ‘Attach’ button on the main toolbar.

  4. When the ‘Attach to Process’ dialog opens, hit the ‘Select’ button next to the ‘Attach To’ parameter. Check Python in the ‘Debug these code types’ list and click ‘Ok’. Make sure you uncheck 'Native’ code type or any other code type that might be checked on.

  5. Next, select ArcMap.exe in the ‘Available Processes’ window and then click the ‘Attach’ button.

  6. At this point, there are 2 ways the breakpoint in build() method can be hit.

    • If the raster type supports Raster Products, browse to a sample dataset that this Raster type supports and click on '+' to view the processing templates of the Raster Product. This will call the build() method of the builder class.
    • The other option to hit the breakpoint in the build() method is to execute Add Rasters to Mosaic Dataset operation. Be careful to select only one dataset to be added so that the breakpoint is hit only once. If crawling a folder, the build() method will be called for each and every item that is supported by the raster builder.
  7. You should have hit the breakpoint set in step 1. You will now be able to step through your python code.

Exceptions and Error Reporting

Another way of identifying problems within the python script is by letting the exceptions from python pass through to the ArcGIS Python Raster Type framework. The Python Raster Type framework can extract exception information from the python script. The exception info can be viewed in two ways

  • Drag and drop a Raster Product into ArcMap - if there is any exception generated in the Python script, it will appear as an error dialog in ArcMap.

  • Run Add Rasters to Mosaic Dataset GP tool. Any exception information will be displayed in the Geoprocessing messages window.