import arcpy import pythonaddins import logging logger = logging.getLogger('myapp') hdlr = logging.FileHandler(r'd:\Workspace\PythonAddIns\ExtensionChecker\agstest.log') formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') hdlr.setFormatter(formatter) logger.addHandler(hdlr) logger.setLevel(logging.DEBUG) class ExtensionChecker(object): """Implementation for ExtensionChecker_addin.extcheckerext (Extension)""" def __init__(self): # For performance considerations, please remove all unused methods in this class. self.enabled = True def startup(self): logger.debug( "Fired startup") stat = arcpy.CheckExtension("3D") logger.debug(stat) stat = arcpy.CheckInExtension("3D") logger.debug(stat) pass
### see if spatial analyst extension is available for use availability = arcpy.CheckExtension("Spatial") if availability=="Available": arcpy.CheckOutExtension("Spatial") arcpy.AddMessage("SA Extension Checked out") else: arcpy.AddError("%s extension is not available (%s)"%("Spatial Analyst Extension",availability)) arcpy.AddError("Please ask someone who has it checked out but not using to turn off the extension") return #depending upon where this is located, you could also use sys.Exit() or pass/continue #.... do the necessary processing with the extension arcpy.CheckInExtension("Spatial") arcpy.AddMessage("SA Checked back in")
Hi James,
Thanks for the reply and sample code, however it doesn't solve the particular issue I am having. The issue I am having is that if I already have an extension enabled/checked out in ArcMap, I am trying to get the python code to check that license back in and show it as "unchecked" in the ArcMap extensions dialog (see the screen shot in my previous post).