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