Synthèse
From the parameter list, select the desired parameter by its index or its name. The parameter is returned as an object.
Remarque :
The GetParameter function is for use with script tools (.tbx, .atbx). For a Python toolbox (.pyt) tool, access a parameter's value using the Parameter object's value property.
Discussion
To use the parameter as a text string instead, see the GetParameterAsText function.
Syntaxe
GetParameter (index)
Paramètre | Explication | Type de données |
index | The index position of the parameter, or the name of the parameter. | Integer |
Type de données | Explication |
Parameter | The parameter value returned as an object. |
Exemple de code
Get a script tool parameter as an object. The script tool has one parameter that accepts a spatial reference object. The parameter is selected by its index.
import arcpy
# Get the spatial reference from the tool dialog.
spatial_ref = arcpy.GetParameter(0)
# Display the Spatial Reference properties
arcpy.AddMessage("Name is: {0}".format(spatial_ref.name))
arcpy.AddMessage("Type is: {0}".format(spatial_ref.type))
arcpy.AddMessage("Factory code is: {0}".format(spatial_ref.factoryCode))
Get a script tool parameter as an object. The script tool has one parameter named in_spatial_reference, that accepts a spatial reference object. The parameter is selected by its name.
import arcpy
# Get the spatial reference from the tool dialog.
spatial_ref = arcpy.GetParameter("in_spatial_reference")
# Display the Spatial Reference properties
arcpy.AddMessage(f"Name is: {spatial_ref.name}")
arcpy.AddMessage(f"Type is: {spatial_ref.type}")
arcpy.AddMessage(f"Factory code is: {spatial_ref.factoryCode}")
Rubriques connexes
Vous avez un commentaire à formuler concernant cette rubrique ?