erath

How to use arcpy.RemoveToolbox (toolbox) using the toolbox alias

Discussion created by erath on Aug 13, 2013
The help documentation says that the tool "Removes the specified toolbox, either by specifying its path or referencing its alias." The example in the help shows how to use the tool with the full pathname, but not using the alias. I want to write a script that removes a custom python toolbox using the toolbox alias instead of the path, but I cannot get it to work.

This is how it is supposed to work:


import arcpy

def print_custom_tbxs():
        toolboxes = arcpy.ListToolboxes()
        provided_toolboxes = ["3D Analyst Tools(3d)", "Analysis Tools(analysis)", "Coverage Tools(arc)", "Cartography Tools(cartography)", "Conversion Tools(conversion)", "Data Interoperability Tools(interop)", "Data Management Tools(management)", "Editing Tools(edit)", "Geocoding Tools(geocoding)", "Geostatistical Analyst Tools(ga)", "Linear Referencing Tools(lr)", "Multidimension Tools(md)", "Network Analyst Tools(na)", "Parcel Fabric Tools(fabric)", "Samples(samples)", "Schematics Tools(schematics)", "Server Tools(server)", "Spatial Analyst Tools(sa)", "Spatial Statistics Tools(stats)", "Tracking Analyst Tools(ta)"]
        print "Imported toolboxes:"
        for toolbox in toolboxes:
            if toolbox not in provided_toolboxes:
                print toolbox

print_custom_tbxs()
print
arcpy.ImportToolbox(r"E:\Tools\General_Tools.pyt")
print_custom_tbxs()
print
arcpy.RemoveToolbox(r"E:\Tools\General_Tools.pyt")
print_custom_tbxs()
print


The above code produces the below print statements:

>>>
Imported toolboxes:

Imported toolboxes:
General_Tools(gen)

Imported toolboxes:

>>>

But then I replace the RemoveToolbox line and use the toolbox alias instead of the full pathname, and none of these lines work:

arcpy.RemoveToolbox("General_Tools_gen")
arcpy.RemoveToolbox("gen")
arcpy.RemoveToolbox("General Tools (gen)")
arcpy.RemoveToolbox("(gen)")
arcpy.RemoveToolbox("General Tools - gen")



I get this error:

>>>
Imported toolboxes:

Imported toolboxes:
General_Tools(gen)

Traceback (most recent call last):
File "E:\Python_scripts\ImportToolbox\ToolboxImportCheck_forum_question.py", line 15, in <module>
arcpy.RemoveToolbox("gen")
File "C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\__init__.py", line 746, in RemoveToolbox
return gp.removeToolbox(toolbox)
File "C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 274, in removeToolbox
self._gp.RemoveToolbox(*gp_fixargs(args, True)))
RuntimeError: ERROR 999999: Error executing function.
>>>

Why doesn't this work? Am I using the wrong syntax?

Outcomes