1

I'm having issue with using validation to update an input box. Some background:

I created a tool to update and resize text in ArcGIS. This is done by having a series of text elements and shape elements with matching names. So there is a shape element named "Title" and a text element named "Title". I can then resize and move the shape element around in my layout and then run this tool to update the text, resize and center within the shape element.

The tool has a validation script that is supposed to generate a list of these element names in box A and then based on which one the user selects, place the actual text in box B. In this way the user can see exactly which text element they have selected and then edit that text in box B before running the tool. The problem is that after you edit the text in box B, the validation resets the text to the original value.

How can I prevent this?

This is what I tried:

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."""

    mxd = arcpy.mapping.MapDocument("CURRENT")

    if self.params[0].altered:
        temp=arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT",self.params[0].value)
        self.params[1].value = temp[0].text

return

So the behavior now is that the first box populates without issue but switching between values doesn't update box B with the text.

1 Answer 1

5

Instead of

if self.params[0].altered:

try

if self.params[0].value:

I just tested and that seemed to work as you are hoping for. The .altered and .hasBeenValidated properties are super useful, but are still a little mysterious to me sometimes, even after reading the documentation...

UPDATE: Thanks for the feedback, I misinterpreted what you were asking. After a bit of trial and error, I figured out how to do what I think you're after:

if self.params[0].value and self.params[0].altered and not \
   self.params[0].hasBeenValidated:
  self.params[1].value = self.params[0].value

This will change box 2 to equal box 1 only when box 1 has been changed, and will allow box 2 to be edited any time (and retain the edits).

3
  • I tried your suggestion but it doesn't produce the behavior that I am looking for. I make a selection from Box A and Box B is populated (e.g. "XXX-XXX") Then I modify Box B (e.g. "123-456") then when I finish that edit, Box B goes back to "XXX-XXX". It looks like the .altered property stays TRUE once it is triggered, that was my misunderstanding. I will keep working on figuring this out.
    – RossV
    Commented Apr 21, 2015 at 14:44
  • perfect! thank you so much! my head was spinning trying different combinations. I just changed the last part to take the .text of the element that matches the value.
    – RossV
    Commented Apr 21, 2015 at 16:08
  • yes, those properties are tough, especially because they are most useful when used in compound. But they offer such great functionality to dialog menus, it's very good to be aware of them.
    – mr.adam
    Commented Apr 21, 2015 at 16:14

Your Answer

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

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