Select to view content in your preferred language

How to import a python toolbox?

17920
15
Jump to solution
11-01-2013 06:54 AM
ionarawilson1
Deactivated User
Can anybody tell me how to import a python toolbox and access the parameter of a tool inside the toolbox?

I have started importing the toolbox using the ImportToolbox function but I am not sure if this is correct:

    def onSelChange(self, selection):          ptoolbox = arcpy.ImportToolbox("D:/ArcGISData/SARS/Python_10April2013/Toolbox.pyt")
Tags (2)
0 Kudos
15 Replies
RhettZufelt
MVP Notable Contributor

Nowhere in the documentation for ImportToolbox does it say to use arcpy.alias.toolname().  It says to use arcpy.toolname_alias().  Your syntax works, the syntax in the documentation does not, which is what led me here.  Thanks for the tip, however you discovered it.

That explains it.  I had to make the alias and the name identical to get it to work.  Next time, I'll try it backwards from the documentation.

R_

AndrewMoffitt
Frequent Contributor

I'd like to add that the toolbox name cannot contain spaces, so far as I can tell. 

0 Kudos
ShaunWalbridge
Esri Regular Contributor

It works fine with spaces, if you're running into issues, post a code snippet and we can take a look. Here's an example of an import which works fine on my end:

arcpy.ImportToolbox(r'z:\pyt with spaces\more spaces.pyt')‍‍
# <module 'touche'>
AndrewMoffitt
Frequent Contributor

For me, it was a non-python toolbox that caused the spacing issue. (I think. Now I'm second-guessing what I did to fix it).

0 Kudos
ShaunWalbridge
Esri Regular Contributor

OK, if you see the same behavior again, post it to GeoNet and we can see what's going on.

Cheers, Shaun

ionarawilson1
Deactivated User
Thanks Jason
0 Kudos