Setting parameters in Script Tool using Python?

The parameters that you currently have set up should not actually be "output" parameters, as they are simple string arguments to your geoprocessing methods, not true outputs.

There are two ways you can go about this:

  1. Replace your two "Output Location" and "Output Table" parameters with a single output parameter of type Table to supply the full path to the output table, and update your script logic to parse this parameter into the necessary path components using os.path.split as needed for the geoprocessing functions you are using.
  2. Change your "Output Location" and "Output Table" parameters to be input parameters (I would also rename "Output Table" to "Output Table Name" to clarify that it's just the name of the table, not the full path to it). Create a new fourth parameter of type Derived and modify your script tool's ToolValidator class to set its value after parameters 2 and 3 have been validated.

The first method is probably the easier way to go -- the ToolValidator logic is tricky to get right and difficult to debug.

EDIT: Actually there is a third option that may work for your purposes -- it is the same as method two, but instead of modifying ToolValidator, call SetParameterAsText at the end of your script to set the value of the fourth, derived parameter. I have had trouble with SetParameterAsText in the past in script tools used in ModelBuilder, but it might be fixed now.


I'd also look at commenting out all of the code and printing out the parameter values you are passing in. Always good to put in a bit of debugging.

It is also good practise, to check the parametsr as they come in:

# First parameter is ID
ID = long(arcpy.GetParameterAsText(0))

# parameter is optional feature class prefix 
appPrefix = arcpy.GetParameterAsText(1)
if (not appPrefix) or (appPrefix == "#") or (len(appPrefix.strip()) == 0):
    appPrefix = ""

# Optional schema owner
schemaOwner = arcpy.GetParameterAsText(2)
if (not schemaOwner) or (schemaOwner == "#") or (len(schemaOwner.strip()) == 0):
    schemaOwner = ""
else:
    schemaOwner = schemaOwner + "."

# Optional workspace - for use with ArcGIS Desktop. No default.
workspace = arcpy.GetParameterAsText(3)
if (not workspace) or (workspace == "#") or (len(workspace.strip()) == 0):
    workspace = os.path.join(sys.path[0], connFile)

Something like that, then ensure you print out the variables in order you can see them:

arcpy.AddMessage("ID : " + str(Id))

or

print "ID : " + str(Id)

Etc. You need to know the values going in aren't rubbish, as you'll always be chasing your tail.

Putting the row/cur in a try catch is good practise too.