<?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: Tool Validator / Values List Help in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/tool-validator-values-list-help/m-p/376583#M29736</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm not sure what your code is but sys.argv starts at 1 whereas getparameter starts at 0.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;So when you are assigning the input parameters your first sys.argv should be 1 and so on.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Please post your code if this is not your issue.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Joel&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 14 May 2013 18:25:53 GMT</pubDate>
    <dc:creator>JoelCalhoun</dc:creator>
    <dc:date>2013-05-14T18:25:53Z</dc:date>
    <item>
      <title>Tool Validator / Values List Help</title>
      <link>https://community.esri.com/t5/python-questions/tool-validator-values-list-help/m-p/376578#M29731</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;All,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to populate a Values List in a tool from selected features.&amp;nbsp; I have 2 feature classes (Counties and Places).&amp;nbsp; I am trying to narrow down the Placees that will populate the Values List.&amp;nbsp; I would like the user to specify the County and then the Values List would be populated by selecting the Places inside the County(SelectByLocation).&amp;nbsp; I am thinking that the Tool Validator will be used but not sure if/how.&amp;nbsp; Would it be possible to select the County by mouse click?&amp;nbsp; Thanks.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 May 2013 16:52:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/tool-validator-values-list-help/m-p/376578#M29731</guid>
      <dc:creator>AllenSmith</dc:creator>
      <dc:date>2013-05-13T16:52:58Z</dc:date>
    </item>
    <item>
      <title>Re: Tool Validator / Values List Help</title>
      <link>https://community.esri.com/t5/python-questions/tool-validator-values-list-help/m-p/376579#M29732</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;For performance reasons, it would make more sense to tag the places with the County beforehand, you don't want to do significant geoprocessing while a user is staring at the dialog box -- a delay of even a second is a long time in that situation.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's an example of how this would work. The code below assumes:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Parameter 0 is the county polygon with fields CNAME and CCODE&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Parameter 1 is the place points with fields PNAME and CCODE&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Parameter 2 is the county name (picklist)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Parameter 3 is the place name (picklist)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This code is untested! For guidance, see the help article "Programming a Tool Validator Class".&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;def updateParameters(): &amp;nbsp; if self.params[0].value: &amp;nbsp;&amp;nbsp;&amp;nbsp; # get dict of county names and codes &amp;nbsp;&amp;nbsp;&amp;nbsp; counties = {} &amp;nbsp;&amp;nbsp;&amp;nbsp; rows = arcpy.SearchCursor(self.params[0].value,"","","CNAME;CCODE") &amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nm = row.getValue("CNAME") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cd = row.getValue("CCODE")&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; counties[nm] = cd &amp;nbsp;&amp;nbsp;&amp;nbsp; del row, rows &amp;nbsp;&amp;nbsp;&amp;nbsp; # set up picklist (filter) of county names &amp;nbsp;&amp;nbsp;&amp;nbsp; cnames = counties.keys() &amp;nbsp;&amp;nbsp;&amp;nbsp; self.param[2].filter.list = sorted(cnames) &amp;nbsp; # set up picklist of place names for this county &amp;nbsp; if self.params[1].value and self.params[2].value: &amp;nbsp;&amp;nbsp;&amp;nbsp; county_code = counties[self.params[2].value] &amp;nbsp;&amp;nbsp;&amp;nbsp; where = "CCODE = {0}".format(county_code) &amp;nbsp;&amp;nbsp;&amp;nbsp; rows = arcpy.SearchCursor(self.params[1].value,"",where,"PNAME;CCODE") &amp;nbsp;&amp;nbsp;&amp;nbsp; pnames = [] &amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pnames.append(row.getValue("PNAME")) &amp;nbsp;&amp;nbsp;&amp;nbsp; del row, rows &amp;nbsp;&amp;nbsp;&amp;nbsp; pnames = sorted(set(pnames)) # uniqueize and sort &amp;nbsp;&amp;nbsp;&amp;nbsp; self.params[3].filter.list = pnames&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 May 2013 04:09:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/tool-validator-values-list-help/m-p/376579#M29732</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2013-05-14T04:09:32Z</dc:date>
    </item>
    <item>
      <title>Re: Tool Validator / Values List Help</title>
      <link>https://community.esri.com/t5/python-questions/tool-validator-values-list-help/m-p/376580#M29733</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Curtis,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the help.&amp;nbsp; Could you clarify where and how this code gets applied?&amp;nbsp; When I add the script into the toolbox do I set my parameters here at the Add Script dialog box?&amp;nbsp; I am a little confused with the Tool Validator stuff.&amp;nbsp; Thanks again.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 May 2013 13:28:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/tool-validator-values-list-help/m-p/376580#M29733</guid>
      <dc:creator>AllenSmith</dc:creator>
      <dc:date>2013-05-14T13:28:54Z</dc:date>
    </item>
    <item>
      <title>Re: Tool Validator / Values List Help</title>
      <link>https://community.esri.com/t5/python-questions/tool-validator-values-list-help/m-p/376581#M29734</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&amp;nbsp; Could you clarify where and how [validation] code gets applied? &lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;No, tool validation before your main script runs (that's the idea!) - the code is edited in the script tool properties/validation tab.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you have made the jump to Python toolboxes, the tool validation class is in a separate area of your code. (I still like doing it the old way -- less work!)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 May 2013 14:46:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/tool-validator-values-list-help/m-p/376581#M29734</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2013-05-14T14:46:40Z</dc:date>
    </item>
    <item>
      <title>Re: Tool Validator / Values List Help</title>
      <link>https://community.esri.com/t5/python-questions/tool-validator-values-list-help/m-p/376582#M29735</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ok, I just figured that out!&amp;nbsp; (thanks for the help).&amp;nbsp; I get a runtime error saying that the update Parameters() takes no arguments (1 given).&amp;nbsp; In my script that this will be used for, I am updating a tbale using sys.argv statements.&amp;nbsp; I am used to putting these in order in the parameters section of the Add Script&amp;nbsp; dialog box.&amp;nbsp; I entered the first 4 sys.argv statements as you suggested (parameters 0-3) and I think herein lies my problem.&amp;nbsp; Any other suggestions?&amp;nbsp; Thanks for the prompt responses.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 May 2013 14:53:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/tool-validator-values-list-help/m-p/376582#M29735</guid>
      <dc:creator>AllenSmith</dc:creator>
      <dc:date>2013-05-14T14:53:24Z</dc:date>
    </item>
    <item>
      <title>Re: Tool Validator / Values List Help</title>
      <link>https://community.esri.com/t5/python-questions/tool-validator-values-list-help/m-p/376583#M29736</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm not sure what your code is but sys.argv starts at 1 whereas getparameter starts at 0.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;So when you are assigning the input parameters your first sys.argv should be 1 and so on.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Please post your code if this is not your issue.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Joel&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 May 2013 18:25:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/tool-validator-values-list-help/m-p/376583#M29736</guid>
      <dc:creator>JoelCalhoun</dc:creator>
      <dc:date>2013-05-14T18:25:53Z</dc:date>
    </item>
    <item>
      <title>Re: Tool Validator / Values List Help</title>
      <link>https://community.esri.com/t5/python-questions/tool-validator-values-list-help/m-p/376584#M29737</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It's best practice to use arcpy.GetParameterAsText() instead of sys.argv[]. The main reason for this is that objects are passed more efficiently and robustly (especially if the string representation is large or complicated). &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;GetParameter() can also be used, but in most cases it's a lot easier to handle and debug a string representation than get the object directly.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;None of these options can be used in validation code -- there you must access the parameters as members of the self.params list.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 May 2013 23:15:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/tool-validator-values-list-help/m-p/376584#M29737</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2013-05-15T23:15:26Z</dc:date>
    </item>
    <item>
      <title>Re: Tool Validator / Values List Help</title>
      <link>https://community.esri.com/t5/python-questions/tool-validator-values-list-help/m-p/376585#M29738</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I've been in the field for the last couple of days so a big thanks to those who responded.&amp;nbsp; Hopefully you will still be able to help.&amp;nbsp; I am using sys.argv statements to allow the user to populate the fields in the table.&amp;nbsp; One of those fields will be populated by a dropdown list limited (hopefully by Tool Validator) to a subset of cities that lie within a selected county.&amp;nbsp; The County can either be user designated (sysargv) or preferably selected via mouse.&amp;nbsp; The code I am using is below:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#Import modules
import os
import sys
import arcpy

#Set Map Document
mxd = arcpy.mapping.MapDocument("Current")

#Set Overwrite Option
arcpy.env.overwriteOutput = True




#Sets parameters (attributes)
County = sys.argv[1]
Place = sys.argv[2]
CountyName = sys.argv[3]
PlaceName = sys.argv[4]
Office = sys.argv[5]
Forester = sys.srgv[6]
Activity = sys.argv[7]
Persons = sys.argv[8]
Underserverd = sys.argv[9]
NameLast = sys.argv[10]
NameFirst = sys.argv[11]


#Create a new row and fill in fields
rows = arcpy.InsertCursor("CommunityLevelActivity")
row = rows.newRow()
row.TFSOffice = Office
row.TFSForester = Forester
row.Activity = Activity
row.RecipientLast = NameLast
row.RecipientFirst = NameFirst
row.Persons = Persons
row.Underserved = Underserved
row.Place = PlaceName

rows.insertRow(row)
del row
del rows

#Calculate Date Field
expression = datetime.datetime.now()
arcpy.CalculateField_management("CommunityLevelActivity", "DateComplete", expression, "PYTHON_9.3")

# Refresh map to show all changes
arcpy.RefreshActiveView()
mxd.save()

# Refresh map to show all changes
arcpy.RefreshActiveView()
mxd.save()

del mxd, &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;One of the fields in the table is "Place" and this is the one I would like (think I need to use the Tool validator on) to populate using places (PlacesFC -a point FC) that are within a selected county Fc (CountyFC -a polygon FC).&amp;nbsp; I am not sure how to include Curt's code into the Tool Validator.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:23:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/tool-validator-values-list-help/m-p/376585#M29738</guid>
      <dc:creator>AllenSmith</dc:creator>
      <dc:date>2021-12-11T17:23:44Z</dc:date>
    </item>
    <item>
      <title>Re: Tool Validator / Values List Help</title>
      <link>https://community.esri.com/t5/python-questions/tool-validator-values-list-help/m-p/376586#M29739</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&amp;nbsp; I am not sure how to include Curt's code into the Tool Validator.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is complex enough you really need to read the online help before you go any further:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//00150000000t000000"&gt;Desktop 10.1 Help: Customizing script tool behavior&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The code I gave you is designed to be used in the code box you see when you right click on a script tool&amp;nbsp; and select&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;Properties&lt;/SPAN&gt;&lt;SPAN&gt; and go to the &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;Validation&lt;/SPAN&gt;&lt;SPAN&gt; tab.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 May 2013 14:21:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/tool-validator-values-list-help/m-p/376586#M29739</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2013-05-17T14:21:06Z</dc:date>
    </item>
  </channel>
</rss>

