CheckOutExtension and ImportXMLWorkspaceDocument problem

2230
4
Jump to solution
06-29-2016 07:24 AM
PaulHacker2
New Contributor II


I am copying GDB extensions from XML templates.

I am making a Python Toolbox from a Python script that runs perfectly if I run it alone using Python IDLE.

Now when running the tool it works fine except for the last, where I import the XML to overlay the GDB I created.

I get the error:

Traceback (most recent call last):

  File "<string>", line 282, in execute

  File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\management.py", line 1196, in ImportXMLWorkspaceDocument

    raise e

ExecuteError: Failed to execute. Parameters are not valid.

ERROR 000824: The tool is not licensed.

Failed to execute (ImportXMLWorkspaceDocument).

I suspect I do not have a license for the ImportXMLWorkspaceDocument.

I understand I can check with 'arcpy.CheckExtension' and if there is one I can use 'arcpy.CheckOutExtension' and 'arcpy.CheckInExtension'

But what group is ImportXMLWorkspaceDocument part of? Is it 'Spatial'? 'Datareviewer'? or what?

I have the list but don't know what part ImportXMLWorkspaceDocument belongs to.

Thanks.

0 Kudos
1 Solution

Accepted Solutions
Luke_Pinner
MVP Regular Contributor

You don't need to check out an extension, you need to ensure your ArcMap/Catalog is using a standard (aka arceditor) or advanced (aka arcinfo) level license, see Import XML Workspace Document—Help | ArcGIS for Desktop

In your python toolbox, use the arcpy.ProductInfo() function in the "isLicensed" method in your tool to disable the tool if ArcMap/Catalog is using a basic/arcview license.

import arcpy

class Toolbox(object):

    def __init__(self):

        self.label = "Toolbox"

        self.alias = ""

        # List of tool classes associated with this toolbox

        self.tools = [Tool]

class Tool(object):

    init code etc...

    def isLicensed(self):

        """Set whether tool is licensed to execute."""

        return arcpy.ProductInfo() != u'ArcView'

The reason your code works when run from Python/IDLE is that when you import arcpy *from outside ArcGIS*, it will automatically grab the highest available license level (i.e it will try advanced if available, standard if not or basic if all else fails).  You can specify what license level you want by using "import arcview, arcpy" or "import arceditor, arcpy" etc... NOTE: You can not use this method in your tool to change your current license level*

*You might be able to work around this by ensuring the script is run outside of the current ArcGIS process (maybe using background geoprocessing, or the subprocess module to force a new python process), and then setting your license level in the script to standard or advanced.

View solution in original post

4 Replies
Luke_Pinner
MVP Regular Contributor

You don't need to check out an extension, you need to ensure your ArcMap/Catalog is using a standard (aka arceditor) or advanced (aka arcinfo) level license, see Import XML Workspace Document—Help | ArcGIS for Desktop

In your python toolbox, use the arcpy.ProductInfo() function in the "isLicensed" method in your tool to disable the tool if ArcMap/Catalog is using a basic/arcview license.

import arcpy

class Toolbox(object):

    def __init__(self):

        self.label = "Toolbox"

        self.alias = ""

        # List of tool classes associated with this toolbox

        self.tools = [Tool]

class Tool(object):

    init code etc...

    def isLicensed(self):

        """Set whether tool is licensed to execute."""

        return arcpy.ProductInfo() != u'ArcView'

The reason your code works when run from Python/IDLE is that when you import arcpy *from outside ArcGIS*, it will automatically grab the highest available license level (i.e it will try advanced if available, standard if not or basic if all else fails).  You can specify what license level you want by using "import arcview, arcpy" or "import arceditor, arcpy" etc... NOTE: You can not use this method in your tool to change your current license level*

*You might be able to work around this by ensuring the script is run outside of the current ArcGIS process (maybe using background geoprocessing, or the subprocess module to force a new python process), and then setting your license level in the script to standard or advanced.

View solution in original post

PaulHacker2
New Contributor II

Ok, I find we don't have the advanced licenses and thus running it strait by python tools won't do.

So, since it works perfectly outside using python IDLE how does one set the parameters in the tools and then 'batch' it to run? That is using the same pyt script I have in the toolbox to input all the parameters and then send them to a batch .py script to run with IDLE?

Thanks,

Paul

0 Kudos
Luke_Pinner
MVP Regular Contributor

There are only two possibilities:

  1. If you don't have advanced or standard licenses available, you can't use the ImportXMLWorkspaceDocument  tool.
  2. If the tool is running outside of ArcGIS, then you do have advanced or standard licenses available.

You may be having trouble switching from a basic to a standard or advanced license.

0 Kudos
PaulHacker2
New Contributor II

Ok I got it to work.

What I did was:

Make the tool create a batch .bat file with the command to run the python 2.7 and the python script to do all the processing.

Then the tool gets all the parameters via the def getParameterInfo, and uses a python template program minus the parameters.

As it creates a new temporary python script it adds the parameters to the script.

Then using subprocess.call (one uses 'import subprocess' to get access to it) run the bat file with the new temporary python script.

It created everything I desired. So the ArcMap we have does not have the advanced license but the python 2.7 under ArcGIS does!

Thanks,

Paul