AnsweredAssumed Answered

Assign field names by default to a python toolbox value table column

Question asked by jonczerniak on Sep 6, 2017
Latest reply on Sep 7, 2017 by jonczerniak

I'm sure this exists somewhere, but I've been unable to find an answer that works with my code.  I'm trying to take the attribute field names that are assigned as parameter dependencies in my code and have them appear by default in the first column of my value table.  See pics below: 

 

 

Any help would be great.  I've also attached the code.  Thanks!

 

 

 def getParameterInfo(self):
        in_features = arcpy.Parameter(
            displayName="Input Feature",
            name="in_features",
            datatype="GPFeatureLayer",
            parameterType="Required",
            direction="Input")

        # Text field to request the name of the new layer
        layerTitle = arcpy.Parameter(
            displayName="New Layer Name",
            name="layerTitle",
            datatype="GPString",
            parameterType="Required",
            direction="Input")

        # Setup Value Table
        valueTable = arcpy.Parameter(
            displayName="Value Table",
            name="valueTable",
            datatype="GPValueTable",
            parameterType="Optional",
            direction="Input")

        valueTable.columns = [['field', 'Column Name'], ['GPBoolean', 'Hide Field?'], ['GPString', 'New Alias']]
        valueTable.parameterDependencies = [in_features.name]
        valueTable.filters[1].type = 'ValueList'
        valueTable.filters[1].list = ['True', 'False']

        # Add output location for layer file
        outputParam = arcpy.Parameter(
            displayName="Output Location",
            name="outLocation",
            datatype="GPFeatureLayer",
            parameterType="Derived",
            direction="Output")

        outputParam.parameterDependencies = [in_features.name]
        outputParam.schema.clone = True

        params = [in_features, layerTitle, valueTable, outputParam]
        return params

    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."""

        in_features = parameters[0].valueAsText

        if parameters[0].value:
            if not parameters[2].altered:
                fields = arcpy.ListFields(in_features)
                vtab = []
                for field in fields:
                    if field.name != "u'OBJECTID" or field.name != "u'GEOMETRY'":
                        vtab.append([field.name])
                parameters[2].values = vtab


        return

 

Thank you for you time and consideration!

 

Cz

Outcomes