def updateParameters(self): """Modify the values and properties of parameters before internal validation is performed. This method is called whenever a parmater has been changed.""" if self.params[0].value: fldName = self.params[1].value if not fldName: # set default value fldName = "XFIELD" else: # validate field name wk = arcpy.Describe(self.params[0].value).catalogPath fldName = arcpy.ValidateFieldName(fldName,wk).upper() self.params[1].value = fldName # populate filter (picklist) with the current field name # plus existing field names flds = arcpy.Describe(self.params[0].value).Fields fldNames = [f.name.upper() for f in flds if f.type not in ["OID","Geometry"]] self.params[1].filter.list = [fldName] + fldNames return def updateMessages(self): """Modify the messages created by internal validation for each tool parameter. This method is called after internal validation.""" # If field exists, make sure it's a numeric field fldName = self.params[1].value if fldName: flds = arcpy.Describe(self.params[0].value).Fields fldNames = [f.name.upper() for f in flds] try: fType = flds[fldNames.index(fldName)].type # no error means field found - make sure it's a number if fType not in ["Double","Single"]: self.params[1].setIDMessage("Error",889) # invalid field type except: pass return
when I run the tool if I enter new field names it stops me with an error because the fields do not exist. I do still want the combo provided from the field type since there are cases where the field will exist though. I'm thinking it might be a matter of adjusting the validation logic but I've no experience doing that. Any ideas? Thanks in advance.
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.