http://forums.arcgis.com/threads/69376-Message-script-tool-for-ModelBuilder
Message script tool for ModelBuilder
Today I got a message script tool working along the lines of the one discussed in the ArcGIS Blog for use in generating messages inside ModelBuilder.
First, an example of how it works, set up as a script tool with two text arguments, the first "MESSAGE","ERROR","WARNING", the second your message. What's new about this one over the one linked from the blog is that with this version, you can do error codes by using the format: "id arg1,arg2". (Sure would be nice if a tool was provided that does this in ModelBuilder.)
Code:
Executing: Message WARNING "id 591 First,Last" Start Time: Thu Oct 18 11:58:10 2012 Running script Message... WARNING 000591: First parameter not Last. Completed script Message...Succeeded at Thu Oct 18 11:58:10 2012 (Elapsed Time: 0.00 seconds)
Code:
#
# GP Script tool - Message
# for use in ModelBuilder
import arcgisscripting
gp = arcgisscripting.create()
# Message type: MESSAGE, WARNING, ERROR
msgType = gp.GetParameterAsText(0).upper()
# Message text
msgText = gp.GetParameterAsText(1)
try:
  # id message, format: "id 345 arg1,arg2"
  if msgText[:2].lower() != "id" or msgType == "MESSAGE":
    raise
  else:
    msgList = msgText[3:].split()
    msgID = int(msgList[0])
    # pick up arguments, comma-separated
    msgArgs = " ".join(msgList[1:]).split(",")
    msgArgs = [msgType,msgID] + msgArgs
    gp.AddIDMessage(*msgArgs)
except:
  # text messages
  if msgType == "MESSAGE":
    gp.AddMessage(msgText)
  elif msgType == "WARNING":
    gp.AddWarning(msgText)
  elif msgType == "ERROR":
    gp.AddError(msgText)
  else:
    gp.AddMessage(msgText)
 
gp.SetParameterAsText(2,True) 
Cap comentari:
Publica un comentari a l'entrada