lgtateos

ToolValidator value.value,  out of date documentation -

Discussion created by lgtateos on Apr 25, 2014
Latest reply on May 11, 2014 by lgtateos
Hi All,

the ToolValidator documentation says:

As a Value object does not support string manipulation, use the Value object's value property whenever a string is to be manipulated or parsed. The code sample uses the os.path.dirname method to return the directory from a dataset.
if self.params[0].value:
  workspace = os.path.dirname(self.params[0].value.value)



However, the following works fine:
workspace = os.path.dirname(self.params[0].value)


My question are,

1. Has anyone encountered a situation where they DID have to use self.params[0].value.value and self.params[0].value wouldn't work?

2. Is this working because I'm running 10.2?  Does it work for those of you that have 9.3, 10.0, and 10.1? 

I have a dummy script tool with 1 param. The code below is for debugging outside the script tool.  It also works inside the script tool (I set a second param to that value to check it in the script tool). Here's a complete script to test this:

import arcpy, os

arcpy.ImportToolbox(r"C:\temp\sandbox.tbx")
params = arcpy.GetParameterInfo("myScriptTool")
params[0].value = "C:/Temp/data.shp"

class ToolValidator:

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

  def initializeParameters(self):
    # (initializeParameters code here)
    return

  def updateParameters(self):
    # (updateParameters code here)
    print os.path.dirname(self.params[0].value)
    return

  def updateMessages(self):
    # (updateMessages code here)
    return

# Call routine(s) to debug
#
validator = ToolValidator()
validator.updateParameters()
validator.updateMessages()


It runs successfully and prints:
C:/Temp

The documentation is about midway through the following page:
http://resources.arcgis.com/en/help/main/10.2/index.html#/Programming_a_ToolValidator_class/00150000000v000000/

Outcomes