Saturday, December 17, 2011

Displaying Messages for a Specific Tool

Robust messaging is very important to help developers debug issues and it helps end users understand what the tool is doing.

ArcGIS Desktop geoprocessing tools have robust messaging built in, but when you run a script, those messages get lost.  To access individual tool messages, just do the following:



import arcpy
from arcpy import env
import sys
env.overwriteOutput = True
sr = arcpy.SpatialReference()
sr.factoryCode = 4326
sr.create()
pt = arcpy.Point(-78,38)
pointGeom = arcpy.PointGeometry(pt,sr)
copiedPt = arcpy.CopyFeatures_management(pointGeom)
print copiedPt.getMessages()


This produces:


Executing: CopyFeatures in_memory\f331817DB_DC61_4523_88F8_1B0329E5F568 c:\TEMP\copiedPT.shp # 0 0 0
Start Time: Fri Dec 16 13:10:14 2011
Succeeded at Fri Dec 16 13:10:14 2011 (Elapsed Time: 0.00 seconds


Very cool and enjoy

No comments: