<?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: Programmically Populate Value List in ArcGIS Tool Interface in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/programmically-populate-value-list-in-arcgis-tool/m-p/672883#M52047</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Mike,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;you´ll have to use the ToolValidator Class to do this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for a sample tool with 3 parameters where you can first select a Layer then select the field and get the chosen field´s values:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;FC (datatype: Layer)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Field (datatype: Field) &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Value (datatype: String)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;on the validation tab change the validator class code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;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; &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; &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;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; self.params[1].parameterDependencies = [0]&amp;nbsp;&amp;nbsp; # set the parameter dependency for Field to the FC &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; return&amp;nbsp; &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;&amp;nbsp; import arcpy &amp;nbsp;&amp;nbsp;&amp;nbsp; FC = self.params[0].value &amp;nbsp;&amp;nbsp;&amp;nbsp; fldName = self.params[1].value &amp;nbsp;&amp;nbsp;&amp;nbsp; vList = [] &amp;nbsp;&amp;nbsp;&amp;nbsp; #use a cursor to get values of selected field into vList &amp;nbsp;&amp;nbsp;&amp;nbsp; rows = arcpy.SearchCursor(FC) &amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fldVal = str(row.getValue(fldName)) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vList.append(fldVal)&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; self.params[2].filter.list = vList&amp;nbsp; #fill the Values Parameter with the selected field´s values &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; return&amp;nbsp; &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;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 06 Mar 2013 06:01:54 GMT</pubDate>
    <dc:creator>RaphaelR</dc:creator>
    <dc:date>2013-03-06T06:01:54Z</dc:date>
    <item>
      <title>Programmically Populate Value List in ArcGIS Tool Interface</title>
      <link>https://community.esri.com/t5/python-questions/programmically-populate-value-list-in-arcgis-tool/m-p/672882#M52046</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm just trying to set up the parameters in a tool I've built in ArcGIS. What I want to do is read in a feature class or table and get the values in a specific field called "SITE". The field contains a bunch of site names. What I want to do is read in the values of that field and populate them into the 'Value List' tool parameter property&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've been looking at the tool properties and I though I can use the 'Obtained From' property, but it looks like I can only obtain field names, but not that values in the field. Is there anyway else to do this? Is there anyways to read in the values from the SITE field and populate it to a value list programmically?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks, Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Mar 2013 20:30:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/programmically-populate-value-list-in-arcgis-tool/m-p/672882#M52046</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2013-03-05T20:30:46Z</dc:date>
    </item>
    <item>
      <title>Re: Programmically Populate Value List in ArcGIS Tool Interface</title>
      <link>https://community.esri.com/t5/python-questions/programmically-populate-value-list-in-arcgis-tool/m-p/672883#M52047</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Mike,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;you´ll have to use the ToolValidator Class to do this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for a sample tool with 3 parameters where you can first select a Layer then select the field and get the chosen field´s values:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;FC (datatype: Layer)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Field (datatype: Field) &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Value (datatype: String)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;on the validation tab change the validator class code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;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; &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; &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;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; self.params[1].parameterDependencies = [0]&amp;nbsp;&amp;nbsp; # set the parameter dependency for Field to the FC &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; return&amp;nbsp; &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;&amp;nbsp; import arcpy &amp;nbsp;&amp;nbsp;&amp;nbsp; FC = self.params[0].value &amp;nbsp;&amp;nbsp;&amp;nbsp; fldName = self.params[1].value &amp;nbsp;&amp;nbsp;&amp;nbsp; vList = [] &amp;nbsp;&amp;nbsp;&amp;nbsp; #use a cursor to get values of selected field into vList &amp;nbsp;&amp;nbsp;&amp;nbsp; rows = arcpy.SearchCursor(FC) &amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fldVal = str(row.getValue(fldName)) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vList.append(fldVal)&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; self.params[2].filter.list = vList&amp;nbsp; #fill the Values Parameter with the selected field´s values &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; return&amp;nbsp; &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;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Mar 2013 06:01:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/programmically-populate-value-list-in-arcgis-tool/m-p/672883#M52047</guid>
      <dc:creator>RaphaelR</dc:creator>
      <dc:date>2013-03-06T06:01:54Z</dc:date>
    </item>
    <item>
      <title>Re: Programmically Populate Value List in ArcGIS Tool Interface</title>
      <link>https://community.esri.com/t5/python-questions/programmically-populate-value-list-in-arcgis-tool/m-p/672884#M52048</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Rapheal. I haven't played with the validator before. This is exactly what I was looking for. Thanks for taking the time.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Mar 2013 14:31:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/programmically-populate-value-list-in-arcgis-tool/m-p/672884#M52048</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2013-03-06T14:31:39Z</dc:date>
    </item>
    <item>
      <title>Re: Programmically Populate Value List in ArcGIS Tool Interface</title>
      <link>https://community.esri.com/t5/python-questions/programmically-populate-value-list-in-arcgis-tool/m-p/672885#M52049</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks very much. This is exactly what I needed to accomplish and I learned about validation in the processes.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jul 2019 21:02:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/programmically-populate-value-list-in-arcgis-tool/m-p/672885#M52049</guid>
      <dc:creator>MarcusBrown</dc:creator>
      <dc:date>2019-07-03T21:02:01Z</dc:date>
    </item>
  </channel>
</rss>

