AnsweredAssumed Answered

Is there a way to set columns of a table after load

Question asked by Liz.Eidsness_aafc on Dec 5, 2017

I am creating a Python Toolbox.  I have a RecordSet parameter.  I'd like to be able to set the columns during the updateParameters method.  It does not.  parameter[x].columns is not settable outside of getParameterInfo

 

Is there a way to do this where I could?  Here is a greatly simplified look at the problem.

 

import arcpy

class Toolbox(object):
    def __init__(self):
        self.label = "Toolbox"
        self.alias = ""
        self.tools = [Tool]


class Tool(object):
    def __init__(self):
        self.label = "Tool"
        self.description = ""
        self.canRunInBackground = False

    def getParameterInfo(self):

        param0 = arcpy.Parameter(
            displayName="Column Names",
            name="my_columns",
            datatype="GPString",
            parameterType="Required",
            direction="Input")
        param0.filter.list = ["ABC","XYZ"]

        param1 = arcpy.Parameter(
            displayName="Table",
            name="my_table",
            datatype="GPValueTable",
            parameterType="Required",
            direction="Input")

        param1.columns = [['GPLong',"ID"],["GPString","A"],["GPString","B"],["GPString","C"]]

        params = [param0,param1]
        return params

    def updateParameters(self, parameters):
        if (parameters[0].altered and not parameters[0].hasBeenValidated):
            if (parameters[0].value == "ABC"):
                parameters[1].columns = [['GPLong',"ID"],["GPString","A"],["GPString","B"],["GPString","C"]]
            else:
                parameters[1].columns = [['GPLong',"ID"],["GPString","X"],["GPString","Y"],["GPString","Z"]]

        return

    def isLicensed(self):
        return True

    def updateMessages(self, parameters):
        return

    def execute(self, parameters, messages):
        return

 

Thanks,

Outcomes