-
Notifications
You must be signed in to change notification settings - Fork 16
/
custommessaging.py
48 lines (44 loc) · 1.56 KB
/
custommessaging.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import arcpy
class MsgType:
INF = "INFORMATIVE"
WRN = "WARNING"
ERR = "ERROR"
class Message:
def __init__(self, msgID, msg, msgType):
self.msgID = msgID
self.msg = msg
self.msgType = msgType
## Common Functions
def printMessage(msgObj, messageVar1=None, messageVar2=None):
try: #Try printing message from message xml first
arcpy.AddIDMessage(msgObj.msgType, msgObj.msgID, messageVar1, messageVar2)
except:
message = msgObj.msg.format(messageVar1, messageVar2)
if msgObj.msgType == MsgType.INF:
arcpy.AddMessage(message)
elif msgObj.msgType == MsgType.WRN:
arcpy.AddWarning(message)
elif msgObj.msgType == MsgType.ERR:
arcpy.AddError(message)
return
def validationMessage(msgObj,paramObj, messageVar1=None, messageVar2=None):
try:
paramObj.setIDMessage(msgObj.msgType,msgObj.msgID,messageVar1, messageVar2)
except:
message = msgObj.msg.format(messageVar1, messageVar2)
if msgObj.msgType == MsgType.WRN:
paramObj.setWarningMessage(message)
elif msgObj.msgType == MsgType.ERR:
paramObj.setErrorMessage(message)
return
def retrieveMessage(msgObj, messageVar1=None, messageVar2=None):
try:
message = arcpy.GetIDMessage(msgObj.msgID)
if not message:
raise Exception
message = message.replace("%1","{0}")
message = message.replace("%2","{1}")
except:
message = msgObj.msg
message = message.format(messageVar1, messageVar2)
return message