Select to view content in your preferred language

Python Addin - Extension Checkin Issue

4306
6
06-14-2013 12:53 PM
by Anonymous User
Not applicable
Original User: palavido

Hello GISers,

Our organization has a single floating license of 3D Analyst and many times people inadvertently leave it enabled. I was hoping to make a simple Python Add-in that would check the 3D Analyst license in when ArcMap opens. I made a python add-in that executes the code below to check the license in. I set up logging so I could confirm the actions were being taken. The log reports that the license has been successfully checked in, however it still remains checked (enabled) in ArcMap (see screenshot).

[ATTACH=CONFIG]25276[/ATTACH]

My question would be, is there some step in my code that I am missing or is the ChecInkExtension code only related to the scope of code execution and not the ArcMap extension GUI? I've also attached the source files for the python add-in in case anyone wants to compile and test themselves. You'll just need to change the path to the log file.


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


Thanks in advance for any help!

Matt
0 Kudos
6 Replies
JamesCrandall
MVP Frequent Contributor
I am unsure about loggin file usage, but you should be able to set up a simple if...else statement to check for availability, peform the nececssary processing and finally check the extension back in.


### 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")

0 Kudos
by Anonymous User
Not applicable
Original User: palavido

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). The python code that I wrote (and also the example you provided) executes successfully and says it checks in the extension, however if you open up the extensions dialog in ArcMap, the extension is still checked/enabled.

To recreate this try the following:

1) In ArcMap, manually enable an extension (like Spatial Analyst or 3D Analyst)
2) Run the python code to check the license in
3) Open the extensions dialog (Customize --> Extensions) in ArcMap.

Thanks,

Matt
0 Kudos
JamesCrandall
MVP Frequent Contributor
Hi Matt -- I verified the same thing you are experiencing.  Ran from a Toolbox script and it did not uncheck th SpatialAnalyst extension in the Customize-->Extensions dialog.

Not sure how to remedy this.  Sorry I am not much help on this one!
j
0 Kudos
by Anonymous User
Not applicable
Original User: swalbridge

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


As I understand, doing things in Python only modifies the arcpy environment, not the ArcMap environment itself: when you enable an extension in ArcMap, you are in effect checking it out for the duration of that ArcMap session. So, you don't need to manually 'check-in' the license unless folks are leaving ArcMap open and you want 3D analyst at times. One quick hack around this is to leave it disabled, and then use the arcpy approach you outlined to enable it in the code that you do need to use it for, and check it back in. I'm not an expert in this area, but this is my best understanding from reading the documentation.
0 Kudos
MatthewPalavido
Deactivated User
Shaun,

Thanks for the reply. That's what I kind of figured, but was hoping otherwise. I guess I'll just have to go the VB .NET route for the add-in so I can interact with the ArcMap GUI via ArcObjects.

Thanks again!

Matt
0 Kudos
by Anonymous User
Not applicable
Original User: swalbridge

If you do want to stick with Python, you could probably hack something up using a few ingredients: the list of CLSIDs for extensions, the spot in the registry those are stored (HKEY_USERS\...\Software\Esri\Desktop10.1\ArcMap\Extensions), and then run an escalated process that updates the registry. If you already have skill with ArcObjects, that's probably the easiest and safest approach, but I figured I'd mention this for completeness.
0 Kudos