combine arcpy.GetMessages with arcpy.AddWarning in cust modules in a Python Toobox

357
1
Jump to solution
03-12-2013 04:10 AM
JohnBurkhart1
New Contributor II
Hello, I've created a Python Toolbox that imports a function from a custom module to do most the work. So, in my toolbox.pyt file I have:

def execute(self, parameters, messages):     """The source code of the tool."""     import sys     sys.path.append(CUSTOM_PATH)     import pEnki.ENKI_prepinput as ep      ep.prep_input(parameters)


It seems to work, but I am having some problems with messages. In my prep_input function I have the following as one example:

# # Process: Polygon to Raster  for shp, field in selects:      arcpy.AddMessage("trying to create {0} raster".format(field))     try:         res = arcpy.PolygonToRaster_conversion(shp, "FID",                                                 "{0}_{1}.tif".format(RegionName, field),                                                 "CELL_CENTER", "NONE", "1000")         arcpy.AddMessage('Created: {0} raster'.format(field) )     except:         arcpy.AddWarning( arcpy.GetMessages(2) ) 


But this just returns an empty string in the Warning. I've tried some other variants of the above... but so far can't figure out exactly how to pass the message from arcpy.GetMessages(2) (e.g. the reason for the exception) to the arcpy.AddWarning.

Some documentation on how this should be done/achieved would be appreciated.

Thanks,
john
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JohnBurkhart1
New Contributor II
Answering my own post... a little more playing around and I discovered this works:

res = arcpy.GetMessage(2) arcpy.AddWarning( res )

View solution in original post

0 Kudos
1 Reply
JohnBurkhart1
New Contributor II
Answering my own post... a little more playing around and I discovered this works:

res = arcpy.GetMessage(2) arcpy.AddWarning( res )
0 Kudos