摘要
使用字符串值按索引或参数名称设置指定参数属性。 此函数用于将值从脚本传递到脚本工具。 如果您需要传递对象,例如 SpatialReference 对象,请使用 SetParameter 函数。
语法
SetParameterAsText (index, text)
参数 | 说明 | 数据类型 |
index | The specified parameter's index position or parameter name. | Integer |
text | The string value that will set the specified parameter's property. | String |
代码示例
按索引将字符串传递到指定工具参数。
import arcpy
# Get the feature class from the tool.
fc = arcpy.GetParameterAsText(0)
# Determine the shape type of the feature class.
describe = arcpy.Describe(fc)
# Set tool output parameters based on shape type.
if describe.shapeType == "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 describe.shapeType == "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 describe.shapeType == "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
按参数名称将字符串传递到指定工具参数。
该工具有四个参数,一个输入和三个输出。 参数名称为 in_features、is_polygon、is_line 和 is_point。
import arcpy
# Get the feature class from the tool.
fc = arcpy.GetParameterAsText("in_features")
# Determine the shape type of the feature class.
describe = arcpy.Describe(fc)
# Set tool output parameters based on shape type.
if describe.shapeType == "Polygon":
arcpy.AddMessage("Feature Type is polygon")
arcpy.SetParameterAsText("is_polygon", "true")
arcpy.SetParameterAsText("is_line", "false")
arcpy.SetParameterAsText("is_point", "false")
elif describe.shapeType == "Polyline":
arcpy.AddMessage("Feature Type is polyline")
arcpy.SetParameterAsText("is_polygon", "false")
arcpy.SetParameterAsText("is_line", "true")
arcpy.SetParameterAsText("is_point", "false")
elif describe.shapeType == "Point":
arcpy.AddMessage("Feature Type is point")
arcpy.SetParameterAsText("is_polygon", "false")
arcpy.SetParameterAsText("is_line", "false")
arcpy.SetParameterAsText("is_point", "true")
else:
arcpy.AddMessage("Unknown feature type")
arcpy.SetParameterAsText("is_polygon", "false")
arcpy.SetParameterAsText("is_line", "false")
arcpy.SetParameterAsText("is_point", "false")