Parameter
汇总
每个工具参数都拥有一个包含可用于工具验证的属性和方法的关联 Parameter 对象。
讨论
虽然很多 Parameter 对象属性为读/写,但其中大多数属性只能在最初创建或修改对象时进行设置或修改。 以下属性建立了参数的特征,并且在验证方法(例如 updateMessages 和 updateParameters )执行期间不能修改:
categorycontrolCLSIDdatatypedirectiondisplayNamedisplayOrdermultiValuenameparameterDependenciesparameterType
语法
Parameter({name}, {displayName}, {direction}, {datatype}, {parameterType}, {enabled}, {category}, {symbology}, {multiValue})
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
name (可选) |
参数名称。 (默认值为 None) |
String |
|
displayName (可选) |
地理处理 窗格中显示的参数标注。 (默认值为 None) |
String |
|
direction (可选) |
指定参数的方向。 (默认值为 Input) |
String |
|
datatype (可选) |
参数的数据类型。 (默认值为 GPString) |
String |
|
parameterType (可选) |
指定参数类型。 (默认值为 Required) |
String |
|
enabled (可选) |
指定参数在 地理处理 窗格中是否可见。 (默认值为 True) |
Boolean |
|
category (可选) |
参数的类别。 (默认值为 None) |
String |
|
symbology (可选) |
用于绘制输出的图层文件( (默认值为 None) |
String |
|
multiValue (可选) |
指定参数是否为多值参数。 (默认值为 False) |
Boolean |
属性
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
altered (只读) |
制定用户是否修改了值。 |
Boolean |
|
category (读取和写入) |
参数的类别。 |
String |
|
charts (读取和写入) |
添加至输出参数的 |
Object |
|
columns (读取和写入) |
“值表”参数中的列结构。 这些列按列表的列表形式进行组织,每个内部列表表示列数据类型、列名称和可选只读值。 如果只读值设置为
|
String |
|
controlCLSID (读取和写入) |
可用于覆盖数据类型的默认控件的类标识符。 |
String |
|
datatype (读取和写入) |
参数的数据类型。 |
String |
|
defaultEnvironmentName (读取和写入) |
将用于设置参数默认值的地理处理环境名称。 |
String |
|
direction (读取和写入) |
指定参数的方向。
|
String |
|
displayName (读取和写入) |
地理处理 窗格中显示的参数标注。 |
String |
|
displayOrder (读取和写入) |
参数在 地理处理 窗格中的显示顺序。 该顺序可能与从 Python 访问参数的顺序不同。 |
Integer |
|
enabled (读取和写入) |
指定参数在 地理处理 窗格中是否可见。 |
Boolean |
|
filter (只读) |
要应用于参数中值的 过滤器 。 |
Filter |
|
filters (读取和写入) |
与 对于值表参数,设置
对于复合参数,设置
|
Filter |
|
hasBeenValidated (只读) |
指定内部验证例程是否检查了参数。 |
Boolean |
|
message (只读) |
要向用户显示的消息。 |
String |
|
multiValue (读取和写入) |
指定参数是否为多值参数。 |
Boolean |
|
name (读取和写入) |
参数名称。 |
String |
|
parameterDependencies (读取和写入) |
各依存参数的索引列表。 在脚本工具中,使用参数索引列表设置 |
Integer |
|
parameterType (读取和写入) |
指定参数类型。
对于派生参数,将 在验证中,无法动态修改 |
String |
|
schema (只读) |
输出数据集的 方案 。 |
Schema |
|
symbology (读取和写入) |
用于绘制输出的图层文件( |
String |
|
value (读取和写入) |
参数的值。 |
Object |
|
valueAsText (只读) |
字符串形式的参数值。 |
String |
|
values (读取和写入) |
值表参数的值,使用一系列列表进行设置。 |
Object |
方法
clearMessage()
清除所有消息文本并将状态设置为信息性状态(无错误或警告)。
hasError()
如果参数包含错误,则返回 True 。
要评估参数是否包含错误,应在工具验证的 updateMessages 方法中调用 hasError 。
返回值
| 数据类型 | 说明 |
|---|---|
|
Boolean |
如果参数包含错误,则为 |
hasWarning()
指定参数是否包含警告。
返回值
| 数据类型 | 说明 |
|---|---|
|
Boolean |
返回参数是否包含警告。 |
isInputValueDerived()
指定是否在模型内部验证工具,以及输入值是否是模型中另一个工具的输出。
返回值
| 数据类型 | 说明 |
|---|---|
|
Boolean |
返回是否在模型内部验证工具,并且输入值是否是模型中另一个工具的输出。 |
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.
|
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 data type 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 data type 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 |
代码示例
在 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
为 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
为 ToolValidator 类中的参数设置自定义错误消息。
def updateMessages(self):
self.params[6].clearMessage()
# Check whether 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. Be sure to specify "
"a distance.")
return