<?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: Get path to script tool inside of a toolset? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/get-path-to-script-tool-inside-of-a-toolset/m-p/1133137#M63492</link>
    <description>&lt;P&gt;If you don't know where the user stores their toolboxes, then you will have a difficult job.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;import sys
sys.path
['C:\\arc_pro\\Resources\\ArcPy',... snip ...]

# -- my stuff
# 'C:\\Arc_projects', 'C:\\arcpro_npg',&lt;/LI-CODE&gt;&lt;P&gt;which isn't going to help unless you want to remove path info normally present from that on a specific machine&lt;/P&gt;</description>
    <pubDate>Wed, 12 Jan 2022 22:52:09 GMT</pubDate>
    <dc:creator>DanPatterson</dc:creator>
    <dc:date>2022-01-12T22:52:09Z</dc:date>
    <item>
      <title>Get path to script tool inside of a toolset?</title>
      <link>https://community.esri.com/t5/python-questions/get-path-to-script-tool-inside-of-a-toolset/m-p/1133078#M63486</link>
      <description>&lt;P&gt;I've used sys.argv[0] before to get the path to the current script tool being ran. H&lt;SPAN&gt;owever, I'm finding that if the script tool is inside of a toolset within the toolbox, sys.argv[0] doesn't return anything. Is there a way to get the script tool path when it is inside of a toolset?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jan 2022 20:50:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-path-to-script-tool-inside-of-a-toolset/m-p/1133078#M63486</guid>
      <dc:creator>GB_MattPanunto_GISS</dc:creator>
      <dc:date>2022-01-12T20:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: Get path to script tool inside of a toolset?</title>
      <link>https://community.esri.com/t5/python-questions/get-path-to-script-tool-inside-of-a-toolset/m-p/1133103#M63487</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# --- carry on from before
import arcpy
pth = r"C:\arcpro_npg\npg_tools.tbx"
t0 = arcpy.ImportToolbox(pth)
t0.__pathname__
'C:\\arcpro_npg\\npg_tools.tbx'

# -- or
tools = arcpy.ListTools('*_npg')
tools
['AttributeSort_npg',
... snip ...
 'Triangulate_npg']

t0.__pathname__
'C:\\arcpro_npg\\npg_tools.tbx'
c = arcpy.AttributeSort_npg.__code__  # --- get the code reference
c.co_filename
'C:\\arcpro_npg\\npg_tools.tbx'

# ----
# -- ..\tbx_tools.py&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It stops at some point.&amp;nbsp; Once I get the toolbox name from either of the methods.&amp;nbsp; I know where the script is located since I store my scripts relate to the tbx path like&lt;/P&gt;&lt;P&gt;..\\tbx_path\\scripts\&lt;/P&gt;&lt;P&gt;and you can parse off the module name (_npg) from the tool name (arcpy.AttributeSort_npg)&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jan 2022 21:42:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-path-to-script-tool-inside-of-a-toolset/m-p/1133103#M63487</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-01-12T21:42:02Z</dc:date>
    </item>
    <item>
      <title>Re: Get path to script tool inside of a toolset?</title>
      <link>https://community.esri.com/t5/python-questions/get-path-to-script-tool-inside-of-a-toolset/m-p/1133110#M63488</link>
      <description>&lt;P&gt;But what if you don't know the path to the toolbox? Say if the toolbox is being used by another user on a different machine.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jan 2022 21:48:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-path-to-script-tool-inside-of-a-toolset/m-p/1133110#M63488</guid>
      <dc:creator>GB_MattPanunto_GISS</dc:creator>
      <dc:date>2022-01-12T21:48:45Z</dc:date>
    </item>
    <item>
      <title>Re: Get path to script tool inside of a toolset?</title>
      <link>https://community.esri.com/t5/python-questions/get-path-to-script-tool-inside-of-a-toolset/m-p/1133118#M63489</link>
      <description>&lt;P&gt;see lines 3, 4, 5&amp;nbsp; import the toolbox BUT that is as far as it goes.&lt;/P&gt;&lt;P&gt;The new format of toolboxes ( *.atbx ) has some more options that I have been exploring&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jan 2022 22:15:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-path-to-script-tool-inside-of-a-toolset/m-p/1133118#M63489</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-01-12T22:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: Get path to script tool inside of a toolset?</title>
      <link>https://community.esri.com/t5/python-questions/get-path-to-script-tool-inside-of-a-toolset/m-p/1133126#M63490</link>
      <description>&lt;P&gt;Hmm, but wouldn't importing the toolbox require the user to specifically define its location first? I'm trying to avoid that.&lt;/P&gt;&lt;P&gt;The end goal here is to determine the path to the toolbox on the user's machine, without them having to define its location. This was easy with&amp;nbsp;&lt;SPAN&gt;sys.argv[0], since I could just grab the parent directory of the script tool, but this method doesn't seem to be working for me when the script tool is inside of a toolset.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I'd be willing to convert the toolbox to the new format (.atbx), if that made this possible.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jan 2022 22:30:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-path-to-script-tool-inside-of-a-toolset/m-p/1133126#M63490</guid>
      <dc:creator>GB_MattPanunto_GISS</dc:creator>
      <dc:date>2022-01-12T22:30:59Z</dc:date>
    </item>
    <item>
      <title>Re: Get path to script tool inside of a toolset?</title>
      <link>https://community.esri.com/t5/python-questions/get-path-to-script-tool-inside-of-a-toolset/m-p/1133137#M63492</link>
      <description>&lt;P&gt;If you don't know where the user stores their toolboxes, then you will have a difficult job.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;import sys
sys.path
['C:\\arc_pro\\Resources\\ArcPy',... snip ...]

# -- my stuff
# 'C:\\Arc_projects', 'C:\\arcpro_npg',&lt;/LI-CODE&gt;&lt;P&gt;which isn't going to help unless you want to remove path info normally present from that on a specific machine&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jan 2022 22:52:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-path-to-script-tool-inside-of-a-toolset/m-p/1133137#M63492</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-01-12T22:52:09Z</dc:date>
    </item>
    <item>
      <title>Re: Get path to script tool inside of a toolset?</title>
      <link>https://community.esri.com/t5/python-questions/get-path-to-script-tool-inside-of-a-toolset/m-p/1133183#M63495</link>
      <description>&lt;P&gt;You can use the python '_file_' variable to get the path to your .py file.&amp;nbsp; From there you can back it up to the root of your toolbox.&amp;nbsp; &amp;nbsp;Here is an example of how I do it:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;path_code_base = os.path.normpath(__file__ + '/../../../../')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jan 2022 00:43:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-path-to-script-tool-inside-of-a-toolset/m-p/1133183#M63495</guid>
      <dc:creator>DonMorrison1</dc:creator>
      <dc:date>2022-01-13T00:43:12Z</dc:date>
    </item>
    <item>
      <title>Re: Get path to script tool inside of a toolset?</title>
      <link>https://community.esri.com/t5/python-questions/get-path-to-script-tool-inside-of-a-toolset/m-p/1133645#M63506</link>
      <description>&lt;P&gt;I discovered that if you embed the script AND put a password on it, &lt;SPAN&gt;sys.argv[0] will include the toolbox in the path of the script tool. A bit of a clunky workaround, but may work in a pinch.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jan 2022 22:24:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-path-to-script-tool-inside-of-a-toolset/m-p/1133645#M63506</guid>
      <dc:creator>GB_MattPanunto_GISS</dc:creator>
      <dc:date>2022-01-13T22:24:38Z</dc:date>
    </item>
  </channel>
</rss>

