I am trying to create my first Python Toolbox. I have tons of ACS text file, comma field separated files. I want my users to easily be able to join the tables to the geometry file. My first parameter, the list of available text files is working. Then, when I add the next parameter for the users to pick which fields they want to join from the text file as a check list is not working. Not sure how to set this up the parameters properly? Any help is much appreciated?
import arcpy
import os
class Toolbox(object):
def __init__(self):
"""Define the toolbox (the name of the toolbox is the name of the
.pyt file)."""
self.label = "ACS_2013_5Year_Toolbox"
self.alias = ""
# List of tool classes associated with this toolbox
self.tools = [ACSJoinTableTool]
class ACSJoinTableTool(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Join ACS Table to Census Block Group Geometry"
self.description = "Pick a table to temporarily join to the" + \
"Block Group GIS layer."
self.canRunInBackground = False
def getParameterInfo(self):
"""Define parameter definitions"""
#Make parameter #0 a list of the ACS text files.
filterList = []
fol = r"---file path of folder containing text files here---"
for i in os.listdir(fol):
if i.split(".")[-1].find("txt") != -1:
x = i.split(".")[0]
filterList.append(x)
filterList.sort()
param0 = arcpy.Parameter(displayName = "Pick Table:",
name = "in_table",
datatype="GPString",
parameterType="Required",
direction="Input")
param0.filter.list = filterList
#Make parameter #1 a list of the table columns
joinTable = os.path.join(r"---file path of folder containing text files here---", param[0].valueAsText + ".txt")
pickedTable = open(jointable,"r")
pickedTableFields = pickedTable.readline()
pickedTableFields = pickedTableFields.replace(",",";")
param1 = arcpy.Parameter(displayName = "Pick Join Fields:",
name = "in_fields",
datatype="GPString",
parameterType="Derived",
direction="Input")
param1.parameterDependencies = [param0.value]
param1.filter.list = pickedTableFields
parameters = [param0,param1]
return parameters