3

I have a Python add-in that includes an extension class. The only purpose of this extension is for some buttons in the add-in to be automatically enabled/disabled depending on if there are relevant layers in the current MXD's table on contents (by using the extension's itemAdded() and itemDeleted() functions).

Therefore I need this extension to be loaded automatically AND enabled when this add-in is installed.

In the config.xml, I have autoLoad="true". In the Python class, the __init__ function for the extension class includes:

self.enabled = True

I thought this should be enough for it to work as I wanted.

However, when I install the add-in and re-launch ArcMap, the extensions dialog shows the extension but NOT checked.

Now, I have found that if I run something like:

myExtension.enabled = True

Within the __init__ method of some other toolbar class (eg, one of the buttons, NOT the extension class), then the extension IS CHECKED in the extensions dialog when ArcMap is re-launched! However, it doesn't actually work - it's functions are not called. But, if I then quit ArcMap and restart ArcMap, the extension is both checked in the dialogue AND fully functional (presumably because it remained enabled from the previous run of ArcMap).

So I can get the desired behaviour ONLY if I do ALL of the following ODD things:

  • enable the extension in the class of some other add-in button (NOT just in the extension class itself)
  • launch ArcMap
  • quit ArcMap
  • launch ArcMap

After that it works fine on subsequent launches of ArcMap.

Is it possible to get a Python add-in extension to automatically load and be enabled by default when the add-in is installed by any other means, and to have it work the first time ArcMap is launched after the add-in is installed?

Ie, is there a correct way to get an extension to be fully functional immediately after an add-in is installed (and ArcMap re-launched once) without any other manual interaction from the user? Or is this behaviour simply not supported?

Your Answer

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

Browse other questions tagged or ask your own question.