摘要
返回给定工具的参数对象列表,并且通常用在脚本工具的 ToolValidator 类中。
语法
GetParameterInfo (tool_name)
参数 | 说明 | 数据类型 |
tool_name | 工具名称。在其中包括工具箱别名有助于解决重复工具名称之间的任何冲突。 | String |
返回值
数据类型 | 说明 |
Parameter | 返回参数对象列表。 |
代码示例
GetParameterInfo 示例 1
显示指定工具的某些参数对象属性。
import arcpy
# Load tool parameter objects into list.
params = arcpy.GetParameterInfo("HotSpots")
for param in params:
print("Name: {}, Type: {}, Value: {}".format(
param.name, param.parameterType, param.value))
GetParameterInfo 示例 2
设置脚本工具输出数据集的符号。
import os
import arcpy
# Set data variables for Clip tool.
in_features = arcpy.GetParameterAsText(0)
clip_features = arcpy.GetParameterAsText(1)
out_feature_class = arcpy.GetParameterAsText(2)
# Execute Clip tool
output = arcpy.Clip_analysis(in_features, clip_features,
out_feature_class)[0]
# Get parameter objects
params = arcpy.GetParameterInfo()
# Use describe on result object and get shape type.
desc = arcpy.Describe(output)
# Set symbology property for out_feature_class parameter
# Layer files are located in same folder as the .py file
lyr_location = os.path.dirname(__file__)
if desc.shapeType == "Polygon":
params[2].symbology = os.path.join(lyr_location, "Polygon.lyr")
elif desc.shapeType == "Polyline":
params[2].symbology = os.path.join(lyr_location, "Polyline.lyr")
else:
params[2].symbology = os.path.join(lyr_location, "Point.lyr")