Parameter
サマリー
Every tool parameter has an associated Parameter object with properties and methods that are useful in tool validation.
ディスカッション
Although many Parameter object properties are read/write, most of them can only be set or modified when you initially create or modify the object. The following properties establish the characteristics of a parameter and cannot be modified during validation methods (such as updateMessages and updateParameters):
categorycontrolCLSIDdatatypedirectiondisplayNamedisplayOrdermultiValuenameparameterDependenciesparameterType
構文
Parameter({name}, {displayName}, {direction}, {datatype}, {parameterType}, {enabled}, {category}, {symbology}, {multiValue})
| 名前 | 説明 | データ タイプ |
|---|---|---|
|
name (オプション) |
The parameter name. The default value is None. |
String |
|
displayName (オプション) |
The parameter label as shown in the Geoprocessing pane. The default value is None. |
String |
|
direction (オプション) |
Specifies the direction of the parameter. The default value is Input. |
String |
|
datatype (オプション) |
The data type of the parameter. Learn more about geoprocessing data types. The default value is GPString. |
String |
|
parameterType (オプション) |
Specifies the parameter type. The default value is Required. |
String |
|
enabled (オプション) |
Specifies whether the parameter is visible in the Geoprocessing pane. The default value is True. |
Boolean |
|
category (オプション) |
The category of the parameter. The default value is None. |
String |
|
symbology (オプション) |
The path to a layer file ( The default value is None. |
String |
|
multiValue (オプション) |
Specifies whether the parameter is a multivalue parameter. The default value is False. |
Boolean |
プロパティ
| 名前 | 説明 | データ タイプ |
|---|---|---|
|
altered (読み取り専用) |
Specifies whether the user has modified the value. |
Boolean |
|
category (読み取り/書き込み) |
The category of the parameter. |
String |
|
charts (読み取り/書き込み) |
A list of |
Object |
|
columns (読み取り/書き込み) |
The structure of the columns in a Value Table parameter. The columns are organized in a list of lists, with each inner list representing the column data type, column name, and an optional read-only value. If the read-only value is set to
|
String |
|
controlCLSID (読み取り/書き込み) |
A class identifier that can be used to override the default control for the data type. |
String |
|
datatype (読み取り/書き込み) |
The data type of the parameter. |
String |
|
defaultEnvironmentName (読み取り/書き込み) |
The name of the geoprocessing environment that will be used to set the parameter's default value. |
String |
|
direction (読み取り/書き込み) |
Specifies the direction of the parameter.
|
String |
|
displayName (読み取り/書き込み) |
The parameter label as shown in the Geoprocessing pane. |
String |
|
displayOrder (読み取り/書き込み) |
The order in which a parameter displays in the Geoprocessing pane. This may be different from the order the parameters are accessed from Python. |
Integer |
|
enabled (読み取り/書き込み) |
Specifies whether the parameter is visible in the Geoprocessing pane. |
Boolean |
|
filter (読み取り専用) |
The filter to apply to values in the parameter. |
Filter |
|
filters (読み取り/書き込み) |
Similar to the For a value table parameter, set the
For a composite parameter, set the
|
Filter |
|
hasBeenValidated (読み取り専用) |
Specifies whether the internal validation routine has checked the parameter. |
Boolean |
|
message (読み取り専用) |
The message to be displayed to the user. |
String |
|
multiValue (読み取り/書き込み) |
Specifies whether the parameter is a multivalue parameter. |
Boolean |
|
name (読み取り/書き込み) |
The parameter name. |
String |
|
parameterDependencies (読み取り/書き込み) |
A list of indexes of each dependent parameter. In a script tool, |
Integer |
|
parameterType (読み取り/書き込み) |
Specifies the parameter type.
For derived parameters, set the In validation, the |
String |
|
schema (読み取り専用) |
The schema of the output dataset. |
Schema |
|
symbology (読み取り/書き込み) |
The path to a layer file ( |
String |
|
value (読み取り/書き込み) |
The value of the parameter. |
Object |
|
valueAsText (読み取り専用) |
The value of the parameter as a string. |
String |
|
values (読み取り/書き込み) |
The values of a Value Table parameter, which is set using a list of lists. |
Object |
方法
clearMessage()
Clears any message text and sets the status to informative (no error or warning).
hasError()
Returns True if the parameter contains an error.
To evaluate whether a parameter has an error, call hasError from the tool validation's updateMessages method.
戻り値
| データ タイプ | 説明 |
|---|---|
|
Boolean |
|
hasWarning()
Specifies whether the parameter contains a warning.
戻り値
| データ タイプ | 説明 |
|---|---|
|
Boolean |
Returns whether the parameter contains a warning. |
isInputValueDerived()
Specifies whether the tool is validated inside a model and the input value is the output of another tool in the model.
戻り値
| データ タイプ | 説明 |
|---|---|
|
Boolean |
Returns whether the tool is validated inside a model and the input value is the output of another tool in the model. |
setErrorMessage(message)
Sets a parameter as having an error with the supplied message. Tools do not execute if any of the parameters have an error.
| 名前 | 説明 | データ タイプ |
|---|---|---|
|
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})
Sets a parameter as having a system message.
| 名前 | 説明 | データ タイプ |
|---|---|---|
|
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)
Sets a parameter as having an error with the supplied message. Unlike errors, tools will execute with warning messages.
| 名前 | 説明 | データ タイプ |
|---|---|---|
|
message |
The string to be added as a warning message to the geoprocessing tool messages. |
String |
コードのサンプル
Enable or disable a parameter in a ToolValidator class.
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
Set 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).
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
Set a custom error message for a parameter in a ToolValidator class.
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