Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

ToolValidator value.value, out of date documentation -

$
0
0
Hi All,

the ToolValidator documentation says:

Quote:

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.
Code:

if self.params[0].value:
  workspace = os.path.dirname(self.params[0].value.value)


However, the following works fine:
Code:

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:

Code:

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/...000000v000000/

Viewing all articles
Browse latest Browse all 2485

Trending Articles