dkatnik

Set Tool Parameter default values from table

Discussion created by dkatnik on Aug 23, 2012
How can I programatically set the default values for the parameters in a tool based on a variable (such as the tool name)?

The Class ToolValidator initialize function might have something like this:

def initializeParameters(self):
[INDENT]"""Refine the properties of a tool's parameters.  This method is called when the tool is opened."""
 
import SetDefaults "a separate python script with two subroutines"

toolName = ???  "how do I set this?"
   
self.params[0].value = SetDefaults.Parameter1(toolName)
self.params[1].value = SetDefaults.Parameter1(toolName)
   
return[/INDENT]


Then the script being called, "SetDefaults.py" would be returning values like:

def Parameter0(ToolName):
[INDENT]if ToolName == "WaterTool":
[INDENT]defVal = "Water"[/INDENT]
elif ToolName == "LandTool":
[INDENT]defVal = "Land"[/INDENT]
return defVal[/INDENT]

def Parameter1(ToolName):
[INDENT]if ToolName == "WaterTool":
[INDENT]defVal = "Aquatic"[/INDENT]
elif ToolName == "LandTool":
[INDENT]defVal = "Terrestrial"[/INDENT]
return defVal[/INDENT]


Actually, instead of hard-coding the default values in a script like this, it would read them from a different table depending on the tool name.

This would allow users to create different versions of the tool that would open with different default parameter values based on the name of the tool.  But I don't know how to pass the tool name to an outside script...

Outcomes