joakleaf

Interactively setting the current workspace using the ToolValidator class

Discussion created by joakleaf on Nov 15, 2012
Latest reply on Nov 19, 2012 by curtvprice
I have a tool which has the user select a workspace in the first parameter.  Once the user selects the appropriate workspace I would then like the tool's environmental settings to be changed so the current workspace be set to that select workspace.  What I am hoping to accomplish is if the user just inputs a name in a feature class output parameter, the new featureclass will be created in the previously selected workspace by default.  I have tried using the ToolValidator however it doesn't seem to change the tool's environment settings.  I have included code from my ToolValidator class showing two ways I have tried to accomplish this.

Thanks for any advice or suggestions,
Jim Oakleaf



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

  def initializeParameters(self):
    return

  def updateParameters(self):
    if self.params[0].altered:
      theW = self.params[0].value
      dsW=arcpy.Describe(theW)
      arcpy.env.workspace=dsW.catalogPath  """Tried this method"""
      arcpy.env.scratchWorkspace=theW   """Also tried this method"""

  def updateMessages(self):
    return

Outcomes