arcpy.CheckOutExtension -- Check out custom Extension

Discussion created by caseym on Aug 21, 2013
Latest reply on Aug 21, 2013 by curtvprice
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?


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()