I've got a weird problem. My addin throws problems intermittently where it doesn't recognize buttons or tools when I try to toggle the visibility in my code. It seems as though the objects aren't instantiated as trying to toggle them works after I try to interact with them. What is the problem and how do I begin to debug it? My code is far too long to post but if there's something I can provide to help can you let me know?

Here's a scenario:

User starts Arc and clicks a button. The button tries to enable another button with:

anotherButton.enabled = False

Arc throws an error:

global variable "anotherButton" not defined.

User clicks on "anotherButton" and then tries the first button again. This time the command executes and "anotherButton" is disabled.


The add-in framework usually won't create the objects until it needs them. I have a solution in this Esri forums thread: create them yourself at load time, so you'd have something like

anotherButton = anotherButtonClass()

at the bottom of your add-in's main .py file to make sure it's around.

| improve this answer | |
  • wow! Thank you. I can't tell you how many hours I scoured the internet looking for this solution. – ShaunLangley Nov 18 '13 at 17:43
  • @Jason Is this behavior similar to the "onDemand" property of .NET add-in types? I would generally set "onDemand" to false to avoid such problems. – blah238 Nov 19 '13 at 0:22
  • 1
    Exactly the same. The Python add-in framework shares a lot of the same code with the .Net add-in framework. – Jason Scheirer Nov 19 '13 at 1:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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