'NoneType' object when calling a toolbox method problem

929
2
08-11-2014 12:28 PM
PeterLen
Occasional Contributor

Hello - We are using ArcGIS 10 and Python 2.6.  I have a Python script tool where I would like to call a custom-built tool.  In my tool script I import my toolbox if it has not already been imported (I check the arcpy.ListToolboxes()).

if "AddLayerToolbox" not in arcpy.ListToolboxes():

    arcpy.ImportToolbox([path to toolbox])

I then make the following call as debug:

arcpy.AddMessage(inspect.getargspec(arcpy.AddLayerToMXD_jtools))

That prints out the arguments to that tool correctly so I assume that arcpy knows about that tool now. Then I call the tool via:

arcpy.AddLayerToMXD_jtools(param1, param2)

With that call, I get the error:

Error: 'NoneType' object has no attribute 'AddLayerToMXD_jtools'

I am not sure what this really means since.  It isn't an issue with the parameter values because that would come back with a different error.  This is indicating that it can't find that tool, although I used that tool in the preceding call to print out the tool's arguments.  I tried running a test where I used one of the standard ArcGIS Toolbox methods and that seemed to run fie.

Any thoughts on what I am missing?

Thanks - Peter

0 Kudos
2 Replies
AdamCox1
Occasional Contributor II

Hi Peter, I don't have experience with adding toolboxes in that way, but it seems like it's saying that arcpy is a None (null) value, or NoneType object.  Where a layer object has attributes like .visible or .isGroupLayer, a NoneType object does not have an attribute .AddLayerToMXD_jtools.  So it seems like there's something weird with the way you're referring to arcpy...  Maybe in part of the script that's not shown?  Try printing arcpy, or help(arcpy) just before you call that custom function to see what happens.  Hope this is helpful...

0 Kudos
PattiHaggerty
New Contributor III

Hi

I had a problem importing a python toolbox (downloaded from ESRI) from a script using the arcpy.Importbox command and ended up getting an ESRI tech or two working on the problem.  It turned out that I could not import any python toolboxes from a script, though they worked fine from the desktop. I had 64 bit python installed by default in our setup so we could use 64 bit geoprocessing but the custom python tool boxes required 32 bit python.  When I ran my same script using 32 bit python, it imported the toolbox just fine and the script ran without incident.

Patti