[GIS] Implementing MultiValue Parameter with Multiple Columns with Python and ArcGIS Desktop

arcgis-9.3arcpypython-script-tool

I am working on an ArcGIS (9.3) Python script. One of the inputs is a list of features. For each feature, I need to select a corresponding field. Setting the parameter to MultiValue gives a nice table in the UI for all the features being processed. How do I add another column to the MultiValue table to select a field for each feature?

Cross-posted: http://forums.arcgis.com/threads/30907-MultiValue-Parameter-with-Multiple-Columns

Esri's Answer from the ArcGIS forum:

Unfortunately, the solution for this was implemented just recently for
10.1 with ValueTable inputs for script tools. You will need to have two multivalue parameters with some custom validation to make this
work for 9.3.1.

Best Answer

I've worked out how to do this albeit in a fairly simple manner. I wanted to create a multivalue parameter where I add many FeatureLayers and then choose an ID field for each layer. I've got it working but I was unable to work how to make the field a drop down list, so a user has to enter a field name manually. Here is the interface:

Example interface

If anyone has managed to crack this problem or some guru from ESRI blesses us with their knowledge I would love to find out how to turn my second column (Site ID) into a drop down, listing specific fields. If you want to see an example of this have a look at the Create TIN tool.

Anyway to create this interface I create a script tool and added a parameter of type feature layer and set it to a multivalue as shown below.

Initial interface setting

I then clicked on the Validation tab at the top and then the Edit button. As this parameter is the 6th parameter in my script tool I updated the following code:

def initializeParameters(self):
    """Refine the properties of a tool's parameters.  This method is
    called when the tool is opened."""

    # Get the 6th parameter
    param = self.params[6]
    param.datatype = "Value Table"
    param.columns = [["Feature Layer","Activity Layer"],["Field","Site ID"]]    
    return

This resets the interface into the multi column table that I wanted. When you use GetParameterAsText it returns the following using my example:

pipeline pid;Dredging did


I've done some more research and have created the tool using a python toolbox. It works very well but does have a limitation if you go back and choose another ID. I have posted the code on GeoNet here.