<?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: A toolbox parameter can either depend on other parameters or user enter value, how to realize? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/a-toolbox-parameter-can-either-depend-on-other/m-p/1340106#M69009</link>
    <description>&lt;P&gt;Okay, maybe something like this then.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;if parameters[0].value:
    if not parameters[0].hasBeenValidated:
        param0_default, param1_default = default[parameters[0].valueAsText]
        parameters[1].value = param0_default
        parameters[2].value = param1_default
else:
    parameters[1].value = None
    parameters[2].value = None&lt;/LI-CODE&gt;&lt;P&gt;Using the&amp;nbsp;hasBeenValidated property will tell you if it was just changed. So with this, if the category was just changed, set the default measured values. After that, if the user changes the default measured values, they should be left alone. The measured values would only get changed if the user changed the category again.&lt;/P&gt;</description>
    <pubDate>Fri, 20 Oct 2023 16:32:36 GMT</pubDate>
    <dc:creator>BlakeTerhune</dc:creator>
    <dc:date>2023-10-20T16:32:36Z</dc:date>
    <item>
      <title>A toolbox parameter can either depend on other parameters or user enter value, how to realize?</title>
      <link>https://community.esri.com/t5/python-questions/a-toolbox-parameter-can-either-depend-on-other/m-p/1339834#M68997</link>
      <description>&lt;P&gt;I'm a newbie and I am creating a toolbox for python. I have a parameter A about categories that need to be selected by the user, there are 5 categories. Parameter A selects a category, and parameter B and C show the default parameter when that category is selected. If the user has a measured value for parameter B or C, then they can also enter it themselves.&lt;/P&gt;&lt;P&gt;I have created the following code but it is not working properly.&amp;nbsp;When I change the value of A, B and C do not change with it.&amp;nbsp;What should I do, please?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

default = {"Class A":  [1.46, 1.50],
           "Class B":  [1.46, 1.70],
           "Class C":  [0.35, 1.50],
           "Class D":  [0.35, 1.80],
           "Class E":  [0.35, 1.50]}
   
class Interfacemodel(object):
    def __init__(self) -&amp;gt; None:
    self.label = "model"
        self.description = """model"""

def getParameterInfo(self) -&amp;gt; list:
        """Define parameter definitions.
        """
        Option = arcpy.Parameter(name="class",
                                 displayName="class",
                                 datatype="String",
                                 parameterType="Required",
                                 direction="Input")
        choices = ["Class A", "Class B", "Class C", "Class D", "Class E"]
        Option.filter.list = choices
        Option.value = "Class A"

    param0 = arcpy.Parameter(name="param0",
                                 displayName="param0",
                                 datatype="GPDouble",
                                 parameterType="Required",
                                 direction="Input")
        param0.value = 1.46

param1 = arcpy.Parameter(name="param1",
                                 displayName="param1",
                                 datatype="GPDouble",
                                 parameterType="Required",
                                 direction="Input")
        param0.value = 1.50

return [Option, param0, param1]

def updateParameters(self, parameters) -&amp;gt; None:
    if parameters[0].altered:
            if not parameters[1].altered:
                parameters[1].value = default[parameters[0].valueAsText][0]
            if not parameters[2].altered:
                parameters[2].value = default[parameters[0].valueAsText][1]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2023 21:48:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/a-toolbox-parameter-can-either-depend-on-other/m-p/1339834#M68997</guid>
      <dc:creator>WeiMao</dc:creator>
      <dc:date>2023-10-19T21:48:03Z</dc:date>
    </item>
    <item>
      <title>Re: A toolbox parameter can either depend on other parameters or user enter value, how to realize?</title>
      <link>https://community.esri.com/t5/python-questions/a-toolbox-parameter-can-either-depend-on-other/m-p/1339840#M68998</link>
      <description>&lt;P&gt;Reading &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/geoprocessing_and_python/customizing-tool-behavior-in-a-python-toolbox.htm#GUID-F347F5FD-0DF8-4931-827D-EC90EA80D35F" target="_self"&gt;the documentation&lt;/A&gt;, it says:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;Once a parameter has been altered, it remains altered until the user empties (removes) the value in which case it returns to an unaltered state. Programmatically changing a value with validation code will change the altered state. That is, if you set a value for a parameter, the altered state of the parameter will be updated.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;So when you set the value of the parameter in&amp;nbsp;getParameterInfo(), I think it's coming through as altered in&amp;nbsp;updateParameters(). Try removing the lines where you set the value of&amp;nbsp;param0 and&amp;nbsp;param1. You can also use the &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/geoprocessing_and_python/customizing-tool-behavior-in-a-python-toolbox.htm#GUID-7BB6CB76-B030-41F0-B609-F54EE0027C27" target="_self"&gt;hasBeenValidated property&lt;/A&gt; to determine if it was changed.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Maybe to simplify this, try checking if there is a value and, if not, set the default.&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;if parameters[0].value:
    if not parameters[1].value:
        parameters[1].value = default[parameters[0].valueAsText][0]
    if not parameters[2].value:
        parameters[2].value = default[parameters[0].valueAsText][1]
else:
    parameters[1].value = None
    parameters[2].value = None&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 19 Oct 2023 22:12:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/a-toolbox-parameter-can-either-depend-on-other/m-p/1339840#M68998</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2023-10-19T22:12:59Z</dc:date>
    </item>
    <item>
      <title>Re: A toolbox parameter can either depend on other parameters or user enter value, how to realize?</title>
      <link>https://community.esri.com/t5/python-questions/a-toolbox-parameter-can-either-depend-on-other/m-p/1339994#M69004</link>
      <description>&lt;P&gt;Thank you very much sir.&amp;nbsp;I tried the above code, but with a little regret. For example, when I select Class C, the value of parameters[1] doesn't change automatically, it only changes to the default value when I remove its value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;The intention is that when I choose different class, the parameters will automatically change to the default value.&amp;nbsp;But users are allowed to change the default value if they want to.&amp;nbsp;I'm still trying and haven't found a better solution yet.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2023 13:39:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/a-toolbox-parameter-can-either-depend-on-other/m-p/1339994#M69004</guid>
      <dc:creator>WeiMao</dc:creator>
      <dc:date>2023-10-20T13:39:43Z</dc:date>
    </item>
    <item>
      <title>Re: A toolbox parameter can either depend on other parameters or user enter value, how to realize?</title>
      <link>https://community.esri.com/t5/python-questions/a-toolbox-parameter-can-either-depend-on-other/m-p/1340106#M69009</link>
      <description>&lt;P&gt;Okay, maybe something like this then.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;if parameters[0].value:
    if not parameters[0].hasBeenValidated:
        param0_default, param1_default = default[parameters[0].valueAsText]
        parameters[1].value = param0_default
        parameters[2].value = param1_default
else:
    parameters[1].value = None
    parameters[2].value = None&lt;/LI-CODE&gt;&lt;P&gt;Using the&amp;nbsp;hasBeenValidated property will tell you if it was just changed. So with this, if the category was just changed, set the default measured values. After that, if the user changes the default measured values, they should be left alone. The measured values would only get changed if the user changed the category again.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2023 16:32:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/a-toolbox-parameter-can-either-depend-on-other/m-p/1340106#M69009</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2023-10-20T16:32:36Z</dc:date>
    </item>
    <item>
      <title>Re: A toolbox parameter can either depend on other parameters or user enter value, how to realize?</title>
      <link>https://community.esri.com/t5/python-questions/a-toolbox-parameter-can-either-depend-on-other/m-p/1340143#M69010</link>
      <description>&lt;P&gt;Great. Thank you very much, sir.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2023 18:07:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/a-toolbox-parameter-can-either-depend-on-other/m-p/1340143#M69010</guid>
      <dc:creator>WeiMao</dc:creator>
      <dc:date>2023-10-20T18:07:30Z</dc:date>
    </item>
  </channel>
</rss>

