Select to view content in your preferred language

Debugging_a_ToolValidator_class

1896
0
02-20-2012 06:59 AM
OlivierOlivier
Regular Contributor
Hi,

I'm trying to debug a stand alone python script as written in http://webhelp.esri.com/arcgiSDEsktop/9.3/index.cfm?TopicName=Debugging_a_ToolValidator_class "Debugging in a Python editor" (page bottom)

I thought I did things as described but what I don't understand is that if I call the script from the toolbox in ArcMap, it runs well, but if I launch the script from pythonwin, I get the following error :

gp.savetolayerfile("arc", bdd + "arc.lyr")
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Layer: Dataset arc does not exist or is not supported
Failed to execute (SaveToLayerFile).

So it appears that I'm not in the ArcMap environment as I expected. What I would like to do is exactly what is described in the help "In some cases, you need to debug your code using a Python editor ..."

Thanks for any help.

Olivier


import arcgisscripting
import pyodbc

gp = arcgisscripting.create(9.3)
# ------------------------- TEMP Debug Tool Validator

gp.addtoolbox(r"D:... my toolbox.tbx")
params = gp.GetParameterInfo("script name") # 
params[0].value = "value"

# Classe Tool validator
class ToolValidator:
  """Class for validating a tool's parameter values and controlling
  the behavior of the tool's dialog."""

  def __init__(self):
    """Setup the Geoprocessor and the list of tool parameters."""
    import arcgisscripting as ARC
    import pyodbc
    bdd = "my folder"
    mdb = bdd + "mybase.mdb"
    conn = pyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb)};DBQ='+mdb)
    cursor = conn.cursor()

    self.GP = ARC.create(9.3)
    self.params = self.GP.getparameterinfo()
    cursor.execute("SELECT .... my query")
    rows = cursor.fetchall()
    list = []
    for row in rows:
      list.append(row.name)
    self.params[0].Filter.List=list
    conn.close()
    del rows,row,cursor,conn

  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 parmater
    has been changed."""
    return

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

#--------------------------End tool validator
bdd = "my folder"
mdb = bdd + "mybase.mdb"

gp.workspace = mdb
gp.overwriteoutput = True
gp.savetolayerfile("arc", bdd + "arc.lyr") <---- ERROR


validator = ToolValidator()
validator.updateParameters()
validator.updateMessages()
Tags (2)
0 Kudos
0 Replies