3

I am creating a python tool which looks like the figure below.

enter image description here

Input feature: It asks for a input feature class. Valuetable(Lookup tables): It has two columns - one for look up tables and another for fields.

The fields in value table should have dependency on Input feature. is this possible ? How ?

Code:

 def getParameterInfo(self):
    param1 = arcpy.Parameter(
        displayName = "Input Feature",
        name = "in_features",
        datatype = "DEFeatureClass",
        parameterType = "Required",
        direction= "Input")
    param1.filter.list = ["Polyline"]

    param2 = arcpy.Parameter(
        displayName='Lookup tables',
        name='lookup',
        datatype='GPValueTable',
        parameterType='Required',
        direction='Input')

    param2.columns = [ ['DETable', 'LookupTable'], ['Field', 'Fields']]


    param2.filters[1].type="ValueList"  
    desc = arcpy.Describe(param1)  
    fields = desc.fields
    l=[]
    for f in fields:
        l.append(f.name)
    param2.filters[1].list = l

    param3 = arcpy.Parameter(
        displayName='Output',
        name='excel',
        datatype='DEFile',
        parameterType='Required',
        direction='Output')
    param3.filter.list = ['xls', 'xlsx']



    params = [param1, param2, param3]
    return params
5
  • Typically, you would set parameter dependencies like this: param2.parameterDependencies = [param1.name]. But it sounds like you want the user to add a table into the Value Table as a "Lookup Table", and then choose a field from that? Is that what you mean?
    – crmackey
    Commented Aug 21, 2015 at 15:57
  • Someone can correct me if I'm wrong here, but if this what you are wanting to do, I don't think it's possible to set a filter on the Field column of your value table based on the Lookup Table value in that same row in a PYT. You might be able to customize this in .NET, but I'm not sure. It would be awesome though if Esri implemented an advanced filter option where you could dynamically change filters in each row of the Value Table.
    – crmackey
    Commented Aug 21, 2015 at 16:10
  • No. let me correct you. The field in valueTable has dependency on the Input feature class and not lookup tables.
    – Jio
    Commented Aug 21, 2015 at 18:41
  • I added some more code after param2 definition though it doesnot work.
    – Jio
    Commented Aug 21, 2015 at 18:57
  • Haha, ok. I was able to get it to work, but I think in order to use parameter dependencies you have to have the Fields as the first column in the Value Table. Se my answer below.
    – crmackey
    Commented Aug 21, 2015 at 19:18

1 Answer 1

1

I think you need to have the Fields as the first column in the Value Table in order to use the parameter dependency:

import arcpy
import pythonaddins

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 = [SomeTool]

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

    def getParameterInfo(self):
        param1 = arcpy.Parameter(
            displayName = "Input Feature",
            name = "in_features",
            datatype = "DEFeatureClass",
            parameterType = "Required",
            direction= "Input")
        param1.filter.list = ["Polyline"]

        param2 = arcpy.Parameter(
            displayName='Lookup tables',
            name='lookup',
            datatype='GPValueTable',
            parameterType='Required',
            direction='Input')

        param2.columns = [ ['Field', 'Fields'], ['DETable', 'LookupTable']]


        param3 = arcpy.Parameter(
            displayName='Output',
            name='excel',
            datatype='DEFile',
            parameterType='Required',
            direction='Output')
        param3.filter.list = ['xls', 'xlsx']
        param2.parameterDependencies = [param1.name]

        params = [param1, param2, param3]
        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."""

        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."""
        arcpy.AddMessage('Success')   
        return

enter image description here

enter image description here

2
  • Yes. by putting in first column it is possible but then how can i select the lookup tables interactively ? I think in your example you wrote the names "foo" and "bar" . You did not select them from file system . isnt it ?
    – Jio
    Commented Aug 21, 2015 at 19:35
  • I just typed those in. These value tables seem kind of limited on what you can do. I have been tinkering with it and cannot seem to get more than one drop down to work. I thought I would be able to do nested lists in the UpdateParameters method, something like parameters[2].filter.list = [[fieldList, lookupTable] for fieldList, lookupTable in valuetable] but this didn't work either. It may not be possible in a PYT.
    – crmackey
    Commented Aug 21, 2015 at 19:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.