+ Reply to Thread
Results 1 to 7 of 7

Thread: How to automatically release extension?

  1. #1
    Hubert Bast
    Join Date
    Aug 2012
    Posts
    5
    Points
    1
    Answers Provided
    1


    0

    Default How to automatically release extension?

    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

  2. #2
    James Crandall
    Join Date
    Apr 2010
    Posts
    780
    Points
    181
    Answers Provided
    42


    0

    Default Re: How to automatically release extension?

    What version of ArcGIS are you working with?

    Here's an example for 10:

    http://help.arcgis.com/en/arcgisdesk...0000003q000000

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

    Code:
    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")

  3. #3
    Hubert Bast
    Join Date
    Aug 2012
    Posts
    5
    Points
    1
    Answers Provided
    1


    0

    Default Re: How to automatically release extension?

    @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.

  4. #4
    James Crandall
    Join Date
    Apr 2010
    Posts
    780
    Points
    181
    Answers Provided
    42


    0

    Default Re: How to automatically release extension?

    Quote Originally Posted by basth View Post
    @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/...0000025000000/

  5. #5
    Randy .
    Join Date
    Apr 2010
    Posts
    260
    Points
    12
    Answers Provided
    0


    0

    Default Re: How to automatically release extension?

    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.

  6. #6
    Hubert Bast
    Join Date
    Aug 2012
    Posts
    5
    Points
    1
    Answers Provided
    1


    0

    Default Re: How to automatically release extension?

    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.

  7. #7
    Melanie Maguire
    Join Date
    Nov 2012
    Posts
    18
    Points
    11
    Answers Provided
    3


    0

    Default Re: How to automatically release extension?

    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.

    Code:
    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

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts