Select to view content in your preferred language

arcpy.CheckOutExtension -- Check out custom Extension

1154
2
08-21-2013 10:03 AM
CaseyMcLaughlin
Deactivated User
I've created a simple Python Add-in extension for taking a value from the mxd name and using it in a definition query.  The map automatically opens to the area of interest as specified in the title.  I have a startup() event which checks for the custom extension and gives a warning that it should be turned on. 

Can I turn on a custom extension if it isn't already on?

arcpy.CheckInExtension("CustomName")

returns : u'Unrecongized extension code CusstomName'

If i don't have the extension on, the openDocument() event listener doesn't listen.....
My basic openDocument code is below.  If I can't turn on my extension, is there another way to get this done automatically for the user?

    def openDocument(self):
        mxd = arcpy.mapping.MapDocument('current')
        mxd_name = mxd.filePath
        ##Only try this if its a TMDL document or in the TMDL directory?
        if mxd_name.find("TMDL") > 0:
            mxd_name = mxd_name.replace(' ', '')[:-4].upper()
            mxd_name_len = len(mxd_name)
            huc = mxd_name[(mxd_name_len - 8): mxd_name_len]
            df = mxd.activeDataFrame
            lyr = arcpy.mapping.ListLayers(mxd, "8 Digit HUC", df)[0]
            lyr.definitionQuery = u"HUC_ID ='" + huc + "'"
            df.extent = lyr.getExtent()
            arcpy.RefreshActiveView()
        return
Tags (2)
0 Kudos
2 Replies
DaveBarrett
Deactivated User
Hi,

Not had too much experience with this as yet but from what I have read the check in / out extension is not the way to go. Think you need to ensure that the enabled property in the extension class is set to true. This can be set in you openDocument method. Think this help doc should be useful

http://resources.arcgis.com/en/help/main/10.2/#/Application_Extension/014p00000019000000/


Dave
0 Kudos
curtvprice
MVP Alum
I believe Dave is spot on. arcpy.CheckOutExtension checks out licenses.

For example, I have XTools installed, and although there is a checkbox to enable it or disable it in Customize/Extensions,  it not supported by CheckOutExtension.

I think this is the key sentence in the help article Dave linked:

Application extensions can be configured to load when needed or automatically when their associated application is started; extensions can also be configured to appear in the standard ArcGIS Extensions dialog box located under the Customize menu.
0 Kudos