<?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 Passing Field Names from a MultiValue Parameter in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/passing-field-names-from-a-multivalue-parameter/m-p/1053938#M61002</link>
    <description>&lt;P&gt;I am creating a custom tool that involves 3 steps.&amp;nbsp; First, allow the user to pick one or more feature classes from a geodatabase.&amp;nbsp; Next, from those chosen features, generate a list of fields that are from those selected feature classes.&amp;nbsp; Lastly, export each selected feature class to another database, and if the field was selected, do not include that field (if it exists of course).&amp;nbsp; It all kinda works like this code:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os

fc = arcpy.GetParameterAsText(0).split(";") if arcpy.GetParameterAsText(0).find(";") &amp;gt; -1 else [arcpy.GetParameterAsText(0)]
fields = arcpy.GetParameterAsText(1).split(";") if arcpy.GetParameterAsText(1).find(";") &amp;gt; -1 else [arcpy.GetParameterAsText(1)]
output_database = arcpy.GetParameterAsText(2)


arcpy.AddMessage(fc)
# From the selected features, create a list
feature_list = []
for each in fc:
    # arcpy.CopyFeatures_management(each, "{}_Layer".format(each))
    arcpy.AddMessage(each)
    arcpy.MakeFeatureLayer_management(each, "{0}_lyr".format(os.path.splitext(os.path.basename(each))[0]))
    feature_list.append("{0}_lyr".format(os.path.splitext(os.path.basename(each))[0]))

# From the selected features list, create a list with their field names
fieldList = []
for each in feature_list:
    fieldnames = [f.name for f in arcpy.ListFields(each)]
    for fields in fieldnames:
        if fields not in fieldList:
            fieldList.append(fields)

print(fieldList)

# Using fieldList, exclude these fields from Field_mapping
# ........... &lt;/LI-CODE&gt;&lt;P&gt;So far, I have lines of code that accomplish the first two steps, but I am unsure how to incorporate this into a custom script.&amp;nbsp; I am assuming I need to use the tool validation?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def updateParameters(self):
    """Modify the values and properties of parameters before internal
    validation is performed.  This method is called whenever a parameter
    has been changed."""
    if self.params[0].value:
        lyr = self.params[0].valueAsText.split(";")
        fieldList = [f.name for f in arcpy.ListFields(lyr)]
        self.params[1].value=fieldList
    return&lt;/LI-CODE&gt;&lt;P&gt;When I run this with the tool I get an IOError: *file path* does not exist.&amp;nbsp; I get this error a lot and I have no idea what causes it.&lt;/P&gt;&lt;P&gt;I don't know how I did it before but I managed to pass the fields from multiple feature classes, but the tool wouldn't work if I only selected one feature class.&amp;nbsp; I have since attempted to fix that issue but I got the above error message.&amp;nbsp; In my efforts to fix this error I have basically had to start over.&lt;/P&gt;&lt;P&gt;Anyway, my question is, how can I pass field names from the MultiValue Feature Class parameter to my next MultiValue Field parameter (which will also be used for another step)?&lt;/P&gt;</description>
    <pubDate>Mon, 03 May 2021 19:28:51 GMT</pubDate>
    <dc:creator>EvanMyers1</dc:creator>
    <dc:date>2021-05-03T19:28:51Z</dc:date>
    <item>
      <title>Passing Field Names from a MultiValue Parameter</title>
      <link>https://community.esri.com/t5/python-questions/passing-field-names-from-a-multivalue-parameter/m-p/1053938#M61002</link>
      <description>&lt;P&gt;I am creating a custom tool that involves 3 steps.&amp;nbsp; First, allow the user to pick one or more feature classes from a geodatabase.&amp;nbsp; Next, from those chosen features, generate a list of fields that are from those selected feature classes.&amp;nbsp; Lastly, export each selected feature class to another database, and if the field was selected, do not include that field (if it exists of course).&amp;nbsp; It all kinda works like this code:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os

fc = arcpy.GetParameterAsText(0).split(";") if arcpy.GetParameterAsText(0).find(";") &amp;gt; -1 else [arcpy.GetParameterAsText(0)]
fields = arcpy.GetParameterAsText(1).split(";") if arcpy.GetParameterAsText(1).find(";") &amp;gt; -1 else [arcpy.GetParameterAsText(1)]
output_database = arcpy.GetParameterAsText(2)


arcpy.AddMessage(fc)
# From the selected features, create a list
feature_list = []
for each in fc:
    # arcpy.CopyFeatures_management(each, "{}_Layer".format(each))
    arcpy.AddMessage(each)
    arcpy.MakeFeatureLayer_management(each, "{0}_lyr".format(os.path.splitext(os.path.basename(each))[0]))
    feature_list.append("{0}_lyr".format(os.path.splitext(os.path.basename(each))[0]))

# From the selected features list, create a list with their field names
fieldList = []
for each in feature_list:
    fieldnames = [f.name for f in arcpy.ListFields(each)]
    for fields in fieldnames:
        if fields not in fieldList:
            fieldList.append(fields)

print(fieldList)

# Using fieldList, exclude these fields from Field_mapping
# ........... &lt;/LI-CODE&gt;&lt;P&gt;So far, I have lines of code that accomplish the first two steps, but I am unsure how to incorporate this into a custom script.&amp;nbsp; I am assuming I need to use the tool validation?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def updateParameters(self):
    """Modify the values and properties of parameters before internal
    validation is performed.  This method is called whenever a parameter
    has been changed."""
    if self.params[0].value:
        lyr = self.params[0].valueAsText.split(";")
        fieldList = [f.name for f in arcpy.ListFields(lyr)]
        self.params[1].value=fieldList
    return&lt;/LI-CODE&gt;&lt;P&gt;When I run this with the tool I get an IOError: *file path* does not exist.&amp;nbsp; I get this error a lot and I have no idea what causes it.&lt;/P&gt;&lt;P&gt;I don't know how I did it before but I managed to pass the fields from multiple feature classes, but the tool wouldn't work if I only selected one feature class.&amp;nbsp; I have since attempted to fix that issue but I got the above error message.&amp;nbsp; In my efforts to fix this error I have basically had to start over.&lt;/P&gt;&lt;P&gt;Anyway, my question is, how can I pass field names from the MultiValue Feature Class parameter to my next MultiValue Field parameter (which will also be used for another step)?&lt;/P&gt;</description>
      <pubDate>Mon, 03 May 2021 19:28:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/passing-field-names-from-a-multivalue-parameter/m-p/1053938#M61002</guid>
      <dc:creator>EvanMyers1</dc:creator>
      <dc:date>2021-05-03T19:28:51Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Field Names from a MultiValue Parameter</title>
      <link>https://community.esri.com/t5/python-questions/passing-field-names-from-a-multivalue-parameter/m-p/1053961#M61005</link>
      <description>&lt;P&gt;Is your&amp;nbsp;multivalue input for fields a boolean value list (checkboxes) or something else?&lt;/P&gt;</description>
      <pubDate>Mon, 03 May 2021 20:11:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/passing-field-names-from-a-multivalue-parameter/m-p/1053961#M61005</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-05-03T20:11:10Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Field Names from a MultiValue Parameter</title>
      <link>https://community.esri.com/t5/python-questions/passing-field-names-from-a-multivalue-parameter/m-p/1053967#M61006</link>
      <description>&lt;P&gt;I managed to get the tool to stop the file path error but now it only lists the fields from first feature class (wControlValve).&amp;nbsp; When I remove that one, it lists the fields from the wHydrants.&lt;/P&gt;&lt;P&gt;Right now my tool looks like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="EvanMyers1_0-1620072805747.png" style="width: 521px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/12443i416C639FEA28E19F/image-dimensions/521x438?v=v2" width="521" height="438" role="button" title="EvanMyers1_0-1620072805747.png" alt="EvanMyers1_0-1620072805747.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 03 May 2021 20:17:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/passing-field-names-from-a-multivalue-parameter/m-p/1053967#M61006</guid>
      <dc:creator>EvanMyers1</dc:creator>
      <dc:date>2021-05-03T20:17:59Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Field Names from a MultiValue Parameter</title>
      <link>https://community.esri.com/t5/python-questions/passing-field-names-from-a-multivalue-parameter/m-p/1053975#M61009</link>
      <description>&lt;P&gt;All the Python Toolboxes I've seen have&amp;nbsp;updateParameters defined like&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def updateParameters(self, parameters):&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;So you should have a parameters argument that you can use instead of self.params, but that's just more of a curiosity.&lt;/P&gt;&lt;P&gt;self.params[0].values should return a list of values instead of splitting the delimited string. And I don't see where you're actually iterating over the list of feature classes. Try something like&lt;/P&gt;&lt;LI-CODE lang="python"&gt;if self.params[0].values:
    lyrs = self.params[0].values
    fieldList = []
    for lyr in self.params[0].values:
        fieldList.append([f.name for f in arcpy.ListFields(lyr)])
    self.params[1].values = sorted(fieldList)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;However, I've never worked with multivalue inputs so I could be way off.&lt;/P&gt;</description>
      <pubDate>Mon, 03 May 2021 20:33:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/passing-field-names-from-a-multivalue-parameter/m-p/1053975#M61009</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-05-03T20:33:49Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Field Names from a MultiValue Parameter</title>
      <link>https://community.esri.com/t5/python-questions/passing-field-names-from-a-multivalue-parameter/m-p/1053984#M61011</link>
      <description>&lt;P&gt;I tried your suggestion and it did not work unfortunately.&amp;nbsp; I did a hybrid but now I get a message saying "ListFields(*gp_fixargs(args, True))) IOError: "C" does not exist"&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;if self.params[0].values:
    lyrs = self.params[0].valueAsText.split(";")[0]
    fieldList = []
    for lyr in lyrs:
        fieldList.append([f.name for f in arcpy.ListFields(lyr)])
    self.params[1].values = sorted(fieldList)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 May 2021 20:55:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/passing-field-names-from-a-multivalue-parameter/m-p/1053984#M61011</guid>
      <dc:creator>EvanMyers1</dc:creator>
      <dc:date>2021-05-03T20:55:50Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Field Names from a MultiValue Parameter</title>
      <link>https://community.esri.com/t5/python-questions/passing-field-names-from-a-multivalue-parameter/m-p/1053994#M61012</link>
      <description>&lt;P&gt;For debugging, try only having this in&amp;nbsp;updateParameters() just to see what you're working with&lt;/P&gt;&lt;LI-CODE lang="python"&gt;self.params[0].setWarningMessage(self.params[0].values)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 May 2021 21:32:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/passing-field-names-from-a-multivalue-parameter/m-p/1053994#M61012</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-05-03T21:32:13Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Field Names from a MultiValue Parameter</title>
      <link>https://community.esri.com/t5/python-questions/passing-field-names-from-a-multivalue-parameter/m-p/1054419#M61030</link>
      <description>&lt;P&gt;Sorry for the late reply, but I tried your suggestion and nothing seemed to happen when I added this.&amp;nbsp; When I open the tool and add Feature Classes for my first parameter, nothing shows up in the fields list, but no errors either.&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 20:55:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/passing-field-names-from-a-multivalue-parameter/m-p/1054419#M61030</guid>
      <dc:creator>EvanMyers1</dc:creator>
      <dc:date>2021-05-04T20:55:56Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Field Names from a MultiValue Parameter</title>
      <link>https://community.esri.com/t5/python-questions/passing-field-names-from-a-multivalue-parameter/m-p/1054426#M61033</link>
      <description>&lt;P&gt;It would show up in the yellow warning icon next to the input. You could also print it out with&amp;nbsp;arcpy.AddMessage() but you have to comment out enough code to get it to run so you can see the message in the geoprocessing results.&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 21:19:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/passing-field-names-from-a-multivalue-parameter/m-p/1054426#M61033</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-05-04T21:19:46Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Field Names from a MultiValue Parameter</title>
      <link>https://community.esri.com/t5/python-questions/passing-field-names-from-a-multivalue-parameter/m-p/1058078#M61125</link>
      <description>&lt;P&gt;I got my code working so far with no errors, and my field list updates properly when I add or remove feature classes, but now I have a new problem.&lt;/P&gt;&lt;P&gt;When I press the "Select All" or "Unselect All" buttons, they don't to do anything, and if I click anywhere (even in another application), all of the boxes are re-check themselves.&lt;/P&gt;&lt;P&gt;I suspect it is because of the updateParameters section of the tool Validator, but I can't wrap my head around the logic the tool is using.&amp;nbsp; No matter what my order of indentation is in the code it always wants to refresh the list.&lt;/P&gt;&lt;P&gt;Here is my code so far:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;  def updateParameters(self):
    """Modify the values and properties of parameters before internal
    validation is performed.  This method is called whenever a parameter
    has been changed."""

    if self.params[0].value:
      fclist = self.params[0].valueAsText.split(";") if self.params[0].valueAsText.find(";") &amp;gt; -1 else [
        self.params[0].valueAsText]
      if ";" in fclist:
        fclist.split(";")
      elif "'" in fclist:
        [f.strip("'") for f in fclist]
      else:
        [f.strip("'") for f in fclist]
      if self.params[0].altered:
        fieldlist = []
        for each in fclist:
          fieldnames = [f.name for f in arcpy.ListFields(each)]
          for fields in fieldnames:
            if fields not in fieldlist:
              fieldlist.append(fields)
        self.params[1].value = fieldlist
    return&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 May 2021 15:56:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/passing-field-names-from-a-multivalue-parameter/m-p/1058078#M61125</guid>
      <dc:creator>EvanMyers1</dc:creator>
      <dc:date>2021-05-14T15:56:50Z</dc:date>
    </item>
  </channel>
</rss>

