2

I've tried several different data types but can't figure out how to allow a user to create a list of elevation-temperature pairs. For example, a spreadsheet might look like this:

example values

Is there a parameter data type that would allow the user to specify these values as pairs?

  • 1
    You need to use a Value Table. Is your script in a regular toolbox or a python toolbox? – user2856 Mar 5 '15 at 8:13
  • I was about to say the same as @Luke i.e. that this is a use case for Value Tables which are only available with Python Toolboxes and not for Python script tools in standard toolboxes - see Creating value table parameters at resources.arcgis.com/en/help/main/10.2/index.html#//… – PolyGeo Mar 5 '15 at 8:35
7

Python Toolbox:

If your script is in a Python Toolbox, you can use a Value Table (GPValueTable).

def getParameterInfo(self):
    param0 = arcpy.Parameter(
        displayName='Elevation and Temperature',
        name='in_features',
        datatype='GPValueTable',
        parameterType='Required',
        direction='Input')

    param0.columns = [['Long', 'Elevation'], ['Long', 'Temperature']]

Regular Toolbox:

If your script is in a regular Toolbox, you can use a Record Set.

Using a record set in a regular toolbox is a little more complicated to set up as you have to create a new (empty) table to use as a schema for the Record Set parameter. What you can do is create a new File GDB alongside your script, create a table with Elevation and Temperature fields in that GDB, then add a Record Set parameter to your script and set the new table as the parameter schema. You may also be able to create this table in memory in the script ToolValidator.initializeParameters method, but I haven't tried that.

enter image description here enter image description here enter image description here

You can access the Record Set from within your script like so (assuming it is the first parameter and the schema has "Elevation" and "Temperature" fields, otherwise adjust code below accordingly):

import os, sys
import json
import arcpy

elev_temp = json.loads(arcpy.GetParameter(0).JSON)
for rec in elev_temp['features']:
    print rec['attributes']['Elevation'],rec['attributes']['Temperature']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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