Select to view content in your preferred language

Setting parameter values in ToolValidator Class

910
0
04-14-2010 06:15 AM
deleted-user-wJESCgrAq9zI
Deactivated User
In version 9.3.1. I'm building af script tool where some of the parameters have Data Type "Field" and with a Field-Filter limiting the allowed types (text, float etc.) and where the field names are "Obtained from" a Feature Layer given in a preceding parameter. This works OK in itself. Then I build a ToolValidator class for this tool in which I populate these field parameters with a string containing a valid field name from the same feature layer. This doesn't work. The field parameters gets a red errormark and the error text: "Invalid field type" - except for the fields of type "long integer"!?

I can see in the documentation, that when you read parameter values using "self.params.Value" you may have to convert the obtained value to a string before using it. What I am writing to the value is a string, and it may have to be a field object or a field name object. How do I make that?

My current code fragment is this:

if self.params[1].Altered and self.params[1].Value and not self.params[1].HasBeenValidated:
LayerLayer = self.params[1].Value
if self.GP.exists(LayerLayer):
desc = self.GP.describe(LayerLayer)
datasettype = desc.DatasetType
if datasettype.lower() == "featureclass":
layertype = desc.ShapeType
if layertype.lower() == "point":
# Check for a match with standard names
fieldlist = self.GP.ListFields(LayerLayer)
standardlist = ["Z","ProfileNam","Comment","Quality","UserName","ChangeDate"]
for i in range(len(standardlist)):
for candidatefield in fieldlist:
if candidatefield.name.upper() == standardlist.upper():
self.params[i+2].Value = candidatefield.name
0 Kudos
0 Replies