Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

parameter dependencies fc to field python toolbox

$
0
0
so I have been looking but I can not seem to find how to populate a input field parameter that is based on the fc parameter. please note the dependence for p2.

Code:

import arcpy


class Toolbox(object):
    def __init__(self):
        """Define the toolbox (the name of the toolbox is the name of the
        .pyt file)."""
        self.label = "Toolbox"
        self.alias = ""

        # List of tool classes associated with this toolbox
        self.tools = [Tool]


class Tool(object):
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "Tool"
        self.description = ""
        self.canRunInBackground = False

    def getParameterInfo(self):
        """Define parameter definitions"""
            # First parameter
        p1 = arcpy.Parameter(
            displayName="Input Features",
            name="in_features",
            datatype="Feature Layer",
            parameterType="Required",
            direction="Input")

        p2 = arcpy.Parameter(
            displayName="Input Field",
            name="in_field",
            datatype="Field",
            parameterType="Derived",
            direction="Input")

        p2.parameterDependencies = ????

        p3 = arcpy.Parameter(
            displayName="Input String",
            name="in_string",
            datatype="String",
            parameterType="Required",
            direction="Input")

        return [p1, p2, p3]


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

    def updateMessages(self, parameters):
        """Modify the messages created by internal validation for each tool
        parameter.  This method is called after internal validation."""
        return

    def execute(self, parameters, messages):
        """The source code of the tool."""
        in_fc = parameters[0].valueAsText
        in_field = parameters[1].valueAsText
        in_string = parameters[2].valueAsText

        rows = arcpy.UpdateCursor(in_fc)

        for row in rows:
            row.setValue(in_field, in_string)
            rows.updateRow(row)

        del row, rows

        return


Viewing all articles
Browse latest Browse all 2485

Latest Images

Trending Articles



Latest Images