Change the binding of another property in perspective

Is it possible to change the binding of a property on the change of another?

Let’s say I have:

  1. 3 value properties:
    a: 1
    b: 2
    c: 3
  2. A dropdown list with values: [a,b,c]
  3. A label which is bound to the dropdown list with a transform:
  • if the selected dropdown is a, show value of a.
  • If the value is b, show value of b
  • If the value is c, show value of c

Now, if select a in the dropdown, the label will show the value of a. Same with selecting b or c. All good.

However, if the dropdown is selected as a, and the value a itself changes, the label will not update, because it’s bound to the value of the dropdown list.

Ideally, what I would like is:

  1. If the selected dropdown value is a, then the label is bound to property a
  2. If the selected dropdown value is b, then the label is bound to property b
  3. If the selected dropdown value is c, then the label is bound to property c

Is this possible?

I’ve achieved this using value changed scripts but it’s become quite messy and I’m hoping for a cleaner solution.

Any help would be hugely appreciated.

I advice you put these 3 props into an object (altho it works on the base props too)
image
bind your dropdown options to this object so that the label/values stay updated too
return [{"value":x,"label":x} for x in value]


then you can easily acces the dynamic attribues with [] like so
return self.view.custom.customValues[value]

if you want the label to update in real time when the customValues updates and/or the dropdownvalue you will have to use a structed expression binding so you can bind those two props so it will execute when any of them changes

edit:
note: you might want to put in some logic on the label incase the dropdown value is null to return a default message or something, else it will show a null error

if value != "":
	return self.view.custom.customValues[value]
return "Nothing is selected"

or in one pythony line:
return self.view.custom.customValues[value] if value != "" else "Select something"

1 Like
return self.view.custom.customValues[value] if value != "" else "Select something"

Could just use if value, so it handles both None and empty strings.

1 Like

Hey @victordcq, thank you very much for the solution! That’s worked perfectly for me. Seems like expression structure bindings were the trick I needed!

Also nice to know you can bind the drop options to an object property using python dictionary syntax, another thing I didn’t know was possible!

1 Like