<?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: Select a String Parameter Value in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/select-a-string-parameter-value/m-p/695754#M53927</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Caleb,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;That looks very promising. Will be trying it. Is the list auto-populated into a tool when script is imported into ArcToolbox or do properties need setting? The on-line help doesn't make things real clear.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Craig&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 22 Jan 2014 02:34:13 GMT</pubDate>
    <dc:creator>CPoynter</dc:creator>
    <dc:date>2014-01-22T02:34:13Z</dc:date>
    <item>
      <title>Select a String Parameter Value</title>
      <link>https://community.esri.com/t5/python-questions/select-a-string-parameter-value/m-p/695752#M53925</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am using GetParameterAsText. I want to be able to select a value (i.e. A or B) for my response from a prompted list.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;How can I code a prompt list to appear with set values? Is this possible within ArcPy without having to use an add-in? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;C. Poynter&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Jan 2014 01:39:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-a-string-parameter-value/m-p/695752#M53925</guid>
      <dc:creator>CPoynter</dc:creator>
      <dc:date>2014-01-17T01:39:17Z</dc:date>
    </item>
    <item>
      <title>Re: Select a String Parameter Value</title>
      <link>https://community.esri.com/t5/python-questions/select-a-string-parameter-value/m-p/695753#M53926</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;&lt;SPAN&gt;You have to do this in the &lt;A href="&amp;lt;/span&amp;gt;&amp;lt;a" target="_blank" rel="nofollow noopener noreferrer"&gt;tool" rel="nofollow" target="_blank"&amp;gt;http://resources.arcgis.com/en/help/main/10.1/index.html#//00150000000v000000]tool&lt;/A&gt;&lt;SPAN&gt; validator class for your script tool.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is an example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
class ToolValidator(object):
&amp;nbsp; """Class for validating a tool's parameter values and controlling
&amp;nbsp; the behavior of the tool's dialog."""

&amp;nbsp; def __init__(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Setup arcpy and the list of tool parameters."""
&amp;nbsp;&amp;nbsp;&amp;nbsp; self.params = arcpy.GetParameterInfo()

&amp;nbsp; def initializeParameters(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Refine the properties of a tool's parameters.&amp;nbsp; This method is
&amp;nbsp;&amp;nbsp;&amp;nbsp; called when the tool is opened."""
&amp;nbsp;&amp;nbsp;&amp;nbsp; return

&amp;nbsp; def updateParameters(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Modify the values and properties of parameters before internal
&amp;nbsp;&amp;nbsp;&amp;nbsp; validation is performed.&amp;nbsp; This method is called whenever a parameter
&amp;nbsp;&amp;nbsp;&amp;nbsp; has been changed."""

&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color:&amp;quot;#FF0000&amp;quot;;"&gt;# List for parameter
&amp;nbsp;&amp;nbsp;&amp;nbsp; self.params[0].filter.list = ['Option A', 'Option B', 'etc']&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return

&amp;nbsp; def updateMessages(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Modify the messages created by internal validation for each tool
&amp;nbsp;&amp;nbsp;&amp;nbsp; parameter.&amp;nbsp; This method is called after internal validation."""
&amp;nbsp;&amp;nbsp;&amp;nbsp; return
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This will create a drop down list for the first parameter of a script tool.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 05:17:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-a-string-parameter-value/m-p/695753#M53926</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-12T05:17:10Z</dc:date>
    </item>
    <item>
      <title>Re: Select a String Parameter Value</title>
      <link>https://community.esri.com/t5/python-questions/select-a-string-parameter-value/m-p/695754#M53927</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Caleb,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;That looks very promising. Will be trying it. Is the list auto-populated into a tool when script is imported into ArcToolbox or do properties need setting? The on-line help doesn't make things real clear.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Craig&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Jan 2014 02:34:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-a-string-parameter-value/m-p/695754#M53927</guid>
      <dc:creator>CPoynter</dc:creator>
      <dc:date>2014-01-22T02:34:13Z</dc:date>
    </item>
    <item>
      <title>Re: Select a String Parameter Value</title>
      <link>https://community.esri.com/t5/python-questions/select-a-string-parameter-value/m-p/695755#M53928</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes, the drop down list will be automatically populated in the tool interface &lt;/SPAN&gt;&lt;STRONG&gt;after&lt;/STRONG&gt;&lt;SPAN&gt; you set up the tool's validation. This can be set up in the 'Validation' tab from the script tool properties. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]30703[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;From inside the Validation tab, you need to choose to edit the script in the lower right corner. Esri provides every script tool with this tool validator class template. For making drop down lists, you just need to alter the 'updateParameters' method. In this case, my validation code looks like this (drop down lists highlighted in red):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import os, fnmatch

# function to find files with wildcard
def find(pattern, path):
&amp;nbsp;&amp;nbsp;&amp;nbsp; theFiles = []
&amp;nbsp;&amp;nbsp;&amp;nbsp; for path, dirs, files in os.walk(path):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for filename in files:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if fnmatch.fnmatch(filename, pattern):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; theFiles.append(os.path.abspath(os.path.join(path, filename)))
&amp;nbsp;&amp;nbsp;&amp;nbsp; return sorted(theFiles)

class ToolValidator:
&amp;nbsp; """Class for validating a tool's parameter values and controlling
&amp;nbsp; the behavior of the tool's dialog."""

&amp;nbsp; def __init__(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Setup arcpy and the list of tool parameters."""
&amp;nbsp;&amp;nbsp;&amp;nbsp; import arcpy
&amp;nbsp;&amp;nbsp;&amp;nbsp; self.params = arcpy.GetParameterInfo()

&amp;nbsp; def initializeParameters(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Refine the properties of a tool's parameters.&amp;nbsp; This method is
&amp;nbsp;&amp;nbsp;&amp;nbsp; called when the tool is opened."""
&amp;nbsp;&amp;nbsp;&amp;nbsp; return

&amp;nbsp; def updateParameters(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Modify the values and properties of parameters before internal
&amp;nbsp;&amp;nbsp;&amp;nbsp; validation is performed.&amp;nbsp; This method is called whenever a parmater
&amp;nbsp;&amp;nbsp;&amp;nbsp; has been changed."""

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Path to SQL Databases
&amp;nbsp;&amp;nbsp;&amp;nbsp; sde_loc = r'\\arcserver1\SDE'
&amp;nbsp;&amp;nbsp;&amp;nbsp; sde_db = find('*.mdf', sde_loc)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # drop down lists
&amp;nbsp;&amp;nbsp;&amp;nbsp; self.params[0].filter.list = [os.path.basename(s).split('.')[0] for s in sde_db]
&amp;nbsp;&amp;nbsp;&amp;nbsp; self.params[2].filter.list = ['DBO.DEFAULT', 'DBO.EDITOR']
&amp;nbsp;&amp;nbsp;&amp;nbsp; return

&amp;nbsp; def updateMessages(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Modify the messages created by internal validation for each tool
&amp;nbsp;&amp;nbsp;&amp;nbsp; parameter.&amp;nbsp; This method is called after internal validation."""
&amp;nbsp;&amp;nbsp;&amp;nbsp; return
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Once you have added your validation, when you open the tool you should have little black arrows in the lower right of each parameter for which you set up a list. And when you click on the arrow, your list should appear.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]30704[/ATTACH][ATTACH=CONFIG]30705[/ATTACH]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:48:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-a-string-parameter-value/m-p/695755#M53928</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-12T16:48:53Z</dc:date>
    </item>
  </channel>
</rss>

