描述
使用字符串值按索引来设置指定参数属性。将值从脚本传递到脚本工具时会用到此函数。如果您需要将对象(例如空间参考)传递到脚本工具,请使用 SetParameter。
语法
SetParameterAsText (index, text)
参数 | 说明 | 数据类型 |
index | 参数列表中指定参数的索引位置。 | Integer |
text | 将设置指定参数属性的字符串值。 | String |
代码示例
SetParameterAsText 示例
将文本字符串传递到指定工具参数。
import arcpy
# Get the feature class from the tool.
#
fc = arcpy.GetParameterAsText(0)
# Determine the shape type of the feature class.
#
dscFC = arcpy.Describe(fc)
# Set tool output parameters based on shape type.
#
if dscFC.ShapeType.lower() == "polygon":
arcpy.AddMessage("Feature Type is polygon")
arcpy.SetParameterAsText(1, "true") # Is polygon
arcpy.SetParameterAsText(2, "false") # Is not line
arcpy.SetParameterAsText(3, "false") # Is not point
elif dscFC.ShapeType.lower() == "polyline":
arcpy.AddMessage("Feature Type is polyline")
arcpy.SetParameterAsText(1, "false") # Is not polygon
arcpy.SetParameterAsText(2, "true") # Is line
arcpy.SetParameterAsText(3, "false") # Is not point
elif dscFC.ShapeType.lower() == "point":
arcpy.AddMessage("Feature Type is point")
arcpy.SetParameterAsText(1, "false") # Is not polygon
arcpy.SetParameterAsText(2, "false") # Is not line
arcpy.SetParameterAsText(3, "true") # Is point
else:
arcpy.AddMessage("Unknown feature type")
arcpy.SetParameterAsText(1, "false") # Is not polygon
arcpy.SetParameterAsText(2, "false") # Is not line
arcpy.SetParameterAsText(3, "false") # Is not point