behClevest

Adding Combobox/Dropdown List to Python Toolbox Tool Dialog?

Discussion created by behClevest on Dec 12, 2017
Latest reply on Dec 12, 2017 by jborgion

I am trying to create a Python Toolbox tool which is supposed to add two fields State and StateAbb to selected Shapefile from selected combobox.

How I can add a Combobox which contains a list of US states to the Tool?

import arcpy

class Toolbox(object):
    def __init__(self):
        """Define the toolbox (the name of the toolbox is the name of the
        .pyt file)."""

        self.label = "states"
        self.alias = "states"

        # List of tool classes associated with this toolbox
        self.tools = [states]


class states(object):
    def __init__(self):
        self.label = "states Tool"
        self.description = "Add and Insert Value from Combo"
        self.canRunInBackground = False

    def getParameterInfo(self):

        param0 = arcpy.Parameter(
            displayName="1- State Street Layer",
            name="in_features",
            datatype="GPFeatureLayer",
            parameterType="Optional",
            direction="Input"
        )

        params = [param0]

        return params


    def execute(self, params, messages):
        """The source code of the tool."""
        arcpy.AddField_management(params[0],"area","TEXT","#","#","#","#","NULLABLE","NON_REQUIRED","#")
        arcpy.CalculateField_management(params[0],"area","!shape.area@squaremeters!","PYTHON_10.3","#")


        return

Outcomes