How to link to list parameters in and ArctoolBox?

3495
5
Jump to solution
07-02-2015 06:07 AM
SaidAkif
New Contributor III

Hi

Among other parameters in an ArcToolBox i developed, two string parameters. each one is filtred by a Value List.

lets say the first list is related to five Canada regions: ATL, PNR, PYR, QC and ON. each of those regions is composed of proinces and territories: ATL = NB, NL, NS, PE; ON=ON, QC=QC; PNR = AB, MB, NT, NU, SK and PYR=BC, YT. the Regions parameters is regions=arcpy.GetParameterAsText(4) and the provinces/terretories parameter is  ProvTerri = arcpy.GetParameterAsText(5).

Now what I want is to automatically populate ProvTerri when I select one of the regions. I wrote the following code in validation, but it did not work:

def updateParameters(self):

   if (self.params[4].value and not self.params[5].hasbeenvalidated):

      if self.params[4].value=["PNR"]:

         self.params[5].filter.list = ["AB","MB","NT","NU","SK"]

      if .....

      if not self.params[4].value:

        self.params[5].filter.list=[]

I also try to figure out the problem assuming that the problem come from the assessmenet of self.params[4].value. since it is a liste, I put after the first if:

  name=self.params[4].value

  names1=names.split(";")[0]

  if names1 = "PNR":

    ...

Thanks for your help

0 Kudos
1 Solution

Accepted Solutions
FreddieGibson
Occasional Contributor III

I believe that your problem is a logical error. You're check to see if the value of the parameter is equal to a list instead of a value within the list (i.e. value=["PNR"] vs value = "PNR").

Maybe I can suggest an easier way to execute this. I was able to get it to work with the below logic. You'll see that I'm using a dictionary to host the list of values for each province.

import arcpy
class ToolValidator(object):
  """Class for validating a tool's parameter values and controlling
  the behavior of the tool's dialog."""


  def __init__(self):
    """Setup arcpy and the list of tool parameters."""
    self.params = arcpy.GetParameterInfo()


  def initializeParameters(self):
    """Refine the properties of a tool's parameters.  This method is
    called when the tool is opened."""
    return


  def updateParameters(self):
    """Modify the values and properties of parameters before internal
    validation is performed.  This method is called whenever a parameter
    has been changed."""


    caDict = {'ATL':['NB', 'NL', 'NS'], 'ON':['ON'], 'PNR':['AB', 'MB', 'NT']}
    self.params[0].filter.list = sorted(caDict.keys())


    if not self.params[0].hasBeenValidated:
      if caDict.has_key(self.params[0].valueAsText):
        self.params[1].filter.list = caDict[self.params[0].valueAsText]        


    return


  def updateMessages(self):
    """Modify the messages created by internal validation for each tool
    parameter.  This method is called after internal validation."""
    return

View solution in original post

5 Replies
DanPatterson_Retired
MVP Emeritus

A more general comment... if the combined provinces are always to be treated as a region and not as individual provinces, you would be advised to edit the geometry and union the regions to one feature so that when someone selects one province, the whole region gets selected.  More simply, the Atlantic Provinces would be the combined geometry of NL,NB,NS and PE and selecting either provincial location would result in one record being selected.

Ignore these comments if you have other operations that require updating of simple provincial data...unless of course it is easier to parse your toolset based upon the two possible geometry configurations

0 Kudos
SaidAkif
New Contributor III

Hi

It is not a problem of geometry, it is just a question of how to customize the arctoolBox parameters. But thanks for your input

0 Kudos
FreddieGibson
Occasional Contributor III

I believe that your problem is a logical error. You're check to see if the value of the parameter is equal to a list instead of a value within the list (i.e. value=["PNR"] vs value = "PNR").

Maybe I can suggest an easier way to execute this. I was able to get it to work with the below logic. You'll see that I'm using a dictionary to host the list of values for each province.

import arcpy
class ToolValidator(object):
  """Class for validating a tool's parameter values and controlling
  the behavior of the tool's dialog."""


  def __init__(self):
    """Setup arcpy and the list of tool parameters."""
    self.params = arcpy.GetParameterInfo()


  def initializeParameters(self):
    """Refine the properties of a tool's parameters.  This method is
    called when the tool is opened."""
    return


  def updateParameters(self):
    """Modify the values and properties of parameters before internal
    validation is performed.  This method is called whenever a parameter
    has been changed."""


    caDict = {'ATL':['NB', 'NL', 'NS'], 'ON':['ON'], 'PNR':['AB', 'MB', 'NT']}
    self.params[0].filter.list = sorted(caDict.keys())


    if not self.params[0].hasBeenValidated:
      if caDict.has_key(self.params[0].valueAsText):
        self.params[1].filter.list = caDict[self.params[0].valueAsText]        


    return


  def updateMessages(self):
    """Modify the messages created by internal validation for each tool
    parameter.  This method is called after internal validation."""
    return
SaidAkif
New Contributor III

Thanks for your help

I did exactly what you mention but i steel have an error (Parameter object has no valueAsText).

I use arcGIS 10.1

I define my two parameters as string with es in Multivalue proporty

Thanks

0 Kudos
SaidAkif
New Contributor III

Hi

the problem was just a parameter propreties issue. I just put MultiValue Property in the first list (regions) as no and remove AsText in the code.

Thanks for all