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.
1 Answer 1
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.
-
wow! Thank you. I can't tell you how many hours I scoured the internet looking for this solution.ShaunLangley– ShaunLangley2013年11月18日 17:43:06 +00:00Commented Nov 18, 2013 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– blah2382013年11月19日 00:22:12 +00:00Commented Nov 19, 2013 at 0:22
-
1Exactly the same. The Python add-in framework shares a lot of the same code with the .Net add-in framework.Jason Scheirer– Jason Scheirer2013年11月19日 01:46:10 +00:00Commented Nov 19, 2013 at 1:46