摘要
每个工具参数都拥有一个包含可用于工具验证的属性和方法的关联 Parameter 对象。
语法
 Parameter  ({name}, {displayName}, {direction}, {datatype}, {parameterType}, {enabled}, {category}, {symbology}, {multiValue})| 参数 | 说明 | 数据类型 | 
| name | 参数名称。 (默认值为 None) | String | 
| displayName | 工具对话框上显示的参数标注。 (默认值为 None) | String | 
| direction | 参数的输入/输出方向。 (默认值为 None) | String | 
| datatype | 参数的数据类型。 要获取参数数据类型的列表,请参阅地理处理数据类型。 (默认值为 None) | String | 
| parameterType | parameterType 可以是 Required、Optional 或 Derived。Derived 表示工具的用户未输入参数值。Derived 类型始终为输出参数。 (默认值为 None) | String | 
| enabled | 如果参数不可用,则为 False。 (默认值为 None) | Boolean | 
| category | 参数的类别。 (默认值为 None) | String | 
| symbology | 用于绘制输出的图层文件(.lyr)的路径。 (默认值为 None) | String | 
| multiValue | 如果参数为多值参数,则为 True。 (默认值为 None) | Boolean | 
属性
| 属性 | 说明 | 数据类型 | 
| altered (只读) | 如果用户对值做出了修改,则为 True。 | Boolean | 
| category (可读写) | 参数的类别。 | String | 
| columns (可读写) | 值表参数的列数据类型和名称,使用一系列列表进行设置。  | String | 
| datatype (可读写) | 参数的数据类型。 要获取参数数据类型的列表,请参阅地理处理数据类型。 | String | 
| defaultEnvironmentName (可读写) | 用于设置参数的默认值的地理处理环境设置。 | String | 
| direction (可读写) | 参数的输入/输出方向。 | String | 
| displayName (可读写) | 工具对话框上显示的参数标注。 | String | 
| enabled (可读写) | 如果参数不可用,则为 False。 | Boolean | 
| filter (只读) | 要应用于参数中的值的过滤器。 | Filter | 
| filters (可读写) | 与 filter 相似,但用于支持值表参数。  | Filter | 
| hasBeenValidated (只读) | 如果内部验证例程已检查参数,则为 True。 | Boolean | 
| message (只读) | 要向用户显示的消息。 | String | 
| multiValue (可读写) | 如果参数为多值参数,则为 True。 | Boolean | 
| name (可读写) | 参数名称。 | String | 
| parameterDependencies (可读写) | 各依存参数的索引列表。 在脚本工具中,通过参数索引列表设置 parameterDependencies;在 Python 工具箱工具中,通过参数名称列表设置 parameterDependencies。 | Integer | 
| parameterType (可读写) | parameterType 可以是 Required、Optional 或 Derived。Derived 表示工具的用户未输入参数值。Derived 类型始终为输出参数。 
 | String | 
| schema (只读) | 输出数据集的方案。 | Schema | 
| symbology (可读写) | 用于绘制输出的图层文件(.lyr)的路径。 | String | 
| value (可读写) | 参数的值。 | Object | 
| valueAsText (只读) | 字符串形式的参数值。 | String | 
| values (可读写) | Value Table 参数的值,使用一系列列表进行设置。 | Variant | 
方法概述
| 方法 | 说明 | 
| clearMessage () | 清除所有消息文本并将状态设置为信息性的(无错误或警告)。 | 
| hasError () | 如果参数包含错误,则返回 true。 | 
| hasWarning () | 如果参数包含警告,则返回 True。 | 
| isInputValueDerived () | 如果在模型内部验证工具并且输入值是模型中其他工具的输出,则返回 True。 | 
| setErrorMessage (message) | 通过提供的消息将参数标记为存在错误。如果其中任何参数存在错误,则不会执行工具。 | 
| setIDMessage (message_type, message_ID, {add_argument1}, {add_argument2}) | 用于设置系统消息。 | 
| setWarningMessage (message) | 通过提供的消息将参数标记为存在警告。与存在错误时不同,工具在有警告消息的情况下也会执行。 | 
方法
clearMessage ()
hasError ()
返回值
| 数据类型 | 说明 | 
| Boolean | 如果参数包含错误,则为 True。 | 
hasWarning ()
返回值
| 数据类型 | 说明 | 
| Boolean | 如果参数包含警告,则为 True。 | 
isInputValueDerived ()
返回值
| 数据类型 | 说明 | 
| Boolean | 如果在模型内部验证工具并且输入值是模型中其他工具的输出,则为 True。 | 
setErrorMessage (message)
| 参数 | 说明 | 数据类型 | 
| message | 要作为错误消息添加到地理处理工具消息中的字符串。 | String | 
setIDMessage (message_type, message_ID, {add_argument1}, {add_argument2})| 参数 | 说明 | 数据类型 | 
| message_type | 定义消息为错误消息还是警告消息。 
 | String | 
| message_ID | 消息 ID 可用于参考现有的系统消息。 | Integer | 
| add_argument1 | 根据所使用的消息 ID,可能需要使用参数来完成消息。常见的示例包括数据集或字段名称。datatype 随着消息的不同而变化。 | Object | 
| add_argument2 | 根据所使用的消息 ID,可能需要使用参数来完成消息。常见的示例包括数据集或字段名称。datatype 随着消息的不同而变化。 | Object | 
setWarningMessage (message)
| 参数 | 说明 | 数据类型 | 
| message | 要作为警告消息添加到地理处理工具消息中的字符串。 | String | 
代码示例
参数示例
启用或禁用 ToolValidator 类中的参数。
def updateParameters(self):
    # If the option to use a weights file ("Get Spatial Weights From File") 
    # is selected, enable the parameter for specifying the file; 
    # otherwise, disable it
    if self.params[3].value == "Get Spatial Weights From File":
        self.params[8].enabled = True
    else:
        self.params[8].enabled = False
    return
参数示例 2
为 ToolValidator 类中的参数设置默认值。
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).
    if self.params[0].value:
        if not self.params[6].altered:
            extent = arcpy.Describe(self.params[0].value)
        width = extent.XMax - extent.XMin
        height = extent.YMax - extent.YMin
        if width < height:
            self.params[6].value = width / 100
        else:
            self.params[6].value = height / 100
        return
参数示例 3
为 ToolValidator 类中的参数设置自定义错误消息。
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