Network Attribute Data Types in the GUI

08-30-2011 05:39 AM
New Contributor

I am trying to make a GUI for a tool that takes the network "Impedance Value" as a value that is 'obtained' from the inputted Network Dataset. That is, I would like to have the "Impedance Value" field in the GUI check what cost attributes the given input network has available, and restrict the options from a drop-down to only those cost attributes. This exact actions is available, for instance, in the "Make OD Cost Matrix Layer" tool,"Make Route Layer" tool and other NA tools.

I am unable, however, to figure out what the input parameter field 'data type' needs to be for that to happen. There is no 'Network Attribute' data type offered in the tool properties dialog box. Unfortunately cannot see what 'data type' other NA tools use for the "Impedance Value" field. Help!


Tags (2)
0 Kudos
2 Replies
Esri Contributor
Hi Andres,
    What you want to accomplish is possible in ArcGIS 10 (and even 9.3) but with some additional python code. A script tool�??s GUI can be further programmed using a ToolValidator class. This class can perform actions such as populating values of a parameter based on value from another parameter or enabling/disabling a parameter based on other parameters. More info about the ToolValidator class is available in the help

There was also a recent blog post on the geoprocessing blog explaining how to use ToolValidator class

For your case, In your script tool, You need to define  a network dataset parameter of type network dataset layer and a second parameter called Impedance of type string. Then you can use the attached tool validator code to automatically populate the values for Impedance value parameter based on the network dataset. I am attaching the toolbox containing this sample code.

class ToolValidator:
  """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."""
    import arcpy as ARC
    self.arcpy = ARC
    self.paramsIndex = {'networkDataset':0,
                  'impedance': 1}
    self.params = arcpy.GetParameterInfo()    
    #Get the parameter objects that will be modified
    self.networkParam = self.params[self.paramsIndex['networkDataset']]
    self.impedanceParam = self.params[self.paramsIndex['impedance']]

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

  def updateParameters(self):
    """Modify the values and properties of parameters before internal
    validation is performed.  This method is called whenever a parmater
    has been changed."""   
    if self.networkParam.altered:
      if self.networkParam.value and not self.networkParam.hasBeenValidated:
        #Check if the NDS exits

  def updateMessages(self):
    """Modify the messages created by internal validation for each tool
    parameter.  This method is called after internal validation."""
  def getNetworkProps(self,network):
    '''Update the parameter values based on th network dataset'''    
    desc = self.arcpy.Describe(network)
    defaultCostAttr = ""
    costAttributes = []
    count = 0
    #Build a list of cost attributes and get the default cost attribute
    attributes = desc.attributes
    for attribute in attributes:
      usageType = attribute.usageType
      name =
      useByDefault = attribute.useByDefault 
      if usageType == "Cost":
        #Check if the cost attribute has to be used by default.
          if useByDefault:  
            defaultCostAttr = name
    #Set the lists for cost attribute    
    self.impedanceParam.filter.list = costAttributes    
    #Set the default value for the cost attribute 
    if not self.impedanceParam.altered:
      if defaultCostAttr == "" and costAttributes:
        #if there is no default use the first one in the list
        defaultCostAttr = costAttributes[0] 
      self.impedanceParam.value = defaultCostAttr
  def resetNetworkProps(self):
    """Resets the network dataset derived parameters to nothing"""
    self.impedanceParam.filter.list = []
    self.impedanceParam.value = ""

Hope this helps.
0 Kudos
New Contributor
Thank you Deelesh, it works nicely! In case others wonder, the only thing to change in the validator code are the input order numbers of the Network Dataset and Impedance Attribute (if you have them in a different order in your tool).

For example:
self.paramsIndex = {'networkDataset':1, 'impedance': 9}

0 Kudos