Thanks again Jason and I was afraid I had to do that, although it's not a terrible work around. I'll take what I can get!Now, I attempted to make this happen and I am banging my head against the wall. I can set the default values in the updateParameter with no issue. It's when I set the updates after the user has changed the parameter value. In my if/else statements, I am setting a condition on the value sitting in the first parameter (params[0]). The script isn't picking up the value at all, even though I set it in as a default value. It goes something like this:
- I set the script below, save and close the validator script.
- Open the tool and the parameter is set to "DatabaseConnections\CONNECT1.sde\AREA1_SPATIAL.ER_SVW" as I expected
- The second parameter is empty as expected
- The third parameter is populated with the fields from the default parameter, even though I set an "not in list" condition in the final if/else statement which means the third condition "not in list" is being satisfied, even though the default value I set at the beginning is sitting inside the list....(I've also tried a <> and a simple else with the same outcome)
def updateParameters(self):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
# Set Parameters #1 and 2 default values
if not self.params[0].altered:
self.params[0].value = r"Database Connections\CONNECT1.sde\AREA1_SPATIAL.ER_SVW"
if not self.params[1].altered:
self.params[1].value = ""
if not self.params[2].altered:
self.params[2].value = ""
# if the user changes Parameter #1, then update the datatype and values
if self.params[0].value == r"Database Connections\CONNECT1.sde\AREA1_SPATIAL.ER_SVW":
self.params[1].value = "SITE_NUMBER = "
self.params[2].enabled = False
elif self.params[0].value == r"Database Connections\CONNECT1.sde\AREA2_SPATIAL.ER_SVW":
self.params[1].filter.list = "SITE_NUMBER = "
self.params[2].enabled = False
elif self.params[0].value not in [r"Database Connections\CONNECT1.sde\AREA1_SPATIAL.ER_SVW", r"Database Connections\CONNECT1.sde\AREA2_SPATIAL.ER_SVW"]:
self.params[1].datatype = "String"
descFields = arcpy.Describe(self.params[0].value).fields
self.params[1].filter.list = [field.name for field in descFields]
self.params[1].filter.values = self.params[1].filter.list
This is weird. I created an updateMessage to spit out the value to see if I am missing something and it returns exactly what I set the parameter to NOT look for: if self.params[0].value not in ["Database Connections\CONNECT1.sde\AREA1_SPATIAL.ER_SVW", ""Database Connections\CONNECT1.sde\AREA2_SPATIAL.ER_SVW""]:
self.params[0].setErrorMessage(self.params[0].value)
This line returns Database Connections\CONNECT1.sde\AREA1_SPATIAL.ER_SVW
which is exactly what I told it NOT to do in if self.params[0].value not in ["Database Connections\CONNECT1.sde\AREA1_SPATIAL.ER_SVW", ""Database Connections\CONNECT1.sde\AREA2_SPATIAL.ER_SVW""]
Oh and get this, I even did: if self.params[0].value <> self.params[0].value:
self.params[0].setErrorMessage(self.params[0].value)
And I get an error message. I told it that if it didn't equal itself, then set a message. See, I'm stumped.....I tried setting the string path to raw string and then a none raw string. Same thing. The "value" property is supposed to be of type "Value Object". I don't know what that means, but maybe it means it will pick up the datatype of the parameter as a "Value Object"? The parameter datatype for the first param (param[0]) is of type "Feature Class", so is it not picking up the string as a feature class? Am I explaing my problem properly?? ha! Ughhh....