1

I have tried to write some validation code for a script in ArcGIS. This validation code more or less repeats what the script itself does, which is a simple cutting up of a long string by using the Python "split" string method, and then using each of the outcomes to define some parameters. This works great for most variables here, but for some reason the params 2 and 6 are being set to the full original string when I review the validation results in the ModelBuilder window by hovering over the variable. I have no idea why this is happening. Both of these parameters are defined as String output on the script. There is one more string output variable here (params 8), that displays a good value, and the only difference I see is the extra "replace". I have even tried to hard code the values for params 2 and 6, by setting it directly equivalent to a string, but to no avail, it still showed the full original unsplitted string.

What am I missing?

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."""
    self.params[1].value = self.params[0].value.split(';')[0]
    self.params[2].value = self.params[0].value.split(';')[1]
    self.params[3].value = self.params[0].value.split(';')[2]
    self.params[4].value = self.params[0].value.split(';')[3]
    isExportFeatureClassStr = self.params[0].value.split(';')[4]

    if isExportFeatureClassStr == "True":
        isExportFeatureClass = True
        flowControlBoolean = False
    else:
        isExportFeatureClass = False
        flowControlBoolean = True

    self.params[5].value = isExportFeatureClass
    self.params[6].value = self.params[0].value.split(';')[5]
    self.params[7].value = flowControlBoolean
    self.params[8].value = self.params[0].value.split(';')[6].replace(",",";")

return
2
  • 1
    Would it work better if you first set a variable like splitStr = self.params[0].value.split(';') and then each parameter like self.params[2].value = splitStr[1]? Feb 22, 2015 at 23:06
  • Just tried it, again no change. I just see the unsplit string for these variables. Really strange, as params 8 (I wrongly wrote 5 in my first post - now corrected), comes out OK and is also a String output variable (others are e.g. SQL Expression and Boolean).
    – Marco_B
    Feb 22, 2015 at 23:20

1 Answer 1

2

I have tested it like this:

  def updateParameters(self):
    ValuesStr = self.params[0].value
    Values = ValuesStr.split(';')

    self.params[1].value = Values[0]
    self.params[2].value = Values[1]
    self.params[3].value = Values[2]
    self.params[4].value = Values[3]
    isExportFeatureClassStr = Values[4]

    if isExportFeatureClassStr == "True":
      isExportFeatureClass = True
      flowControlBoolean = False
    else:
      isExportFeatureClass = False
      flowControlBoolean = True

    Val6 = Values[6]
    Val6 = Val6.replace(",",";")

    self.params[5].value = isExportFeatureClass
    self.params[6].value = Values[5]
    self.params[7].value = flowControlBoolean
    self.params[8].value = Val6

    return

with the test string:

zero numeric value;one value one;two is two;three tripple 3;True;five of six;seven, and end of param, for now;

And it works just fine... enter image description here

As replace(",",";") modifies the string it's best to separate it out by making it a string and not a string in a list.

4
  • I have pasted in your version of the validation script, and I still see the same problem when I hover over the variables in a ModelBuilder window (script is part of a bigger model). Michael, what version of ArcGIS are you using? Mine is 10.2.0...
    – Marco_B
    Feb 23, 2015 at 8:52
  • Michael, I now realised I had set params 2 and 6 to "Obtained From" params 0. This - partly - explains why the full string of params 0 was shown. However, after correcting this, the values for 2 and 6 are now empty! This is still an error (and starts to look like a bug).
    – Marco_B
    Feb 23, 2015 at 12:13
  • There is one additional thing that is bugging me though. The Help states: "As a Value object does not support string manipulation, use the Value object's value property whenever a string is to be manipulated or parsed.". I find this sentence highly cryptic. The example shown in the Help (resources.arcgis.com/en/help/main/10.2/index.html#//…), doesn't help me either to understand the consequences or implications for tool validation.
    – Marco_B
    Feb 23, 2015 at 12:17
  • OK, forget all I wrote before. I now finally see the proper results. I had another look over the modifications I did in the validation script, ensured it was right, and made sure I re-entered the main variable params 0 for testing. This triggered a proper update of the variables in the model, and it now displays right. I marked your answer as right now, although the main code may have been right all along. Thanks for the help.
    – Marco_B
    Feb 23, 2015 at 12:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.