Set Tool Parameter default values from table

523
0
08-23-2012 09:55 AM
DonaldKatnik
New Contributor II
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...
Tags (2)
0 Kudos
0 Replies