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:
It seems to work, but I am having some problems with messages. In my prep_input function I have the following as one example:
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
Code:
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)
Code:
# # 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) )
Some documentation on how this should be done/achieved would be appreciated.
Thanks,
john