class ExtensionCheck(object): """Implementation for MyAddIn_addin.ExtensionCheck (Extension)""" def __init__(self): # For performance considerations, please remove all unused methods in this class. self.enabled = True def startup(self): from arcpy.mapping import MapDocument try: mx = MapDocument(r'C:\Users\mmaguire\AppData\Roaming\ESRI\Desktop10.1\ArcMap\Templates\Normal.mxt') pythonaddins.MessageBox('Map document is: ' + mx.filePath, 'Map Document', 0) if arcpy.CheckExtension("3D") == "Available": arcpy.CheckOutExtension("3D") arcpy.CheckInExtension("3D") pythonaddins.MessageBox('Returned 3D extension', '3D', 0) if arcpy.CheckExtension("Spatial") == "Available": arcpy.CheckOutExtension("Spatial") arcpy.CheckInExtension("Spatial") pythonaddins.MessageBox('Returned Spatial extension', 'Spatial', 0) finally: pythonaddins.MessageBox('Extension check started', 'Extension Check', 0) #Shows up mx.save() pythonaddins.MessageBox('Normal.mxt Saved', 'Extension Check', 0) #Never appears
@jamesfreddyc Thanks for your answer. First of all, I'm working with 10.1 SP1. I'm aware of the functionality and how to check in and check out extensions with python. What I don't get to work is storing this code as an Add-In or in the Normal.mxt so it automatically releases any extensions when closing down/starting a mxd. 😞
import arcgisscripting ### see if spatial analyst extension is available for use availability = gp.CheckExtension("Spatial") if availability=="Available": gp.CheckOutExtension("Spatial") gp.AddMessage("Spatial Analyst Has been checked out") else: gp.AddError("%s extension is not available (%s)"%("Spatial Analyst Extension",availability)) gp.AddError("Please ask someone who has it checked out but not using to turn off the extension") return #....do the SA work here.... ### return the Spatial Analyst Extension to the pool ### gp.CheckInExtension("Spatial") gp.AddMessage("Spatial Analyst Has been checked back in")
Membros conectados podem postar, seguir atualizações e mais. Novo aqui? Registre uma conta gratuita.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.