You can enter whatever output name you want once it fills in the first time. If you set the current workspace to the same as the input text file, you'll at least see the path you want. (The default workspace is Default.gdb if it hasn't been setup otherwise.)
If you want to modify what the default output path name to be the same as the input, you can do this using parameter validation in the updateParameters module:
Arc 10 help: Customizing Script Tool Behavior
Curtis,
All of my work is located in a folder called Survey_Shapes, so in order to try and set my current workspace I started my script as follows:
import arcpy
arcpy.env.workspace = "T:/Data/Survey_Shapes"
Rob,
There is a hierarchy to the scope of environment settings; setting environments within a script or custom tool is the lowest in the hierarchy.
Also, tool parameter validation (of which the "pop" of paths you are observing is a part) happens before your script starts, so setting arcpy.env.workspace setting in the script will not affect which path "pops" in the dialog. If you want to have the path "pop" to T:/Data/Survey_Shapes you need to either set your environment current workspace to that path in ArcCatalog, or using the environments button on the tool -- or modify the tool validation python code (in the script tool properties validation tab) to populate the same path as the input.
Rather than dink with the validation to fill in paths, I go with the flow and set the current workspace in ArcCatalog/ArcMap to where I'm working so the script tool will have the maximum flexibility. That's my recommendation.
As you suggested, you could just remove this parameter from the script and generate the output path within your python script, but this makes your script not work very well within ModelBuilder. I also don't recommend naming two objects (your example: output.txt, output.shp) the same thing -- this can cause confusion when scripting and even in your directory listing.
Hope this helps.
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 self.params = arcpy.GetParameterInfo() 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.""" import string import arcpy if self.params[0].value: if not self.params[1].value: inputTxt = str(self.params[0].value) outputTxt = str.replace(inputTxt,"txt","shp") self.params[1].value = outputTxt return def updateMessages(self): """Modify the messages created by internal validation for each tool parameter. This method is called after internal validation.""" import os self.params[1].clearMessage() if os.path.exists(str(self.params[1])): self.params[1].setErrorMessage("File Exists") return
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 self.params = arcpy.GetParameterInfo() 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.""" import string if self.params[0].value: if not self.params[1].value: inputTxt = str(self.params[0].value) outputTxt = str.replace(inputTxt,"txt","shp") self.params[1].value = outputTxt return def updateMessages(self): """Modify the messages created by internal validation for each tool parameter. This method is called after internal validation.""" import os if self.params[1].altered: self.params[1].clearMessage() try: outputTxt = str(self.params[1].value) open(outputTxt) self.params[1].setWarningMessage(outputTxt + " exists") except: self.params[1].clearMessage() return