Resumen
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.
Sintaxis
Parameter ({name}, {displayName}, {direction}, {datatype}, {parameterType}, {enabled}, {category}, {symbology}, {multiValue})
Parámetro | Explicación | Tipo de datos |
name | The parameter name. (El valor predeterminado es None) | String |
displayName | The parameter label as shown on the tool's dialog box. (El valor predeterminado es None) | String |
direction | Input/Output direction of the parameter. (El valor predeterminado es None) | String |
datatype | The data type of the parameter. For a list of parameter data types, see Geoprocessing data types. (El valor predeterminado es 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. (El valor predeterminado es None) | String |
enabled | False if the parameter is unavailable. (El valor predeterminado es None) | Boolean |
category | The category of the parameter. (El valor predeterminado es None) | String |
symbology | The path to a layer file (.lyr) used for drawing the output. (El valor predeterminado es None) | String |
multiValue | True if the parameter is a multivalue parameter. (El valor predeterminado es None) | Boolean |
Propiedades
Propiedad | Explicación | Tipo de datos |
altered (Sólo lectura) | True if the user has modified the value. | Boolean |
category (Lectura y escritura) | The category of the parameter. | String |
columns (Lectura y escritura) | The column data types and names of a value table parameter, which is set using a list of lists:
| String |
datatype (Lectura y escritura) | The data type of the parameter. For a list of parameter data types, see Geoprocessing data types. | String |
defaultEnvironmentName (Lectura y escritura) | The geoprocessing environment setting used to set the parameter's default value. | String |
direction (Lectura y escritura) | Input/Output direction of the parameter. | String |
displayName (Lectura y escritura) | The parameter label as shown on the tool's dialog box. | String |
enabled (Lectura y escritura) | False if the parameter is unavailable. | Boolean |
filter (Sólo lectura) | The filter to apply to values in the parameter. | Filter |
filters (Lectura y escritura) | Similar to filter, but used to support value table parameters, including drop-down menus.
| Filter |
hasBeenValidated (Sólo lectura) | True if the internal validation routine has checked the parameter. | Boolean |
message (Sólo lectura) | The message to be displayed to the user. | String |
multiValue (Lectura y escritura) | True if the parameter is a multivalue parameter. | Boolean |
name (Lectura y escritura) | The parameter name. | String |
parameterDependencies (Lectura y escritura) | A list of indexes of each dependent parameter. In a script tool, parameterDependencies is set with a list of parameter indexes; in a Python toolbox tool, parameterDependencies is set with a list of parameter names. | Integer |
parameterType (Lectura y escritura) | 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.
| String |
schema (Sólo lectura) | The schema of the output dataset. | Schema |
symbology (Lectura y escritura) | The path to a layer file (.lyr) used for drawing the output. | String |
value (Lectura y escritura) | The value of the parameter. | Object |
valueAsText (Sólo lectura) | The value of the parameter as a string. | String |
values (Lectura y escritura) | The values of the Value Table parameter, which is set using a list of lists. | Variant |
Vista general del método
Método | Explicación |
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}) | Allows you to set a system message. |
setWarningMessage (message) | Marks the parameter as having a warning with the supplied message. Unlike errors, tools will execute with warning messages. |
Métodos
clearMessage ()
hasError ()
Valor de retorno
Tipo de datos | Explicación |
Boolean | True if the parameter contains an error. |
hasWarning ()
Valor de retorno
Tipo de datos | Explicación |
Boolean | True if the parameter contains a warning. |
isInputValueDerived ()
Valor de retorno
Tipo de datos | Explicación |
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)
Parámetro | Explicación | Tipo de datos |
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})
Parámetro | Explicación | Tipo de datos |
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 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)
Parámetro | Explicación | Tipo de datos |
message | The string to be added as a warning message to the geoprocessing tool messages. | String |
Muestra de código
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 choose
# "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
return
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).
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
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