<?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: Unexpected behaviour when setting default value for Toolbox input parameter of type DEFile in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/unexpected-behaviour-when-setting-default-value/m-p/1249014#M66586</link>
    <description>&lt;P&gt;Interesting behavior, also reproducable in ArcGIS Pro.&lt;/P&gt;&lt;P&gt;To solve it, you can set the default value in getParameterInfo() and do the glob() in updateParameters():&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import os, glob

class DEFileTest(object):
    label="DEFileTest"
    description="DEFileTest"    

    def getParameterInfo(self):
        parameters = [
            arcpy.Parameter(name="in_file", displayName="In File", datatype="DEFile", parameterType="Required", direction="Input"),
            ]
        parameters[0].value = "N:/.../temp/test.txt"
        return parameters
        
        
    def updateParameters(self, parameters):
        par = {p.name: p for p in parameters}
        if par["in_file"].value is None or not os.path.exists(str(par["in_file"].value)):
            b = glob.glob("N:/.../temp/*.txt")
            try:
                par["in_file"].value = b[0]
            except IndexError:
                par["in_file"].value = None
	
	
    def execute(self, parameters, messages):
        par = {p.name: p for p in parameters}
        arcpy.AddMessage("I'm working on " + str(par["in_file"].value))&lt;/LI-CODE&gt;</description>
    <pubDate>Wed, 18 Jan 2023 12:38:12 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2023-01-18T12:38:12Z</dc:date>
    <item>
      <title>Unexpected behaviour when setting default value for Toolbox input parameter of type DEFile</title>
      <link>https://community.esri.com/t5/python-questions/unexpected-behaviour-when-setting-default-value/m-p/1249002#M66585</link>
      <description>&lt;P&gt;I created an ArcMap Python Toolbox with a DEFile input parameter.&lt;/P&gt;&lt;P&gt;Right after defining the parameter, I placed the lines&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;a = "/some/file.txt"
b = glob.glob("/some/directory/*.txt")
file_parameter.value = a if os.path.exists(a) else b[0]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, when I open the respective Tool dialogue, it shows the file defined in variable "a". I manually renamed that file and opened the Tool again, but still, the original file name was set as the default input parameter. Then I refreshed the toolbox. Now, the new file name was used as default input value, since it has the extension .txt.&lt;/P&gt;&lt;P&gt;The problem is that the output of the first tool is the input of the second, etc. Thus, the input files are generated or altered while using the toolbox. E.g., file "/some/file.txt" is created by the first tool and used by the second. Obviously, it should not be required to right-click and refresh the Toolbox in between executing different tools.&lt;/P&gt;&lt;P&gt;How does this behaviour arise and how can I tell ArcMap to automatically check what files exist (in a Geodatabase or elsewhere) when the Tool dialogue is opened (rather than when the Toolbox is refreshed or the tool is executed)?&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jan 2023 11:50:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unexpected-behaviour-when-setting-default-value/m-p/1249002#M66585</guid>
      <dc:creator>Manu</dc:creator>
      <dc:date>2023-01-18T11:50:02Z</dc:date>
    </item>
    <item>
      <title>Re: Unexpected behaviour when setting default value for Toolbox input parameter of type DEFile</title>
      <link>https://community.esri.com/t5/python-questions/unexpected-behaviour-when-setting-default-value/m-p/1249014#M66586</link>
      <description>&lt;P&gt;Interesting behavior, also reproducable in ArcGIS Pro.&lt;/P&gt;&lt;P&gt;To solve it, you can set the default value in getParameterInfo() and do the glob() in updateParameters():&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import os, glob

class DEFileTest(object):
    label="DEFileTest"
    description="DEFileTest"    

    def getParameterInfo(self):
        parameters = [
            arcpy.Parameter(name="in_file", displayName="In File", datatype="DEFile", parameterType="Required", direction="Input"),
            ]
        parameters[0].value = "N:/.../temp/test.txt"
        return parameters
        
        
    def updateParameters(self, parameters):
        par = {p.name: p for p in parameters}
        if par["in_file"].value is None or not os.path.exists(str(par["in_file"].value)):
            b = glob.glob("N:/.../temp/*.txt")
            try:
                par["in_file"].value = b[0]
            except IndexError:
                par["in_file"].value = None
	
	
    def execute(self, parameters, messages):
        par = {p.name: p for p in parameters}
        arcpy.AddMessage("I'm working on " + str(par["in_file"].value))&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 18 Jan 2023 12:38:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unexpected-behaviour-when-setting-default-value/m-p/1249014#M66586</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-01-18T12:38:12Z</dc:date>
    </item>
  </channel>
</rss>

