[GIS] Check-out XTools Pro with arcpy

arcgis-10.3arcpyerror-000824extensionsxtools-pro

I have an arcpy script that uses a XTools Pro geoprocessing tool, which works if I run it from ArcMap (with the XTools Pro extension enabled), but if I run it outside of ArcMap I get an error.

Tool I'm running:

arcpy.ImportToolbox("C:/Program Files (x86)/DataEast/XTools Pro/Toolbox/XTools Pro.tbx")
arcpy.XToolsGP_DispersePoints_xtp(InputLayer, OutputLayer, "0.25 Meters", "1 Meters", "BY_CLUSTERS", "RING", "", "")

Error message:

arcgisscripting.ExecuteError was unhandled by user code
Message: Failed to execute. Parameters are not valid.
ERROR 000824: The tool is not licensed.
Failed to execute (XToolsGP_DispersePoints).

I have attempted to enabled this extension from arcpy with no success, and have found the XTools Pro help pages don't mention arcpy at all (so now I wonder if it's even supported).

How can I enable the XTools Pro extension from within arcpy? I've attempted to use the following, but am unsure what arcpy would call the XTools Pro extension, so may be using the incorrect Extension name. (I have tried XTools, XToolsPro, XTools-Pro, XTools Pro, xtp, XToolsGP)

if arcpy.CheckExtension("XToolsPro") == "Available":
    arcpy.CheckOutExtension("XToolsPro")
else:
    print "XTools Pro Not Available"

Best Answer

You need to load the XTools Pro toolbox using the arcpy.ImportToolbox() function. The toolbox is usually located in the C:\Program Files (x86)\DataEast\XTools Pro\Toolbox folder; assuming this is the case, add the following statement at the top of your code (after importing arcpy):

arcpy.ImportToolbox('C:\Program Files (x86)\DataEast\XTools Pro\Toolbox\XTools Pro.tbx')

If you're just using the Python window in ArcMap, just type the above into the interpreter and the toolbox will be imported.

Once the toolbox is imported, its tools are accessed using the syntax arcpy.xtp.toolname

enter image description here

Related Question