<?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: Call function from script inserted in Toolbox in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/call-function-from-script-inserted-in-toolbox/m-p/5271#M465</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The problem arises when I import the scripts in the Toolbox.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 20 Oct 2018 15:38:09 GMT</pubDate>
    <dc:creator>AretiSamara2</dc:creator>
    <dc:date>2018-10-20T15:38:09Z</dc:date>
    <item>
      <title>Call function from script inserted in Toolbox</title>
      <link>https://community.esri.com/t5/python-questions/call-function-from-script-inserted-in-toolbox/m-p/5266#M460</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: #242729; background-color: #f9f8f6;"&gt;I'm trying to call a function defined in a script contained in Toolbox. I have imported the Toolbox via arcpy.ImportToolbox. The scripts contained are recognized. I cannot call the function defined to each one.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Oct 2018 09:15:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/call-function-from-script-inserted-in-toolbox/m-p/5266#M460</guid>
      <dc:creator>AretiSamara2</dc:creator>
      <dc:date>2018-10-20T09:15:59Z</dc:date>
    </item>
    <item>
      <title>Re: Call function from script inserted in Toolbox</title>
      <link>https://community.esri.com/t5/python-questions/call-function-from-script-inserted-in-toolbox/m-p/5267#M461</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why are you calling a script in your toolbox? and from where?&lt;/P&gt;&lt;P&gt;Are you not using the toolbox inside of arcmap or ArcGIS pro?&lt;/P&gt;&lt;P&gt;Is it a python toolbox or a conventional toolbox?&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="http://pro.arcgis.com/en/pro-app/arcpy/geoprocessing_and_python/adding-and-removing-toolboxes.htm" title="http://pro.arcgis.com/en/pro-app/arcpy/geoprocessing_and_python/adding-and-removing-toolboxes.htm"&gt;Adding toolboxes in Python—Geoprocessing and Python | ArcGIS Desktop&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have you imported your toolbox first?&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="background-color: transparent; color: #4c4c4c; font-family: &amp;amp;quot; avenir next w01&amp;amp;quot;,&amp;amp;quot;avenir next w00&amp;amp;quot;,&amp;amp;quot;avenir next&amp;amp;quot;,&amp;amp;quot;avenir&amp;amp;quot;,&amp;amp;quot;helvetica neue&amp;amp;quot;,sans-serif; font-size: 17px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; margin-bottom: 26.35px; margin-top: 0px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;In the following example, the &lt;A href="http://pro.arcgis.com/en/pro-app/arcpy/functions/importtoolbox.htm" style="color: #0074b8; text-decoration: none;"&gt;ImportToolbox&lt;/A&gt; function is used to allow tools contained in a custom toolbox to be accessed in Python. After importing the toolbox, the custom tools can be accessed as &lt;SPAN style="font-family: &amp;amp;quot;"&gt;arcpy.&amp;lt;toolname&amp;gt;_&amp;lt;alias&amp;gt;&lt;/SPAN&gt;.&lt;/P&gt;&lt;DIV style="background-color: transparent; color: #4c4c4c; display: block; flex-direction: row; font-family: &amp;amp;quot; avenir next w01&amp;amp;quot;,&amp;amp;quot;avenir next w00&amp;amp;quot;,&amp;amp;quot;avenir next&amp;amp;quot;,&amp;amp;quot;avenir&amp;amp;quot;,&amp;amp;quot;helvetica neue&amp;amp;quot;,sans-serif; font-feature-settings: &amp;amp;quot; liga&amp;amp;quot; 1, &amp;amp;quot;calt&amp;amp;quot; 0; font-size: 17px; font-style: normal; font-weight: 400; height: 83.6px; letter-spacing: normal; line-height: 26.35px; min-height: 0px; margin: 0px;"&gt;&lt;PRE style="font-family: &amp;amp;quot; consolas&amp;amp;quot;,&amp;amp;quot;andale mono&amp;amp;quot;,&amp;amp;quot;lucida console&amp;amp;quot;,&amp;amp;quot;monaco&amp;amp;quot;,monospace; margin-bottom: 26.35px; max-width: 768.41px; white-space: pre-wrap; word-wrap: break-word;"&gt;&lt;CODE style="background-color: #f8f8f8; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-image-outset: 0; border-image-repeat: stretch; border-image-slice: 100%; border-image-source: none; border-image-width: 1; border-top-left-radius: 3px; border-top-right-radius: 3px; color: #595959; display: block; font-family: &amp;amp;quot; consolas&amp;amp;quot;,&amp;amp;quot;andale mono&amp;amp;quot;,&amp;amp;quot;lucida console&amp;amp;quot;,&amp;amp;quot;monaco&amp;amp;quot;,monospace; font-size: 14.46px; line-height: 23.8px; overflow: auto; position: relative; white-space: pre; word-wrap: normal; padding: 17px; border: 1px solid #efefef;"&gt;&amp;gt;&amp;gt;&amp;gt; arcpy.ImportToolbox("c:/mytools/geometrytools.tbx") &amp;gt;&amp;gt;&amp;gt; arcpy.CreateRegularPolygons_geometry(&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You might want to elaborate on your situation more&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Oct 2018 10:45:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/call-function-from-script-inserted-in-toolbox/m-p/5267#M461</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2018-10-20T10:45:51Z</dc:date>
    </item>
    <item>
      <title>Re: Call function from script inserted in Toolbox</title>
      <link>https://community.esri.com/t5/python-questions/call-function-from-script-inserted-in-toolbox/m-p/5268#M462</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="color: #242729; background-color: #f9f8f6; border: 0px; margin: 0px 0px 1em;"&gt;I have added a Toolbox named "Test", in which 4 password-protected scripts are imported. Script script2 (imported in the Toolbox "Test") with user-defined parameters is used to call the other ones (depending on the defined parameters). In the scripts I have defined functions. e.g. script1.py&lt;/P&gt;&lt;P style="color: #242729; background-color: #f9f8f6; border: 0px; margin: 0px 0px 1em;"&gt;def PhiLamdah2XYZ(Phi, Lamda, h, a, f):&lt;/P&gt;&lt;P style="color: #242729; background-color: #f9f8f6; border: 0px; margin: 0px 0px 1em;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;...&lt;/P&gt;&lt;P style="color: #242729; background-color: #f9f8f6; border: 0px; margin: 0px 0px 1em;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return(X,Y,Z)&lt;/P&gt;&lt;P style="color: #242729; background-color: #f9f8f6; border: 0px; margin: 0px 0px 1em;"&gt;def XYZ2PhiLamdah(X, Y, Z, a, f):&lt;/P&gt;&lt;P style="color: #242729; background-color: #f9f8f6; border: 0px; margin: 0px 0px 1em;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;...&lt;/P&gt;&lt;P style="color: #242729; background-color: #f9f8f6; border: 0px; margin: 0px 0px 1em;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return(GeodCoord_Dall)&lt;/P&gt;&lt;P style="color: #242729; background-color: #f9f8f6; border: 0px; margin: 0px 0px 1em;"&gt;Script Script2.py imports the Toolbox "Test":&lt;/P&gt;&lt;P style="color: #242729; background-color: #f9f8f6; border: 0px; margin: 0px 0px 1em;"&gt;relPath = os.path.dirname(__&lt;STRONG style="border: 0px; font-weight: bold;"&gt;file__&lt;/STRONG&gt;)&lt;/P&gt;&lt;P style="color: #242729; background-color: #f9f8f6; border: 0px; margin: 0px 0px 1em;"&gt;PythonTBX = relPath + r"\Test.tbx"&lt;/P&gt;&lt;P style="color: #242729; background-color: #f9f8f6; border: 0px; margin: 0px 0px 1em;"&gt;arcpy.ImportToolbox(PythonTBX)&lt;/P&gt;&lt;P style="color: #242729; background-color: #f9f8f6; border: 0px; margin: 0px 0px 1em;"&gt;Is there a way to call the functions PhiLamdah2XYZ and XYZ2PhiLamdah from Script2.py?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Oct 2018 14:50:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/call-function-from-script-inserted-in-toolbox/m-p/5268#M462</guid>
      <dc:creator>AretiSamara2</dc:creator>
      <dc:date>2018-10-20T14:50:36Z</dc:date>
    </item>
    <item>
      <title>Re: Call function from script inserted in Toolbox</title>
      <link>https://community.esri.com/t5/python-questions/call-function-from-script-inserted-in-toolbox/m-p/5269#M463</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If the scripts are in the same location as the other scripts, why don't you just import those&lt;/P&gt;&lt;P&gt;ie.&lt;/P&gt;&lt;P&gt;Script1 is your main script (module) and script 2 is in the same location&lt;/P&gt;&lt;P&gt;Add this line&lt;/P&gt;&lt;P&gt;from script2 import&amp;nbsp;&lt;SPAN style="display: inline !important; float: none; background-color: #f9f8f6; color: #242729; font-family: arial,helvetica,'helvetica neue',verdana,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt; PhiLamdah2XYZ, XYZ2PhiLamdah&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Oct 2018 15:00:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/call-function-from-script-inserted-in-toolbox/m-p/5269#M463</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2018-10-20T15:00:54Z</dc:date>
    </item>
    <item>
      <title>Re: Call function from script inserted in Toolbox</title>
      <link>https://community.esri.com/t5/python-questions/call-function-from-script-inserted-in-toolbox/m-p/5270#M464</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;script1.py&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;# -*- coding: utf-8 -*-&lt;/SPAN&gt;
&lt;SPAN class="string token"&gt;"""
script1.py
"""&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; script2 &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; hello
name &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; hello&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;nme&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;None&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&amp;nbsp; &lt;SPAN class="comment token"&gt;# nme='Bob'&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;name&lt;SPAN class="punctuation token"&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;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;script2.py&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;# -*- coding: utf-8 -*-&lt;/SPAN&gt;
&lt;SPAN class="string token"&gt;"""
script2.py
"""&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;hello&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;nme&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;None&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; nme &lt;SPAN class="keyword token"&gt;is&lt;/SPAN&gt; None&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nme &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Hello You"&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nme &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Hello {}! "&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;nme&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; nme &lt;SPAN class="operator token"&gt;+=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;" called from script2"&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; nme&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Run script1, you can change line 6 in script 1 to test&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;runfile&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'C:/Temp/script1.py'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; wdir&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'C:/Temp'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
Reloaded modules&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; script2

Hello You called &lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; script2

&lt;SPAN class="comment token"&gt;# ---- changed input to script 1&lt;/SPAN&gt;

runfile&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'C:/Temp/script1.py'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; wdir&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'C:/Temp'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
Reloaded modules&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; script2

Hello Bob!&amp;nbsp; called &lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; script2&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&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>Fri, 10 Dec 2021 20:12:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/call-function-from-script-inserted-in-toolbox/m-p/5270#M464</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-10T20:12:49Z</dc:date>
    </item>
    <item>
      <title>Re: Call function from script inserted in Toolbox</title>
      <link>https://community.esri.com/t5/python-questions/call-function-from-script-inserted-in-toolbox/m-p/5271#M465</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The problem arises when I import the scripts in the Toolbox.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Oct 2018 15:38:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/call-function-from-script-inserted-in-toolbox/m-p/5271#M465</guid>
      <dc:creator>AretiSamara2</dc:creator>
      <dc:date>2018-10-20T15:38:09Z</dc:date>
    </item>
    <item>
      <title>Re: Call function from script inserted in Toolbox</title>
      <link>https://community.esri.com/t5/python-questions/call-function-from-script-inserted-in-toolbox/m-p/5272#M466</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;error messages?&lt;/P&gt;&lt;P&gt;is this a python toolbox (pyt)&lt;/P&gt;&lt;P&gt;I guess you are going to have to show what you have, since you appear to be doing something different than normal imports support&lt;/P&gt;&lt;P&gt;try the toolbox alias approach&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="http://pro.arcgis.com/en/pro-app/arcpy/functions/importtoolbox.htm" title="http://pro.arcgis.com/en/pro-app/arcpy/functions/importtoolbox.htm"&gt;ImportToolbox—ArcPy Functions | ArcGIS Desktop&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Oct 2018 16:06:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/call-function-from-script-inserted-in-toolbox/m-p/5272#M466</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2018-10-20T16:06:19Z</dc:date>
    </item>
  </channel>
</rss>

