GetParameterInfo

サマリ

Returns a list of parameter objects for a given tool. Commonly used in a script tool's ToolValidator class.

構文

GetParameterInfo (tool_name)
パラメータ説明データ タイプ
tool_name

The tool name. Including the toolbox alias will help to resolve any conflicts with duplicated tool names.

注意注意:

When the GetParameterInfo function is used as part of a script tool's ToolValidator class, the tool_name argument is optional.

String
リターン
データ タイプ説明
Parameter

Returns a list of parameter objects.

コードのサンプル

GetParameterInfo example 1

Display some parameter object properties for the specified tool.

import arcpy

# Load tool parameter objects into list.
params = arcpy.GetParameterInfo("HotSpots")

for param in params:
    print "Name: %s, Type: %s, Value: %s" % (param.name, param.parameterType, param.value)
GetParameterInfo example 2

Setting symbology for a script tool's output dataset.

import arcpy
from arcpy import env
import os

# Set workspace and variables for Clip tool.
env.workspace = arcpy.GetParameterAsText(0)
in_features = arcpy.GetParameterAsText(1)
clip_features = arcpy.GetParameterAsText(2)
out_feature_class = arcpy.GetParameterAsText(3)

# Execute clip tool
output = arcpy.Clip_analysis(in_features, clip_features, 
                             output_feature_class)

# Load up list with 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 workspace directory.
lyr_location = os.path.dirname(env.workspace)

if desc.ShapeType.lower() == "polygon":
    params[2].symbology = lyr_location + os.sep + "Polygon.lyr"
elif desc.ShapeType.lower() = "polyline":
    params[2].symbology = lyr_location + os.sep + "Polyline.lyr"
else:
    params[2].symbology = lyr_location + os.sep + "Point.lyr"

次の例は、[フィールドの追加(Add Field)] ツールの整合チェックをエミュレートしたものです。

class ToolValidator:

    def __init__(self):
        import arcpy 
        self.params = arcpy.GetParameterInfo()

    def initializeParameters(self):
        # The derived output is a clone (copy) of the input
        #
        self.params[10].parameterDependencies = [0]
        self.params[10].schema.clone = True

        # Set up the field type list
        #
        self.params[2].filter.list = ["TEXT", "FLOAT", "DOUBLE",
                                      "SHORT", "LONG", "DATE",
                                      "BLOB", "RASTER"]

        # The default field type is LONG
        #
        self.params[2].value = "LONG"

        # Field scale & Length are disabled for LONG types
        #
        self.params[4].enabled = False
        self.params[5].enabled = False

        # Set the Boolean filters for IsNullable and IsRequired and
        #  their default values
        #
        self.params[7].filter.list = ["NULLABLE", "NON_NULLABLE"]
        self.params[7].value = "NULLABLE"
        
        self.params[8].filter.list = ["REQUIRED", "NON_REQUIRED"]
        self.params[8].value = "NON_REQUIRED"

        return

    def updateParameters(self):
        # Set the default field type value unless the user altered it
        #
        if not self.params[2].altered:
            self.params[2].value = "LONG"

        # Enable/Disable parameters based on field type
        #
        fieldType = self.params[2].value.upper()
        if fieldType in ["TEXT", "BLOB"]:
            self.params[3].enabled = False
            self.params[4].enabled = False
            self.params[5].enabled = True
        elif fieldType in ["FLOAT", "DOUBLE"]:
            self.params[3].enabled = True
            self.params[4].enabled = True
            self.params[5].enabled = False
        elif fieldType in ["SHORT", "LONG"]:
            self.params[3].enabled = True
            self.params[4].enabled = False
            self.params[5].enabled = False
        elif fieldType in ["DATE", "RASTER"]:
            self.params[3].enabled = False
            self.params[4].enabled = False
            self.params[5].enabled = False
        else:
            # Unknown field type.  Internal validation will catch this
            #  and show an error. We might as well return here and let
            #  internal validation do its work.
            #
            return
        
        # Update the output schema with the new field. Don't do anything
        #  unless we have an input value and a field name
        #
        if self.params[0].value and self.params[1].value:
            newField = arcpy.Field()
            newField.name = self.params[1].value
            newField.type = self.params[2].value

            # Set up the field properties based on type of field
            #
            if self.params[3].value and self.params[3].enabled:
                newField.precision = self.params[3].value
            if self.params[4].value and self.params[4].enabled:
                newField.scale = self.params[4].value
            if self.params[5].value and self.params[5].enabled:
                newField.length = self.params[5].value
                
            if self.params[6].value:
                newField.aliasName = self.params[6].value
                
            newField.isNullable = self.params[7].value

            # Note: IsRequired is not a property on a field object -- it's
            #  handled internally by the Add Field system tool.
            # 
            if self.params[9].value:
                newField.domain = self.params[9].value

            # Set the additional field on the output schema
            #
            self.params[10].schema.additionalFields = [newField]

    def updateMessages(self):
        return



関連項目


7/10/2012