<?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 Using variables from execution script in the class toolvalidator in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/using-variables-from-execution-script-in-the-class/m-p/1211359#M65532</link>
    <description>&lt;P&gt;Hello everyone! I'd really appreciate your help.&lt;/P&gt;&lt;P&gt;I am creating my first script toolbox in ArcGISPro, and I want to use a variable defined in the execution script.&lt;/P&gt;&lt;P&gt;How can I call a variable from the script and use it in the validation script?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HodaEL_0-1662816010290.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/50866i13C331720FA61FC1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HodaEL_0-1662816010290.png" alt="HodaEL_0-1662816010290.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HodaEL_2-1662816407569.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/50868i37B6DAAAA9D013F3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HodaEL_2-1662816407569.png" alt="HodaEL_2-1662816407569.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 10 Sep 2022 13:27:59 GMT</pubDate>
    <dc:creator>HodaEL</dc:creator>
    <dc:date>2022-09-10T13:27:59Z</dc:date>
    <item>
      <title>Using variables from execution script in the class toolvalidator</title>
      <link>https://community.esri.com/t5/python-questions/using-variables-from-execution-script-in-the-class/m-p/1211359#M65532</link>
      <description>&lt;P&gt;Hello everyone! I'd really appreciate your help.&lt;/P&gt;&lt;P&gt;I am creating my first script toolbox in ArcGISPro, and I want to use a variable defined in the execution script.&lt;/P&gt;&lt;P&gt;How can I call a variable from the script and use it in the validation script?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HodaEL_0-1662816010290.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/50866i13C331720FA61FC1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HodaEL_0-1662816010290.png" alt="HodaEL_0-1662816010290.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HodaEL_2-1662816407569.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/50868i37B6DAAAA9D013F3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HodaEL_2-1662816407569.png" alt="HodaEL_2-1662816407569.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Sep 2022 13:27:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-variables-from-execution-script-in-the-class/m-p/1211359#M65532</guid>
      <dc:creator>HodaEL</dc:creator>
      <dc:date>2022-09-10T13:27:59Z</dc:date>
    </item>
    <item>
      <title>Re: Using variables from execution script in the class toolvalidator</title>
      <link>https://community.esri.com/t5/python-questions/using-variables-from-execution-script-in-the-class/m-p/1211440#M65533</link>
      <description>&lt;P&gt;If you are trying to create a parameter filter based on a selection, you should do that within the Validation class.&amp;nbsp; It executes python commands just like the execution block so you can dynamically create filters from other data. I don't think the internal wiring allows for modifying just the filter of a parameter outside of the Validation class.&lt;/P&gt;&lt;P&gt;Make my_content a parameter pointing to your data by default (used param[0] for the example and then build your list from there:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    def updateParameters(self):
        # get the list values
        if self.params[1].value == 'dashboard':
            fcFilter = self.params[1].filter

            # use list comprehension and set to return a distinct list of values.
            attributevalues = list(
                set([cnt.title for cnt in self.params[0].valueAsText])) # parameter set to what the my_content variable is.

            # sort alphabetically
            attributevalues.sort()

            # set the parameter list
            fcFilter.list = attributevalues&lt;/LI-CODE&gt;&lt;P&gt;If you must do it in through the execution (script), you may have to override/extend the Script Tool/ toolbox / Validation class to create the class methods to set values, or you can try by using SetParameterAsText and some dummy parameters.&lt;/P&gt;&lt;P&gt;It would be (using the next parameter index that is available):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;L = ['a','b','c']

arcpy.SetParameterAsText(5, L)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then do some parsing in the Validation class when the parameter is modified to make it into a list since you can only pass Objects or Text. I am not sure if the disabled boolean will also disable accessing/setting other properties.&amp;nbsp; This is untested:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    def initializeParameters(self):
        # disable the dummy param to hide it from the UI
        self.params[5].enabled = False
        return

    def updateParameters(self):
        # Modify parameter values and properties.
        # This gets called each time a parameter is modified, before
        # standard validation.
        if self.params[1].altered:
            if self.params[1].value == 'dashboard':
                if isinstance(self.params[5].value, str):
                    self.params[1].filterlist = self.params[5].value.strip('][').split(', ')

        return&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You'll have to play around with it.&lt;/P&gt;</description>
      <pubDate>Sun, 11 Sep 2022 14:51:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-variables-from-execution-script-in-the-class/m-p/1211440#M65533</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-09-11T14:51:11Z</dc:date>
    </item>
  </channel>
</rss>

