I have a tool that runs on layouts and I want to insert an error message if the activeview is not a layout. self.params[0].value = '>>> MUST BE IN LAYOUT VIEW<<<' but self.params[0].setErrorMessage("Must be in layout view.") (which I would prefer to use because I think it would be a cleaner error-handling method) is completely, totally ignored and I just can't figure out why. The code is running after the "else:" (the active view is not a layout).
Is there some obvious, easy-to-spot mistake I'm making here? I would appreciate it anyone could see what's because I don't.
Thank you,
Randy McGregor
def initializeParameters(self):
# Customize parameter properties. This method gets called when the
# tool is opened.
aprx = arcpy.mp.ArcGISProject("CURRENT")
av = aprx.activeView
#if av.type =="LAYOUT":
if isinstance(av,arcpy._mp.Layout):
am = aprx.activeMap
mf_filter = []
mf_list = av.listElements("MAPFRAME_ELEMENT")
# Load non-active map frames to filter list.
for mf in mf_list:
if mf.map.name != am.name:
mf_filter.append(mf.name)
# Load the active map frame into the front position of the filter list,
# so that it is the default map frame when the tool is opened.
for mf in mf_list:
if mf.map.name == am.name:
mf_filter.insert(0,mf.name)
self.params[0].filter.list = mf_filter
self.params[0].value = mf_filter[0]
else:
self.params[0].setErrorMessage("Must be in layout view.")
##self.params[0].filter.list=[]
##self.params[0].value = ">>>MUST BE IN LAYOUT VIEW TO USE THIS TOOL<<<"
return
Solved! Go to Solution.
Parameter—ArcGIS Pro | Documentation
Example 3 uses an updateMessages method in conjunction with clearing the messages prior to adding the custome setErrorMessage. If you want to use it in your existing, perhaps try clearing the message prior to setting it or try the updateMessages approach
Parameter—ArcGIS Pro | Documentation
Example 3 uses an updateMessages method in conjunction with clearing the messages prior to adding the custome setErrorMessage. If you want to use it in your existing, perhaps try clearing the message prior to setting it or try the updateMessages approach
Thank you. Some examples did (seem to?) set error messages in other methods, but only the updateMessages method worked for me. Also, combining with updateParameters was necessary. The validator class is a little more complicated than I thought, and error messaging - with dynamic responsiveness - will take a little time to figure out. Thank you for your help.