<?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: Arcpy: get user's input for location and file name in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-get-user-s-input-for-location-and-file-name/m-p/548417#M42794</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Joshua.&amp;nbsp; I was hoping for a more simple approach to my issue.&amp;nbsp; Most of the time I just use model builder and script out to python.&amp;nbsp; The code I put here is just the last step of my workflow not the whole thing so I do not think I'm able to write all that in addin.&amp;nbsp; I've not learned to code in python yet.&amp;nbsp; I tried to use the output parameter but it didn't work.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 31 Aug 2018 17:37:18 GMT</pubDate>
    <dc:creator>helenchu</dc:creator>
    <dc:date>2018-08-31T17:37:18Z</dc:date>
    <item>
      <title>Arcpy: get user's input for location and file name</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-get-user-s-input-for-location-and-file-name/m-p/548413#M42790</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I have arcpy scripts to run in arcmap. Last step is "Table to Excel Conversion"&lt;/P&gt;&lt;P&gt;Instead of having the excel file name and location hard-coded I'd like to get the user's input for those.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your help is greatly appreciated!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# sftMap.py&lt;BR /&gt;# Created on: 2018-08-31 10:42:32.00000&lt;BR /&gt;# (generated by ArcGIS/ModelBuilder)&lt;BR /&gt;# Description:&lt;BR /&gt;# ---------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;# Import arcpy module&lt;BR /&gt;import arcpy&lt;BR /&gt;arcpy.env.overwriteOutput = True&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# Local variables:&lt;BR /&gt;SiteNum_AcreCal = "C:\\...\\scratch\\parcel_Select_SpatialJoin_TableToExcel.xls"&lt;BR /&gt;parcel_Select_SpatialJoin_Ta_xls = "C:\\...\\ArcGIS\\parcel_Select_SpatialJoin_Ta.xls"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Process: Table To Excel&lt;BR /&gt;arcpy.TableToExcel_conversion(ParcelSiteNum, SiteNum_AcreCal, "NAME", "CODE")&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Aug 2018 16:27:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-get-user-s-input-for-location-and-file-name/m-p/548413#M42790</guid>
      <dc:creator>helenchu</dc:creator>
      <dc:date>2018-08-31T16:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy: get user's input for location and file name</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-get-user-s-input-for-location-and-file-name/m-p/548414#M42791</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If the scripts are running within ArcMap, then &lt;A class="link-titled" href="http://desktop.arcgis.com/en/arcmap/latest/analyze/python-addins/the-pythonaddins-module.htm" title="http://desktop.arcgis.com/en/arcmap/latest/analyze/python-addins/the-pythonaddins-module.htm"&gt;The pythonaddins module—Help | ArcGIS Desktop&lt;/A&gt;&amp;nbsp; offers a straightforward way to address your issue.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;UPDATE:&lt;/STRONG&gt;&amp;nbsp; The note on the documentation states the module can only be used in Add-ins, but I have used it some with scripts I execute in ArcMap that aren't part of an Addin.&amp;nbsp; I guess I would have to know more specifics about how the code is run before offering more suggestions.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Aug 2018 16:34:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-get-user-s-input-for-location-and-file-name/m-p/548414#M42791</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2018-08-31T16:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy: get user's input for location and file name</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-get-user-s-input-for-location-and-file-name/m-p/548415#M42792</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Interesting approach.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Aug 2018 16:58:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-get-user-s-input-for-location-and-file-name/m-p/548415#M42792</guid>
      <dc:creator>RandyBurton</dc:creator>
      <dc:date>2018-08-31T16:58:38Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy: get user's input for location and file name</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-get-user-s-input-for-location-and-file-name/m-p/548416#M42793</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can also use arcpy.GetParameter and set the parameter type to a File and the direction as Input. This will allow your user to browse to a file on disk. In a service, you can enable the Uploads capability so the browser can browser to the file to upload as well.&lt;/P&gt;&lt;P&gt;&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; arcpy

inFile&amp;nbsp; &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;GetParameter&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;
arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddMessage&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;inFile&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;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Input parameter data type set to File&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="420904" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/420904_pastedImage_1.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Folder icon opens browser&lt;/P&gt;&lt;P&gt;&lt;IMG class="jive-image image-4" src="https://community.esri.com/legacyfs/online/420912_pastedImage_1.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Path retrieved through variable storing the input parameter:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="420910" class="image-3 jive-image" src="https://community.esri.com/legacyfs/online/420910_pastedImage_3.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:43:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-get-user-s-input-for-location-and-file-name/m-p/548416#M42793</guid>
      <dc:creator>JonathanQuinn</dc:creator>
      <dc:date>2021-12-11T23:43:30Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy: get user's input for location and file name</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-get-user-s-input-for-location-and-file-name/m-p/548417#M42794</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Joshua.&amp;nbsp; I was hoping for a more simple approach to my issue.&amp;nbsp; Most of the time I just use model builder and script out to python.&amp;nbsp; The code I put here is just the last step of my workflow not the whole thing so I do not think I'm able to write all that in addin.&amp;nbsp; I've not learned to code in python yet.&amp;nbsp; I tried to use the output parameter but it didn't work.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Aug 2018 17:37:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-get-user-s-input-for-location-and-file-name/m-p/548417#M42794</guid>
      <dc:creator>helenchu</dc:creator>
      <dc:date>2018-08-31T17:37:18Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy: get user's input for location and file name</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-get-user-s-input-for-location-and-file-name/m-p/548418#M42795</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Tkinter is also an option.&amp;nbsp; For destop 10.6:&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; Tkinter&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; tkFileDialog

root &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; Tkinter&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Tk&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
root&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;withdraw&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

file_path &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; tkFileDialog&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;askopenfilename&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt; file_path&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;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Using Joshua's suggestion inside ArcMap (at the bottom of the page he referenced):&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;import pythonaddins

import os
class MyValidator(object):
&amp;nbsp;&amp;nbsp;&amp;nbsp; def __str__(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return "Text files(*.txt)"
&amp;nbsp;&amp;nbsp;&amp;nbsp; def __call__(self, filename):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.path.isfile(filename) and filename.lower().endswith(".txt"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return True
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return False

filename = pythonaddins.OpenDialog(r"C:\Path", filter=MyValidator())
&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;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:43:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-get-user-s-input-for-location-and-file-name/m-p/548418#M42795</guid>
      <dc:creator>RandyBurton</dc:creator>
      <dc:date>2021-12-11T23:43:33Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy: get user's input for location and file name</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-get-user-s-input-for-location-and-file-name/m-p/548419#M42796</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try the addins module, it might work for your regardless of the note in the documentation.&amp;nbsp; Worst case, you lose an hour or less trying it out.&amp;nbsp; Another approach is &lt;A class="link-titled" href="https://docs.python.org/2/library/tk.html" title="https://docs.python.org/2/library/tk.html"&gt;24. Graphical User Interfaces with Tk — Python 2.7.15 documentation&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Aug 2018 17:42:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-get-user-s-input-for-location-and-file-name/m-p/548419#M42796</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2018-08-31T17:42:28Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy: get user's input for location and file name</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-get-user-s-input-for-location-and-file-name/m-p/548420#M42797</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you so much.&amp;nbsp; From your example, I created 2 parameters, 1&amp;nbsp; folder datatype for path and 1 string datatype for filename.&amp;nbsp; It works!&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Aug 2018 20:43:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-get-user-s-input-for-location-and-file-name/m-p/548420#M42797</guid>
      <dc:creator>helenchu</dc:creator>
      <dc:date>2018-08-31T20:43:04Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy: get user's input for location and file name</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-get-user-s-input-for-location-and-file-name/m-p/548421#M42798</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for all your help.&amp;nbsp; I chose the easiest route for me which is using the built in parameters but all suggestions are very helpful.&amp;nbsp; I might try them later.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Aug 2018 20:44:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-get-user-s-input-for-location-and-file-name/m-p/548421#M42798</guid>
      <dc:creator>helenchu</dc:creator>
      <dc:date>2018-08-31T20:44:39Z</dc:date>
    </item>
  </channel>
</rss>

