I am creating a custom tool that involves 3 steps. First, allow the user to pick one or more feature classes from a geodatabase. Next, from those chosen features, generate a list of fields that are from those selected feature classes. 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). It all kinda works like this code:
import arcpy
import os
fc = arcpy.GetParameterAsText(0).split(";") if arcpy.GetParameterAsText(0).find(";") > -1 else [arcpy.GetParameterAsText(0)]
fields = arcpy.GetParameterAsText(1).split(";") if arcpy.GetParameterAsText(1).find(";") > -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
# ........... 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. I am assuming I need to use the tool validation?
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
returnWhen I run this with the tool I get an IOError: *file path* does not exist. I get this error a lot and I have no idea what causes it.
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. I have since attempted to fix that issue but I got the above error message. In my efforts to fix this error I have basically had to start over.
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)?