<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to import a python toolbox? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445647#M34897</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'd like to add that the toolbox name cannot contain spaces, so far as I can tell.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 17 Mar 2017 17:29:32 GMT</pubDate>
    <dc:creator>AndrewMoffitt</dc:creator>
    <dc:date>2017-03-17T17:29:32Z</dc:date>
    <item>
      <title>How to import a python toolbox?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445635#M34885</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Can anybody tell me how to import a python toolbox and access the parameter of a tool inside the toolbox?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have started importing the toolbox using the ImportToolbox function but I am not sure if this is correct:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def onSelChange(self, selection): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ptoolbox = arcpy.ImportToolbox("D:/ArcGISData/SARS/Python_10April2013/Toolbox.pyt")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Nov 2013 13:54:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445635#M34885</guid>
      <dc:creator>ionarawilson1</dc:creator>
      <dc:date>2013-11-01T13:54:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to import a python toolbox?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445636#M34886</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That is how you import a toolbox. What do you mean "access the parameters"? What are you trying to do?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Nov 2013 15:52:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445636#M34886</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2013-11-01T15:52:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to import a python toolbox?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445637#M34887</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I would like to change the values of a tool parameter. How can I do that?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Nov 2013 18:09:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445637#M34887</guid>
      <dc:creator>ionarawilson1</dc:creator>
      <dc:date>2013-11-01T18:09:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to import a python toolbox?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445638#M34888</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You can't. The Python toolbox objects are isolated from your Python interpreter.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Nov 2013 19:25:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445638#M34888</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2013-11-01T19:25:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to import a python toolbox?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445639#M34889</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;So, there is no way&amp;nbsp; to access a tool parameter if not inside a toolbox? What can I access when I import the toolbox?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Nov 2013 19:35:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445639#M34889</guid>
      <dc:creator>ionarawilson1</dc:creator>
      <dc:date>2013-11-01T19:35:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to import a python toolbox?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445640#M34890</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;When you import the toolbox you can call the tools.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Nov 2013 19:46:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445640#M34890</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2013-11-01T19:46:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to import a python toolbox?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445641#M34891</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;How? Can you show me an example? Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Nov 2013 20:48:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445641#M34891</guid>
      <dc:creator>ionarawilson1</dc:creator>
      <dc:date>2013-11-01T20:48:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to import a python toolbox?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445642#M34892</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Say you have a tool called &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;MyTool &lt;/SPAN&gt;&lt;SPAN&gt;in &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;C:\Users\me\my.pyt&lt;/SPAN&gt;&lt;SPAN&gt; and you've given the toolbox the alias &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;mynewtools&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;arcpy.ImportToolbox(r"C:\Users\me\my.pyt") arcpy.mynewtools.MyTool("a", "b", "c")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A class="jive-link-external-small" href="http://resources.arcgis.com/en/help/main/10.1/index.html#//018v0000005z000000" rel="nofollow" target="_blank"&gt;This is all very clearly documented in the help&lt;/A&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Nov 2013 21:00:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445642#M34892</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2013-11-01T21:00:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to import a python toolbox?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445643#M34893</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Jason&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Nov 2013 13:55:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445643#M34893</guid>
      <dc:creator>ionarawilson1</dc:creator>
      <dc:date>2013-11-05T13:55:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to import a python toolbox?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445644#M34894</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Nowhere in the documentation for ImportToolbox does it say to use arcpy.alias.toolname().&amp;nbsp; It says to use arcpy.toolname_alias().&amp;nbsp; Your syntax works, the syntax in the documentation does not, which is what led me here.&amp;nbsp; Thanks for the tip, however you discovered it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Even using the latest documentation:&lt;/P&gt;&lt;P&gt;&lt;A href="http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-functions/importtoolbox.htm" title="http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-functions/importtoolbox.htm"&gt;ImportToolbox—Help | ArcGIS for Desktop&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Apr 2015 21:02:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445644#M34894</guid>
      <dc:creator>TedChapin</dc:creator>
      <dc:date>2015-04-15T21:02:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to import a python toolbox?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445645#M34895</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;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&amp;nbsp; (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:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;python toolbox parameters have a valueAsText attribute that is set when running via ArcCatalog and will not be created when building the arcpy.parameter object in this manner.&lt;UL&gt;&lt;LI&gt;The alternative to valueAsText is to interpret the .value attribute as a string where needed&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;Additional arcpy.parameter attributes are updated in ArcCatalog including, but not limited to, param.altered or param.hasBeenValidated, in the case below we added a variable to bypass those checks when not using in arcCatalog&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import imp

def getParamByName(params, name):
&amp;nbsp;&amp;nbsp;&amp;nbsp; outParam = None
&amp;nbsp;&amp;nbsp;&amp;nbsp; for param in params:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if param.name == name:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 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)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:54:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445645#M34895</guid>
      <dc:creator>AdamMesser1</dc:creator>
      <dc:date>2021-12-11T19:54:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to import a python toolbox?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445646#M34896</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Nowhere in the documentation for ImportToolbox does it say to use arcpy.alias.toolname().&amp;nbsp; It says to use arcpy.toolname_alias().&amp;nbsp; Your syntax works, the syntax in the documentation does not, which is what led me here.&amp;nbsp; Thanks for the tip, however you discovered it.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That explains it.&amp;nbsp; I had to make the alias and the name identical to get it to work.&amp;nbsp; Next time, I'll try it backwards from the documentation.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Sep 2015 17:16:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445646#M34896</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2015-09-08T17:16:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to import a python toolbox?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445647#M34897</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'd like to add that the toolbox name cannot contain spaces, so far as I can tell.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Mar 2017 17:29:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445647#M34897</guid>
      <dc:creator>AndrewMoffitt</dc:creator>
      <dc:date>2017-03-17T17:29:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to import a python toolbox?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445648#M34898</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ImportToolbox&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;r&lt;SPAN class="string token"&gt;'z:\pyt with spaces\more spaces.pyt'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍‍
&lt;SPAN class="comment token"&gt;# &amp;lt;module 'touche'&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:54:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445648#M34898</guid>
      <dc:creator>ShaunWalbridge</dc:creator>
      <dc:date>2021-12-11T19:54:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to import a python toolbox?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445649#M34899</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For me, it was a non-python toolbox that caused the spacing issue. (I&amp;nbsp;&lt;EM&gt;think&lt;/EM&gt;. Now I'm second-guessing what I did to fix it).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Mar 2017 20:59:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445649#M34899</guid>
      <dc:creator>AndrewMoffitt</dc:creator>
      <dc:date>2017-03-23T20:59:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to import a python toolbox?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445650#M34900</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OK, if you see the same behavior again, post it to GeoNet and we can see what's going on.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers, Shaun&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Mar 2017 04:01:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-import-a-python-toolbox/m-p/445650#M34900</guid>
      <dc:creator>ShaunWalbridge</dc:creator>
      <dc:date>2017-03-24T04:01:04Z</dc:date>
    </item>
  </channel>
</rss>

