2

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

Code:

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') 
 else: 
 warningButton = pythonaddins.MessageBox("Die Datei ist nicht verfugbar.\nBitte kontaktieren Sie die GIS Abteilung.", "Datei nicht verfugbar", 0) 
 pass 
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...' 
 else: 
 WTF_toolbar.enabled = True 
 print 'button re-enabled...' 
 arcpy.RefreshActiveView() 
 return 

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> 
 <Commands> 
 <Button caption="Fish" category="WTF" class="FishButton" id="WTF_addin.fish_button" image="" message="" tip=""><Help heading="" /></Button> 
 </Commands> 
 <Extensions> 
 <Extension autoLoad="true" category="WTF" class="changeToolState" description="" id="WTF_addin.disable" name="Disable" productName="Disable" showInExtensionDialog="true" /> 
 </Extensions> 
 <Toolbars> 
 <Toolbar caption="WTF_Toolbar" category="WTF" id="WTF_addin.WTF_toolbar" showInitially="true"><Items><Menu refID="WTF_addin.cat_menu" /></Items></Toolbar> 
 </Toolbars> 
 <Menus> 
 <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> 
 </Menus> 
 </ArcMap></AddIn></ESRI.Configuration> 
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Apr 27, 2016 at 7:32

1 Answer 1

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

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
answered Apr 27, 2016 at 12:40
2
  • Thanks -- trying to disable the entire toolbar. The print statements were copied in from somewhere else. 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

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.