I'm trying to disable a toolbar with nested menus and buttons when an mxd is in layout view, but it's not working. I also get no output in the ArcGIS python window when I switch to layout view.

Anyone have any ideas?

Using: ArcGIS 10.2.2, Python 2.7


import arcpy  
import pythonaddins  

class FishButton(object):  
    """Implementation for WTF_addin.fish_button (Button)"""  
    def __init__(self):  
        self.enabled = True  
##        self.checked = False  
    def onClick(self):  
        self.mxd = arcpy.mapping.MapDocument('current')  
##        layer = r'\\msds.wv.de\dfsroot\HV\GROUP\Gis\DATEN\wvdat\Querbauwerke\Fischaufstieg.lyr'  
        layer = r'G:\Gis\DATEN\wvdat\Querbauwerke\Fischaufstieg.lyr'  
        activeDataFrame = self.mxd.activeView  
        df = arcpy.mapping.ListDataFrames(self.mxd, activeDataFrame)[0]  
        if arcpy.Exists(layer):  
            layerToAdd = arcpy.mapping.Layer(layer)  
            arcpy.mapping.AddLayer(df, layerToAdd, 'TOP')  
            warningButton = pythonaddins.MessageBox("Die Datei ist nicht verfugbar.\nBitte kontaktieren Sie die GIS Abteilung.", "Datei nicht verfugbar", 0)  

class changeToolState(object):  
    """Implementation for WTF_addin.disable (Extension)"""  
    def __init__(self):  
        # For performance considerations, please remove all unused methods in this class.  
        self.enabled = True  
    def activeViewChanged(self):  
            mxd = arcpy.mapping.MapDocument('current')  
            active_view = mxd.activeView  
            if active_view == 'PAGE_LAYOUT':  
                WTF_toolbar.enabled = False  
                print 'button has been disabled...'  
                WTF_toolbar.enabled = True  
                print 'button re-enabled...'  

And the corresponding config.xml:

<ESRI.Configuration xmlns="http://schemas.esri.com/Desktop/AddIns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><Name>WTF</Name><AddInID>{8ed28a7b-5aa3-4474-baa5-7674acbb350a}</AddInID><Description>New Addin</Description><Version>0.1</Version><Image /><Author>Untitled</Author><Company>Untitled</Company><Date>04/27/2016</Date><Targets><Target name="Desktop" version="10.2" /></Targets><AddIn language="PYTHON" library="WTF_addin.py" namespace="WTF_addin"><ArcMap>  
        <Button caption="Fish" category="WTF" class="FishButton" id="WTF_addin.fish_button" image="" message="" tip=""><Help heading="" /></Button>  
        <Extension autoLoad="true" category="WTF" class="changeToolState" description="" id="WTF_addin.disable" name="Disable" productName="Disable" showInExtensionDialog="true" />  
        <Toolbar caption="WTF_Toolbar" category="WTF" id="WTF_addin.WTF_toolbar" showInitially="true"><Items><Menu refID="WTF_addin.cat_menu" /></Items></Toolbar>  
        <Menu caption="Category" category="WTF" id="WTF_addin.cat_menu" isRootMenu="false" isShortcutMenu="false" separator="false"><Items><Button refID="WTF_addin.fish_button" /></Items></Menu>  

1 Answer 1


Based off your code, it sounds like you're trying to disable a button rather than an entire toolbar.

Instead of WTF_toolbar.enabled = False do fish_button.enabled = False to disable the button. Same goes for WTF_toolbar.enabled = True.

There is more info in the help for Managing the state of Python add-in types

  • Thanks -- trying to disable the entire toolbar. The print statements were copied in from somewhere else.
    – user151631
    Commented Apr 27, 2016 at 13:37
  • I am trying this. Did you got it working? from link that @freshmints provided: "...The enabled property is available for buttons, tools, and combo boxes." nothing about toolbars and it is not workin for my toolbar. Commented Dec 6, 2017 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.