<?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 access the tool path in the arcpy script? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-access-the-tool-path-in-the-arcpy-script/m-p/1253457#M66736</link>
    <description>&lt;P&gt;For some reason sys.argv[0] wasn't working for me, so I used os.dirname(__file__) and that worked nicely&lt;/P&gt;</description>
    <pubDate>Tue, 31 Jan 2023 18:08:46 GMT</pubDate>
    <dc:creator>SamSzotkowski</dc:creator>
    <dc:date>2023-01-31T18:08:46Z</dc:date>
    <item>
      <title>How to access the tool path in the arcpy script?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-access-the-tool-path-in-the-arcpy-script/m-p/544402#M42458</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have written a script for a tool (MyTool) in a toolbox (MyToolbox) used in ArcMap 10.6. In the script I like to get the path to the directory where the toolbox resides. Since we are distributing this tool, this path is a variable which will be different for each user.&lt;/P&gt;&lt;P&gt;For example if a user saves MyToolbox in &lt;EM&gt;C:\User\source\Workspaces &lt;/EM&gt;directory, how can I get this directory in my script?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Aug 2020 14:20:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-access-the-tool-path-in-the-arcpy-script/m-p/544402#M42458</guid>
      <dc:creator>AliNazari</dc:creator>
      <dc:date>2020-08-14T14:20:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to access the tool path in the arcpy script?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-access-the-tool-path-in-the-arcpy-script/m-p/544403#M42459</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;One option is to get the path to the running script.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; sys

script &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; sys&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;argv&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;  &lt;SPAN class="comment token"&gt;# ---- the running script‍‍‍&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;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If you know where the script is relative to the toolbox, then you can work from there.&lt;/P&gt;&lt;P&gt;For instance, if you simply store the script(s) in the same location as the *.tbx, then you just parse the path out of the above.&amp;nbsp; If the script is located in a folder relative to the toolbox, then you parse of that folder name&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And then there is&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://pro.arcgis.com/en/pro-app/arcpy/functions/listtoolboxes.htm" title="https://pro.arcgis.com/en/pro-app/arcpy/functions/listtoolboxes.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;ListToolboxes—ArcGIS Pro | Documentation&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;just limit the wildcard to your toolbox name&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:33:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-access-the-tool-path-in-the-arcpy-script/m-p/544403#M42459</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-12-11T23:33:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to access the tool path in the arcpy script?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-access-the-tool-path-in-the-arcpy-script/m-p/1253457#M66736</link>
      <description>&lt;P&gt;For some reason sys.argv[0] wasn't working for me, so I used os.dirname(__file__) and that worked nicely&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2023 18:08:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-access-the-tool-path-in-the-arcpy-script/m-p/1253457#M66736</guid>
      <dc:creator>SamSzotkowski</dc:creator>
      <dc:date>2023-01-31T18:08:46Z</dc:date>
    </item>
  </channel>
</rss>

