Zusammenfassung
Every tool parameter has an associated Parameter object with properties and methods that are useful in tool validation.
Diskussion
Although many Parameter object properties are read/write, most of these properties can only be set or modified when you initially create or modify the object. Several properties, including name, displayName, datatype, direction, and parameterType, establish the characteristics of a tool and cannot be modified during validation methods (such as updateMessages and updateParameters).
Syntax
Parameter ({name}, {displayName}, {direction}, {datatype}, {parameterType}, {enabled}, {category}, {symbology}, {multiValue})
Parameter | Erläuterung | Datentyp |
name | The parameter name. (Der Standardwert ist None) | String |
displayName | The parameter label as shown in the Geoprocessing pane. (Der Standardwert ist None) | String |
direction | The direction of the parameter. (Der Standardwert ist Input) | String |
datatype | The data type of the parameter. For a list of parameter data types, see Geoprocessing data types. (Der Standardwert ist GPString) | String |
parameterType | The parameter type. (Der Standardwert ist Required) | String |
enabled | Specifies whether the parameter is visible in the Geoprocessing pane. (Der Standardwert ist True) | Boolean |
category | The category of the parameter. (Der Standardwert ist None) | String |
symbology | The path to a layer file (.lyrx or .lyr) used for drawing the output. (Der Standardwert ist None) | String |
multiValue | Specifies whether the parameter is a multivalue parameter. (Der Standardwert ist False) | Boolean |
Eigenschaften
Eigenschaft | Erläuterung | Datentyp |
altered (Schreibgeschützt) | Specifies whether the user has modified the value. | Boolean |
category (Lesen und schreiben) | The category of the parameter. | String |
charts (Lesen und schreiben) | A list of Chart objects that are added to an output parameter. | Object |
columns (Lesen und schreiben) | 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 ReadOnly, the column cannot be modified by the user.
| String |
controlCLSID (Lesen und schreiben) | A class identifier that can be used to override the default control for the data type. | String |
datatype (Lesen und schreiben) | The data type of the parameter. For a list of parameter data types, see Geoprocessing data types. | String |
defaultEnvironmentName (Lesen und schreiben) | The name of the geoprocessing environment setting used to set the parameter's default value. | String |
direction (Lesen und schreiben) | The direction of the parameter.
| String |
displayName (Lesen und schreiben) | The parameter label as shown in the Geoprocessing pane. | String |
displayOrder (Lesen und schreiben) | 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 (Lesen und schreiben) | Specifies whether the parameter is visible in the Geoprocessing pane. | Boolean |
filter (Schreibgeschützt) | The filter to apply to values in the parameter. | Filter |
filters (Lesen und schreiben) | Similar to the filter property, but it is used to support value table parameters.
| Filter |
hasBeenValidated (Schreibgeschützt) | Specifies whether the internal validation routine has checked the parameter. | Boolean |
message (Schreibgeschützt) | The message to be displayed to the user. | String |
multiValue (Lesen und schreiben) | Specifies whether the parameter is a multivalue parameter. | Boolean |
name (Lesen und schreiben) | The parameter name. | String |
parameterDependencies (Lesen und schreiben) | 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 (Lesen und schreiben) | The parameter type.
For derived parameters, set the direction property to Output and the parameterType property to Derived. Bei der Validierung kann der parameterType-Wert nicht dynamisch geändert werden. Abhängig von den Parametereinstellungen muss jedoch ein Parameter möglicherweise das Verhalten eines optionalen oder eines erforderlichen Parameters aufweisen. Legen Sie in diesem Fall den Parameter als optionalen Parameter fest. Verwenden Sie dann in der updateMessages-Validierungsmethode die Parameter setIDMessage-Methode mit der Meldungs-ID 530 oder 735. Durch Verwendung der Meldungs-ID 530 oder 735 verhält sich ein optionaler Parameter als erforderlicher Parameter. | String |
schema (Schreibgeschützt) | The schema of the output dataset. | Schema |
symbology (Lesen und schreiben) | The path to a layer file (.lyrx or .lyr) used for drawing the output. | String |
value (Lesen und schreiben) | The value of the parameter. | Object |
valueAsText (Schreibgeschützt) | The value of the parameter as a string. | String |
values (Lesen und schreiben) | The values of a Value Table parameter, which is set using a list of lists. | Variant |
Methodenübersicht
Methode | Erläuterung |
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. To evaluate whether a parameter has an error, hasError should be called within the tool validation's updateMessages method. |
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) | Sets a 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}) | Sets a parameter as having a system message. |
setWarningMessage (message) | Sets a parameter as having an error with the supplied message. Unlike errors, tools will execute with warning messages. |
Methoden
clearMessage ()
hasError ()
Datentyp | Erläuterung |
Boolean | True if the parameter contains an error. |
hasWarning ()
Datentyp | Erläuterung |
Boolean | True if the parameter contains a warning. |
isInputValueDerived ()
Datentyp | Erläuterung |
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)
Parameter | Erläuterung | Datentyp |
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})
Parameter | Erläuterung | Datentyp |
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)
Parameter | Erläuterung | Datentyp |
message | The string to be added as a warning message to the geoprocessing tool messages. | String |
Codebeispiel
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