I figured out how to make it work in a Python Toolbox...
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 drop down list of the ACS text files and user can pick one
filterList = []
fol = r"---Path of Folder Containing ACS 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="Output")
param0.filter.list = filterList
#Make parameter #1 filter multi-value check list a of the table columns, the user can check multiple columns
pickTableFieldsList=[]
param1 = arcpy.Parameter(displayName = "Pick Join Fields:",
name = "in_fields",
datatype= "GPString",
parameterType= "Required",
direction= "Input",
multiValue=True)
param1.filter.type = "ValueList"
param1.filter.list = pickTableFieldsList
parameters = [param0,param1]
return parameters
def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True
def updateParameters(self, parameters):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
#When the 0th parameter gets a value the field headers (1st column in text file) are available to select
if parameters[0].value:
joinTable = os.path.join(r"---Folder Containing ACS Text Files Here", parameters[0].valueAsText + ".txt")
pickedTable = open(joinTable,"r")
pickedTableFieldsString = pickedTable.readline()
pickedTableFieldsString = pickedTableFieldsString.replace("\n","")
pickedTable.close()
pickedTableFieldsList = pickedTableFieldsString.split(",")
parameters[1].filter.list = pickedTableFieldsList
return