<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to control state of buttons in Python Add-In? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-control-state-of-buttons-in-python-add-in/m-p/622548#M48462</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I am only getting following error:&lt;BR /&gt;Python: NameError: global name 'button1' is not defined&lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's my shot-in-the-dark answer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you by any chance have the button1 on a menu within a toolbar? If so, the button doesn't initialize until the menu is clicked. Here's what I'm experiencing with a button/tool issue of my own. The tool is on the toolbar, a menu is on the toolbar, and the button is in the menu.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Start ArcMap and open the map document. Click the menu name, then use the tool - the enabled property of the button works fine.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Start ArcMap and open the map document. Click the tool and I get the error message "global name 'printButton' is not defined.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Since the menu isn't controlled in the Python script, I don't see a fix.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;David Allen&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 03 Jul 2013 18:38:38 GMT</pubDate>
    <dc:creator>DavidAllen</dc:creator>
    <dc:date>2013-07-03T18:38:38Z</dc:date>
    <item>
      <title>How to control state of buttons in Python Add-In?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-control-state-of-buttons-in-python-add-in/m-p/622542#M48456</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have bunch of buttons to perform separate tasks within a Python Add-In. Buttons are greyed out and required to be enabled after initial tools run. In the following example, tool1 is turned off after execution using its ID and button1 is enabled. Classes are arranged alphabetically at the time of Add-In construction. This configuration of classes works sometimes and fails at others with message: "NameError: global name 'button1' is not defined". This is confusing as to why it runs sometimes and fails at others. Can anyone please help with explanation as to why is it the case and how to better control the state of buttons without error?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;class Calc(object): &amp;nbsp;&amp;nbsp;&amp;nbsp; """Implementation for test_addin.button1 (Button)""" &amp;nbsp;&amp;nbsp;&amp;nbsp; def __init__(self): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.enabled = False &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.checked = False &amp;nbsp;&amp;nbsp;&amp;nbsp; def onClick(self): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; """do something"""&amp;nbsp; class process(object): &amp;nbsp;&amp;nbsp;&amp;nbsp; """Implementation for test_addin.tool1 (Tool)""" &amp;nbsp;&amp;nbsp;&amp;nbsp; def __init__(self): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.enabled = True &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.cursor = 3&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; def onMouseDownMap(self, x, y, button, shift): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; """do something"""&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tool1.enabled = False &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; button1.enabled = True&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Jul 2013 14:00:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-control-state-of-buttons-in-python-add-in/m-p/622542#M48456</guid>
      <dc:creator>IbraheemKhan1</dc:creator>
      <dc:date>2013-07-02T14:00:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to control state of buttons in Python Add-In?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-control-state-of-buttons-in-python-add-in/m-p/622543#M48457</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Please paste a full traceback(s) as it appears in the Python window.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Jul 2013 14:52:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-control-state-of-buttons-in-python-add-in/m-p/622543#M48457</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2013-07-02T14:52:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to control state of buttons in Python Add-In?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-control-state-of-buttons-in-python-add-in/m-p/622544#M48458</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Please paste EVERYTHING that appears in the Python window, not just the error type.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Attached is a simple add-in that does what yours does, and it seems to work fine. I suggest you re-make your addin's .py file from the wizard and try again.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Jul 2013 15:58:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-control-state-of-buttons-in-python-add-in/m-p/622544#M48458</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2013-07-02T15:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to control state of buttons in Python Add-In?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-control-state-of-buttons-in-python-add-in/m-p/622545#M48459</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am only getting following error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Python: NameError: global name 'button1' is not defined&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is it because of the fact that there are many different classes between "tool1" and "button1", in actual -- Just guessing.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Jul 2013 23:49:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-control-state-of-buttons-in-python-add-in/m-p/622545#M48459</guid>
      <dc:creator>IbraheemKhan1</dc:creator>
      <dc:date>2013-07-02T23:49:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to control state of buttons in Python Add-In?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-control-state-of-buttons-in-python-add-in/m-p/622546#M48460</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Check the python prompt, type &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;YourAddIn_addin.&lt;/SPAN&gt;&lt;SPAN&gt; (where the module name is the same as the filename without the .py extension) and see if there is auto-complete. Is the button1 variable there? See if you can create it yourself, if you can make a &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;YourAddinIn_addin.Calc()&lt;/SPAN&gt;&lt;SPAN&gt; or if it throws an exception.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jul 2013 15:20:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-control-state-of-buttons-in-python-add-in/m-p/622546#M48460</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2013-07-03T15:20:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to control state of buttons in Python Add-In?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-control-state-of-buttons-in-python-add-in/m-p/622547#M48461</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If I correctly understood what you have said, &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I typed "YourAddinIn_addin" in Python interactive window and it returned:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;module 'YourAddinIn_addin' from 'C:\Users\Ibe\AppData\Local\ESRI\Desktop10.1\AssemblyCache\{301A358E-60E7-0717-8A9E-86368EAA3D1F}\YourAddinIn_addin.py'&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;but "YourAddinIn_addin.Calc()" throws back:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Runtime error &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "&amp;lt;string&amp;gt;", line 1, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;AttributeError: 'module' object has no attribute 'Calc'&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jul 2013 16:45:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-control-state-of-buttons-in-python-add-in/m-p/622547#M48461</guid>
      <dc:creator>IbraheemKhan1</dc:creator>
      <dc:date>2013-07-03T16:45:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to control state of buttons in Python Add-In?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-control-state-of-buttons-in-python-add-in/m-p/622548#M48462</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I am only getting following error:&lt;BR /&gt;Python: NameError: global name 'button1' is not defined&lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's my shot-in-the-dark answer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you by any chance have the button1 on a menu within a toolbar? If so, the button doesn't initialize until the menu is clicked. Here's what I'm experiencing with a button/tool issue of my own. The tool is on the toolbar, a menu is on the toolbar, and the button is in the menu.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Start ArcMap and open the map document. Click the menu name, then use the tool - the enabled property of the button works fine.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Start ArcMap and open the map document. Click the tool and I get the error message "global name 'printButton' is not defined.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Since the menu isn't controlled in the Python script, I don't see a fix.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;David Allen&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jul 2013 18:38:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-control-state-of-buttons-in-python-add-in/m-p/622548#M48462</guid>
      <dc:creator>DavidAllen</dc:creator>
      <dc:date>2013-07-03T18:38:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to control state of buttons in Python Add-In?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-control-state-of-buttons-in-python-add-in/m-p/622549#M48463</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;So it appears as though the Calc class does not exist. What does &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;dir(YourAddinIn_addin)&lt;/SPAN&gt;&lt;SPAN&gt; tell you? Can you run the .py file on its own from python.exe without syntax errors?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jul 2013 21:47:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-control-state-of-buttons-in-python-add-in/m-p/622549#M48463</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2013-07-03T21:47:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to control state of buttons in Python Add-In?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-control-state-of-buttons-in-python-add-in/m-p/622550#M48464</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;So it appears as though the Calc class does not exist. What does &lt;SPAN style="font-family:Courier New;"&gt;dir(YourAddinIn_addin)&lt;/SPAN&gt; tell you? Can you run the .py file on its own from python.exe without syntax errors?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dir(YourAddinIn_addin) returns various ArcGIS builtin functions including classes, functions, and modules that I am using in my AddIn. There were few global name definition errors during running *.py file from Install folder using python.exe&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It is strange that solution proposed above by David works. So we have to initialize buttons first before clicking on tools, any idea why is it the case?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jul 2013 22:15:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-control-state-of-buttons-in-python-add-in/m-p/622550#M48464</guid>
      <dc:creator>IbraheemKhan1</dc:creator>
      <dc:date>2013-07-03T22:15:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to control state of buttons in Python Add-In?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-control-state-of-buttons-in-python-add-in/m-p/622551#M48465</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It's an optimization in the Add-In framework which makes less sense in Python than it does in C# Add-Ins: it only creates the objects when it needs them.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A class="jive-link-external-small" href="http://forums.arcgis.com/threads/87894-Python-Add-in-puzzler-with-menus-on-a-toolbar" rel="nofollow" target="_blank"&gt;My response in this thread&lt;/A&gt;&lt;SPAN&gt; should give a workaround -- basically, it pre-initializes your button variables.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jul 2013 22:31:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-control-state-of-buttons-in-python-add-in/m-p/622551#M48465</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2013-07-03T22:31:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to control state of buttons in Python Add-In?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-control-state-of-buttons-in-python-add-in/m-p/622552#M48466</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;It's an optimization in the Add-In framework which makes less sense in Python than it does in C# Add-Ins: it only creates the objects when it needs them.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums.arcgis.com/threads/87894-Python-Add-in-puzzler-with-menus-on-a-toolbar"&gt;My response in this thread&lt;/A&gt; should give a workaround -- basically, it pre-initializes your button variables.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It worked. Thanks.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Jul 2013 00:27:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-control-state-of-buttons-in-python-add-in/m-p/622552#M48466</guid>
      <dc:creator>IbraheemKhan1</dc:creator>
      <dc:date>2013-07-05T00:27:00Z</dc:date>
    </item>
  </channel>
</rss>

