def onSelChange(self, selection): ptoolbox = arcpy.ImportToolbox("D:/ArcGISData/SARS/Python_10April2013/Toolbox.pyt")
arcpy.ImportToolbox(r"C:\Users\me\my.pyt") arcpy.mynewtools.MyTool("a", "b", "c")
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).
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<SPAN class="punctuation token">.</SPAN>ImportToolbox<SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">'z:\pyt with spaces\more spaces.pyt'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># <module 'touche'></SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN></SPAN>
I'd like to add that the toolbox name cannot contain spaces, so far as I can tell.
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_
Python toolboxes should not be considered isolated from your data management and analysis workflow. Many of us have a desire to use the functionality in our python toolboxes in conjunction with our other arcpy code. You could build an easy to import companion .py file to hold your toolbox business logic next to your actual toolbox (ie. myTbx.pyt and myTbxFunctions.py), however, pyt files can be accessed and used in your interpreter or IDE by using imp. The example below shows this with our metadataUpdateItems tool. There are a couple important things to note if using pyt outside of ArcCatalog:
import imp def getParamByName(params, name): outParam = None for param in params: if param.name == name: outParam = param #import toolbox myTbx = imp.load_source('t',r'C:\dsCode\toolboxes\myTbx.pyt') #build the toolbox parameter objects list params = myTbx.metadataUpdateItems().getParameterInfo() #retrieve the parameter to update and change its value inLyr = getParamByName(params, 'inLyr') inLyr.value = 'C:\\temp\mySDElyr' #update the parameters #Note: the second argument is a runAsFunction binary T/F # this is to bypass the parameter.altered or parameter.validated checks of the updateParameters code myTbx.metadataUpdateItems().updateParameters(params,True) #update a list parameter agolTags = getParamByName(params, 'agolTags') agolTags.values = [u'wildlife (open data)'] #execute the toolbox myTbx.metadataUpdateItems().execute(params, None)
Even using the latest documentation:
ImportToolbox—Help | ArcGIS for Desktop
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.