This lecture Introduction to arcpy Debugging Using arcpy.

Slides:



Advertisements
Similar presentations
More about Ruby Maciej Mensfeld Presented by: Maciej Mensfeld More about Ruby dev.mensfeld.pl github.com/mensfeld.
Advertisements

Chapter 2.2 – More about Ruby Maciej Mensfeld Presented by: Maciej Mensfeld More about Ruby dev.mensfeld.pl github.com/mensfeld senior.
Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
Introduction to ESRI Add-Ins
Arc: Programming Options Dr Andy Evans. Programming ArcGIS ArcGIS: Most popular commercial GIS. Out of the box functionality good, but occasionally: You.
Esri International User Conference | San Diego, CA Technical Workshops | Python – Getting Started Drew Flater, Ghislain Prince July 12 - July 14, 2011.
Arc: AddIns Dr Andy Evans. Java Direct access to ArcObjects Framework inside and outside Arc. Ability to add components to the GUI. Ability to communicate.
Python: An Introduction
Programming for Geographical Information Analysis: Advanced Skills Lecture 1: Introduction Programming Arc Dr Andy Evans.
Python – Part 1 Python Programming Language 1. What is Python? High-level language Interpreted – easy to test and use interactively Object-oriented Open-source.
ArcGIS Pro: A Quick Tour of Python David Wynne.
Introduction to Exception Handling and Defensive Programming.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
11/25/2015Slide 1 Scripts are short programs that repeat sequences of SPSS commands. SPSS includes a computer language called Sax Basic for the creation.
Introduction to Eclipse Programming with an Integrated Development Environment.
Exceptions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
EXCEPTIONS. Catching exceptions Whenever a runtime error occurs, it create an exception object. The program stops running at this point and Python prints.
Introducing Python 3 Introduction to Python. Introduction to Python L1 Introducing Python 3 Learning Objectives Know what Python is and some of the applications.
Introducing Python Introduction to Python.
Development Environment
Exceptions in Python Error Handling.
Introduction to InVEST ArcGIS Tool
Input from STDIN STDIN, standard input, comes from the keyboard.
BIT116: Scripting Lecture 06
PYGAME.
Introduction to Python
PYTHON: AN INTRODUCTION
A video coding and data visualization tool
Syntax, semantics, and pragmatics
G7 programing language Teacher / Shamsa Hassan Alhassouni.
Visual studio 2010 SENG 403, Tutorial 2 SENG Winter 2011.
Graphing Calculator Troubleshooting Guide
Handling errors try except
LAS for Topographic Analysis Using Python
Exceptions and files Taken from notes by Dr. Neil Moore
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
Programming for Geographical Information Analysis: Advanced Skills
CNS 3260 C# .NET Software Development
Exception Handling Chapter 9.
Topics Introduction to File Input and Output
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
Macros/VBA Project Modules and Creating Add-Ins on the Toolbar
What to do when you get a run-time error message
Lecture Set 3 Introduction to Visual Basic Concepts
Exceptions and files Taken from notes by Dr. Neil Moore
1. Open Visual Studio 2008.
16: extcap – Packet Capture beyond libpcap/winpcap
CPRE 583 Reconfigurable Computing (Tools overview)
Addins Dr Andy Evans Welcome to the course. You’ll find extra information in these note sections below each slide.
Coding Concepts (Standards and Testing)
Addins Dr Andy Evans Welcome to the course. You’ll find extra information in these note sections below each slide.
Lecture Set 11 Creating and Using Classes
Exceptions.
Arcpy Dr Andy Evans Welcome to the course. You’ll find extra information in these note sections below each slide.
Programming for Geographical Information Analysis: Advanced Skills
This lecture Introduction to arcpy Debugging Using arcpy.
Due Next Monday Assignment 1 Start early
Exception Handling Imran Rashid CTO at ManiWeber Technologies.
Exceptions 19-Feb-19.
Problems Debugging is fine and dandy, but remember we divided problems into compile-time problems and runtime problems? Debugging only copes with the former.
CISC101 Reminders Assignment 3 due next Friday. Winter 2019
Exceptions 25-Apr-19.
Exceptions 22-Apr-19.
Programming Arc.
Topics Introduction to File Input and Output
PHP-II.
Exceptions 5-Jul-19.
Enclosing delimiters Python uses three style of special enclosing delimiters. These are what the Python documentation calls them: {} braces # Sometimes.
A few tricks to take you beyond the basics of Microsoft Office
Presentation transcript:

This lecture Introduction to arcpy Debugging Using arcpy

Debugging Scripts with an issue will be marked with a broken script icon. Addins with syntax errors will appear as a red stop sign. Debugging messages are often sent to the Python Window (so keep open). print() also usually writes to the Python Window. Debugging messages for geoprocessing tools will go to their dialog. Debugging information will also go to the results window (usually hidden).

Errors When something goes wrong with an arcpy component, it generates arcpy.ExecuteError exceptions. When something goes wrong with a geoprocessing tool, it generates messages - indeed, they also generate messages when working. Geoprocessing messages are subdivided into the following levels of severity: 0: general messages 1: non-critical warnings 2: critical errors In Arc, geoprocessing messages get diverted to the screen, so it is rarely necessary to deal with them separately, but in external scripts this kind of thing helps: except arcpy.ExecuteError: print(arcpy.GetMessages()) # or print(arcpy.GetMessages(2))

Messages The geoprocessing dialog appears whenever tools run, including script tools. You can write to this with: arcpy.AddMessage(messageString) arcpy.AddWarning(messageString) arcpy.AddError(messageString) arcpy.AddIDMessage(message_severity, message_ID, argument1, argument2) http://desktop.arcgis.com/en/arcmap/latest/analyze/creating-tools/writing-messages-in-script-tools.htm

Pattern for raising your own errors A common pattern used by ESRI in the docs (and quite nice) is this quick and easy way of checking your own stuff is working ok with an empty exception class: class MyException(Exception): pass try { # stuff if (condition): raise MyException("message") except MyException: # do stuff

Python traceback As arcpy error messages don't always include information about the Python itself (such as the erroneous linenumber) it can be useful to explicitly get the stacktrace using the sys and traceback libraries when something goes wrong: tb = sys.exc_info()[2] tbinfo = traceback.format_tb(tb)[0] print(tbinfo) # or arcpy.AddError(tbinfo) http://desktop.arcgis.com/en/arcmap/latest/analyze/python/error-handling-with-python.htm

Emergency treatment In the (unlikely) scenario you destroy Arc to the point it won't reboot, there are various options for resetting it. The easiest is to delete the new map template at: %APPDATA%\Roaming\ESRI\Desktop10.x\ArcMap\Templates\Normal.mxt Rename it, and Arc will rebuild it. Other options at: https://my.usgs.gov/confluence/display/EGIS/Resetting+your+ArcGIS+applicat ion+profile