How to automatically release extension?

2667
6
12-04-2012 12:41 AM
HubertBast
New Contributor II
Good morning,

I'm trying to find a way to automatically release extensions like SA or 3D. The reason being that when I'm working with an extension (concurrent license) and don't explicitly un-tick it before closing the mxd, it will automatically grab it next time I open a mxd, i.e. it seems to be stored in the Normal.mxt. As you can imagine, this many times happens to users in our organisation without them being aware of it and as a result all licenses are in use.
I've tried to write a python Add-In to release the extensions whenever I open or close a mxd. But it doesn't work. I remember having written a VBA macro saved in the Normal.mxt which was very straight forward and worked fine every time. However, this easy method is not possible in python anymore as far as I'm aware of. If anybody has faced the same problem, but was more successful than me, I'd very much appreciate to hear about his/her solution.

Many Thanks,
Hubert
Tags (2)
0 Kudos
6 Replies
JamesCrandall
MVP Frequent Contributor
What version of ArcGIS are you working with?

Here's an example for 10:

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v0000003q000000

I am still on ArcGIS 9.3.1 and here is some sample from one of my arcgisscripting(9.3) implementations:

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")
          
0 Kudos
HubertBast
New Contributor II
@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. 😞
0 Kudos
JamesCrandall
MVP Frequent Contributor
@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. 😞




http://resources.arcgis.com/en/help/main/10.1/index.html#/What_is_a_Python_add_in/014p00000025000000...
0 Kudos
RandyKreuziger
Occasional Contributor III
James, can Add-Ins be triggered automatically when ArcMap is closed?  If not it doesn't do what basth needs to do.  I too had a VBA script to close all shared extensions saved in the Normal.mxt that was trigged by the closing of ArcMap.  But that was back in the 9.x days.
0 Kudos
HubertBast
New Contributor II
Thanks, kreuzrsk, that's exactly what I'm after.
I've written a Python add-in application extension which in a nutshell uses:

arcpy.CheckInExtension("3D") - and the same for Spatial Analyst ("SA")

And for the "Method s to Implement" in the Python Wizard I've selected "closeDocument", "openDocument" and "newDocument" which should act as the trigger points to run the add in. All that sounds really simple, but that doesn't seem to work at all. Licenses are kept in the Normal.mxt when closing down and opening up an mxd.
We have now installed the VBA SDK for 10.1 and if there is no solution with python add-ins I'll have to dig out my old VBA script form the 9.x days and hope it will work.
0 Kudos
MelanieMaguire
New Contributor III
I'm interested in this solution as well.  Besides the attempts listed above, I tried checking the extensions in during my extension startup event and saving the Normal.mxt file after checking in the extensions.  I temporarily added a bunch of message boxes to my script so I could track what was happening.  (I will remove them once my script is running correctly).  My message boxes showed the extensions are being checked in, but that the MapDocument.save() is not taking place. 

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
0 Kudos