Multiple value inputs

Many geoprocessing tools have input parameters that accept multiple values. Any parameter that is a multivalue (accepts multiple values of a data type) or a Value Table (a parameter data type that combines two or more data types in a table-like structure) accepts multiple values.

Multivalue and Value Table parameters can be specified as follows:

  • A list—Values are an element in a list.
  • A string—Values are separated by semicolons.
  • A ValueTable object—Values are stored in a virtual table of rows and columns.

In a tool's reference page, on the Python tab, multivalue and Value Table parameters will show a representation in square brackets ([]) below the parameter name. For example, the Delete Field tool has a multivalue field parameter and the parameter usage shows [drop_field, ...]. The Union tool has a Value Table parameter that accepts input datasets along with a rank value. Its parameter usage displays as [[in_features, {rank}], ...].

As a list

In Python, multivalue and Value Table parameters can be expressed as a list. A list is enclosed in brackets and is a flexible Python type.

The DeleteField function using a list for the drop_field parameter.

import arcpy 

arcpy.env.workspace = 'C:/base/county.gdb'
arcpy.management.DeleteField('roads', ['STREET_NAM', 'LABEL', 'CLASS'])

The Union function using a list for the Value Table in_features parameter.

import arcpy

arcpy.env.workspace = 'C:/base/data/gdb' 
arcpy.analysis.Union([['counties', 2],['parcels', 1]], 'state_landinfo')

As a string

Multivalue and Value Table parameters can be expressed as a string. In a multivalue parameter, the values are delimited by a semicolon. In a Value Table parameter, each row is delimited with a semicolon and values within a row are delimited with a space.

The DeleteField function using a string for the multivalue drop_field parameter.

import arcpy 

arcpy.env.workspace = 'C:/base/county.gdb'
arcpy.management.DeleteField('roads', 'STREET_NAM;LABEL;CLASS')

The Union function using a string for the Value Table in_features parameter.

import arcpy 

arcpy.env.workspace = 'C:/base/data/gdb' 
arcpy.analysis.Union('counties 2;parcels 1', 'state_landinfo')

As a Value Table

A ValueTable allows you to organize values into a virtual table of rows and columns. You specify the number of columns when you create a value table. The default is a single column.

The DeleteField function using a ValueTable object for the multivalue drop_field parameter.

import arcpy 

arcpy.env.workspace = 'C:/base/county.gdb'

value_table = arcpy.ValueTable()
value_table.addRow('STREET_NAM')
value_table.addRow('LABEL')
value_table.addRow('CLASS')

arcpy.management.DeleteField('roads', value_table)

The Union function using a ValueTable object for the Value Table in_features parameter.

import arcpy 

arcpy.env.workspace = 'C:/base/data/gdb' 

value_table = arcpy.ValueTable(2)
value_table.addRow(['counties', 2])
value_table.addRow(['parcels', 1])

arcpy.analysis.Union(value_table, 'state_landinfo')

このトピックの内容
  1. As a list
  2. As a string
  3. As a Value Table