Parameter (arcpy)

摘要

Every tool parameter has an associated parameter object with properties and methods that are useful in tool validation. Parameters are contained in a Python list.

语法

Parameter ({name}, {displayName}, {direction}, {datatype}, {parameterType}, {enabled}, {category}, {symbology}, {multiValue})
参数说明数据类型
name

The parameter name.

(默认值为 None)

String
displayName

The parameter label as shown on the tool's dialog box.

(默认值为 None)

String
direction

Input/Output direction of the parameter.

(默认值为 None)

String
datatype

The data type of the parameter.

For a list of parameter data types, see Geoprocessing data types.

(默认值为 None)

String
parameterType

Can be Required, Optional, or Derived. Derived means that the user of your tool does not enter a value for the parameter. Derived types are always output parameters.

(默认值为 None)

String
enabled

False if the parameter is unavailable.

(默认值为 None)

Boolean
category

The category of the parameter.

(默认值为 None)

String
symbology

The path to a layer file (.lyr) used for drawing the output.

(默认值为 None)

String
multiValue

True if the parameter is a multivalue parameter.

(默认值为 None)

Boolean

属性

属性说明数据类型
altered
(只读)

True if the user has modified the value.

Boolean
category
(读写)

The category of the parameter.

String
columns
(读写)

The column data types and names of a value table parameter. Set using a list of lists:

import arcpy
param = arcpy.Parameter()
param.datatype = "Value Table"
param.columns = [["Feature Layer", "Features"], ["Long", "Ranks"]]
String
datatype
(读写)

The data type of the parameter.

For a list of parameter data types, see Geoprocessing data types.

String
defaultEnvironmentName
(读写)

The geoprocessing environment setting used to set the parameter's default value.

String
direction
(读写)

Input/Output direction of the parameter.

String
displayName
(读写)

The parameter label as shown on the tool's dialog box.

String
enabled
(读写)

False if the parameter is unavailable.

Boolean
filter
(只读)

The filter to apply to values in the parameter.

Filter
hasBeenValidated
(只读)

True if the internal validation routine has checked the parameter.

Boolean
message
(只读)

The message to be displayed to the user.

String
multiValue
(读写)

True if the parameter is a multivalue parameter.

Boolean
name
(读写)

The parameter name.

String
parameterDependencies
(读写)

A list of indexes of each dependent parameter.

Integer
parameterType
(读写)

Can be Required, Optional, or Derived. Derived means that the user of your tool does not enter a value for the parameter. Derived types are always output parameters.

  • RequiredA Required parameter requires an input value from the user. The tool cannot be executed until a value has been supplied.
  • Optional An Optional parameter does not require a value.
  • DerivedA Derived parameter is only for output parameters. A derived output parameter does not show on the tool dialog box.
String
schema
(只读)

The schema of the output dataset.

Schema
symbology
(读写)

The path to a layer file (.lyr) used for drawing the output.

String
value
(读写)

The value of the parameter.

Object
valueAsText
(只读)

The value of the parameter as a string.

注注:

For Python toolboxes only.

String
values
(读写)

The values of the Value Table parameter. Set using a list of lists.

Variant

方法概述

方法说明
clearMessage ()

Clears out any message text and sets the status to informative (no error or warning).

hasError ()

Returns true if the parameter contains an error.

hasWarning ()

Returns True if the parameter contains a warning.

isInputValueDerived ()

Returns True if the tool is being validated inside a Model and the input value is the output of another tool in the model.

setErrorMessage (message)

Marks the parameter as having an error with the supplied message. Tools do not execute if any of the parameters have an error.

setIDMessage (message_type, message_ID, {add_argument1}, {add_argument2})

用于设置系统消息。

setWarningMessage (message)

Marks the parameter as having a warning with the supplied message. Unlike errors, tools will execute with warning messages.

方法

clearMessage ()
hasError ()
返回值
数据类型说明
Boolean

True if the parameter contains an error.

hasWarning ()
返回值
数据类型说明
Boolean

True if the parameter contains a warning.

isInputValueDerived ()
返回值
数据类型说明
Boolean

True if the tool is being validated inside a Model and the input value is the output of another tool in the model.

setErrorMessage (message)
参数说明数据类型
message

The string to be added as an error message to the geoprocessing tool messages.

String
setIDMessage (message_type, message_ID, {add_argument1}, {add_argument2})
参数说明数据类型
message_type

Defines whether the message will be an error or a warning.

  • ERRORThe message will be an error message.
  • WARNINGThe message will be a warning message.
String
message_ID

The message ID allows you to reference existing system messages.

Integer
add_argument1

Depending on which message ID is used, an argument may be necessary to complete the message. Common examples include dataset or field names. The datatype is variable depending on the message.

Object
add_argument2

Depending on which message ID is used, an argument may be necessary to complete the message. Common examples include dataset or field names. The datatype is variable depending on the message.

Object
setWarningMessage (message)
参数说明数据类型
message

The string to be added as a warning message to the geoprocessing tool messages.

String

代码实例

Parameter example

Enabling or disabling a parameter in a ToolValidator class.

def updateParameters(self):

  # If the option to use a weights file is selected (the user chose
  #  "Get Spatial Weights From File", enable the parameter for specifying 
  #  the file, otherwise disable it
  #
  if self.params[3].value == "Get Spatial Weights From File":
    self.params[8].enabled = 1
  else:
    self.params[8].enabled = 0
Parameter example 2

Setting a default value for a parameter in a ToolValidator class.

def updateParameters(self):
  # Set the default distance threshold to 1/100 of the larger of the width
  #  or height of the extent of the input features.  Do not set if there is no 
  #  input dataset yet, or the user has set a specific distance (Altered is true).
  # 
  import string

  if self.params[0].value:
    if not self.params[6].altered:
      extent = string.split(self.GP.Describe\
                           (self.params[0].value).extent, " ")
      width = float(extent[2]) - float(extent[0])
      height = float(extent[3]) - float(extent[1])
      if width > height:
        self.params[6].value = width / 100
      else:
        self.params[6].value = height / 100
                
        return
Parameter example 3

Setting a custom error message for a parameter in a ToolValidator class.

def updateMessages(self):
  self.params[6].clearMessage()

  # Check to see if the threshold distance contains a value of zero and the user has
  #  specified a fixed distance band.
  #
  if self.params[6].value <= 0:
    if self.params[3].value == "Fixed Distance Band":
      self.params[6].setErrorMessage("Zero or a negative distance is invalid \
                                      when using a fixed distance band. Please \
                                      use a positive value greater than zero." )
      elif self.params[6].value < 0:
        self.params[6].setErrorMessage("A positive distance value is required \
                                        when using a fixed distance band. \
                                        Please specify a distance.")

  return

相关主题

9/15/2013