Select to view content in your preferred language

AddMessage not being added to ArcGIS geoprocessing window

3608
5
06-23-2017 09:47 AM
AndrewBartshire1
Deactivated User

I have a few python scripts that are being called from modelbuilder and for months the AddMessage() function was working properly, displaying results in the ArcGIS geoprocessing window as the scripts ran. All of a sudden the geoprocessing window just stopped displaying those messages but continued to run the scripts correctly. I don't think the issue is with the python code but maybe some setting within ArcGIS for the geoprocessing window?

This is just a snippet of the python script:

precheck1 = arcpy.TestSchemaLock(tblQAQC1)
precheck2 = arcpy.TestSchemaLock(tblNew)
precheck3 = arcpy.arcpy.Exists(tblAGOL)

if precheck1 == False:
    schemaCheck = "Fail"
    arcpy.AddMessage("QAQC1 layer locked")

elif precheck2 == False:
    schemaCheck = "Fail"
    arcpy.AddMessage("Raw layer locked")

elif precheck3 == False:
    schemaCheck = "Fail"
    arcpy.AddMessage("AGOL DB not found")

else:
    schemaCheck = "Pass"
    arcpy.AddMessage("Schema is fine")

Attached: Screenshot of resulting geoprocessing window.

0 Kudos
5 Replies
XanderBakker
Esri Esteemed Contributor

What version are you using? I just tested this with 10.5 and it works as it is supposed to.

Tool output:

Underlying script:

def main():
    import arcpy

    tblQAQC1 = arcpy.GetParameterAsText(0)
    tblNew = arcpy.GetParameterAsText(1)
    tblAGOL = arcpy.GetParameterAsText(2)

    precheck1 = arcpy.TestSchemaLock(tblQAQC1)
    precheck2 = arcpy.TestSchemaLock(tblNew)
    precheck3 = arcpy.arcpy.Exists(tblAGOL)

    arcpy.AddMessage("precheck1: '{0}'".format(precheck1))
    arcpy.AddMessage("precheck2: '{0}'".format(precheck2))
    arcpy.AddMessage("precheck3: '{0}'".format(precheck3))

    schemaCheck = "Not Set..."
    if precheck1 == False:
        schemaCheck = "Fail"
        arcpy.AddMessage("QAQC1 layer locked")
    elif precheck2 == False:
        schemaCheck = "Fail"
        arcpy.AddMessage("Raw layer locked")
    elif precheck3 == False:
        schemaCheck = "Fail"
        arcpy.AddMessage("AGOL DB not found")
    else:
        schemaCheck = "Pass"
        arcpy.AddMessage("Schema is fine")

    arcpy.AddMessage("schemaCheck: '{0}'".format(schemaCheck))
    arcpy.SetParameterAsText(3, "schemaCheck: '{0}'".format(schemaCheck))

if __name__ == '__main__':
    main()

I did notice that no matter what I threw at the first parameter (table, table view, featureclass on disk, etc) it always returned False on the arcpy.TestSchemaLock

AndrewBartshire1
Deactivated User

I am using 10.3.1.

Thanks,

Andrew

0 Kudos
MicahBabinski
Frequent Contributor

Hi Andrew,

Have you tried a simple script tool that just outputs a message using arcpy.AddMessage()? That might be a good way to isolate the issue. Also, is there any chance you could execute the whole thing in a Python script?

FWIW, I just tried a script tool of mine in ModelBuilder and it did display the messages as expected.

Good luck,

Micah

0 Kudos
DanPatterson_Retired
MVP Emeritus

throw a print statement in containing the same info as the addmessages.  If you are not seeing print anywhere either, then you have installation issues.  If you are seeing the print statements but the not AddMessage, then it isn't connected to arcmap

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

I have a function (usually in a utils.py file with others) called   myMsgs   so it will print whether using and external IDE, the python window or want it to write to the Results window.   It may double the print if in the Desktop python window, but I can live with that.  I actually have several handy functions (message with or without logging, and with out without time stamping....a "sleep" for scripts that get ahead of themselves and need to be paused, etc).  I'll just post the entite file so you can tweak or use other parts.

import time
import arcpy
import os
from time import localtime


def mySleep(secs):
     myMsgs("     zzz...sleeping {0} seconds to allow network file status to catch up....".format(secs))
     time.sleep(secs)     
     
def timeStamp():   # returns time stamp.
     return time.strftime(' -  %B %d - %H:%M:%S')

# shows messages for python window or tool, but does not log
def myMsgsNoLog(message):
     arcpy.AddMessage(message)
     print(message)

def myMsgs(message):
     arcpy.AddMessage("{0} {1}".format(message, curTime()))
     print("{0} {1}".format(message, curTime()))

     global messageCount
     logFolder = r"C:\ESRITEST"
     if not arcpy.Exists(logFolder):
          arcpy.CreateFolder_management(os.sep.join(logFolder.split(os.sep)[:-1]), logFolder.split(os.sep)[-1])
     mdy = curDate()
     logName = "logfile_" + "_".join(mdy.split("/")) + ".log"
     logFile = open(os.path.join(logFolder, logName), "a")  #a=append, w=create new
     if message.lower() == "blank line":
          logFile.write("\n\n")
          print('\n\n')
     elif message.lower() == "close logfile":
          logFile.write("\n\n*****  finished  *****\n\n")
          logFile.close()
     else:
          messageCount += 1
          logFile.write("0" * (5 - len(str(messageCount))) + str(messageCount) + ".   ")
          logFile.write(message)
          logFile.write("\n")
          #print(message)
          #arcpy.AddMessage(message)

def curDate():          # mmddyyyy
     rawTime = localtime()
     yr = str(rawTime[0]) # Collect the year from the rawTime variable
     mo = str(rawTime[1]).zfill(2) # 2-char month from local rawTime
     dy = str(rawTime[2]).zfill(2) # 2-char day from local rawTime
     return "/".join([mo, dy, yr])

def curTime():          # hhmmss
     rawTime = localtime()
     hr   = str(rawTime[3]).zfill(2) # 2-char hour from local rawTime
     mins = str(rawTime[4]).zfill(2) # 2-char minute from local rawTime
     secs = str(rawTime[5]).zfill(2) # 2-char second from local rawTime
     return (":".join([hr, mins, secs]))

def curFileDateTime():   # yyyymmdd_hhmm
     rawTime = localtime()
     yr = str(rawTime[0]) # Collect year from local rawTime 
     mo = str(rawTime[1]).zfill(2) # 2-char month from local rawTime
     dy = str(rawTime[2]).zfill(2) # 2-char day from local rawTime 
     hr = str(rawTime[3]).zfill(2) # 2-char hour from local rawTime
     mn = str(rawTime[4]).zfill(2) # 2-char minute from local rawTime
     return (yr + mo + dy + "_" + hr + mn)
     #return "".join([mo, dy, yr, hr, mn])

def archiveDate():      # yyyymmddhhmm
     rawTime = localtime()
     yr = str(rawTime[0]) # Collect year from local rawTime
     mo = str(rawTime[1]).zfill(2) # 2-char month from local rawTime
     dy = str(rawTime[2]).zfill(2) # 2-char day from local rawTime 
     hr = str(rawTime[3]).zfill(2) # 2-char hour from local rawTime 
     mn = str(rawTime[4]).zfill(2) # 2-char minute from local rawTime 
     return "".join([yr, mo, dy, hr, mn])


def jdayShort():
     import time
     from time import localtime
     return localtime()[7]

messageCount = 0