Script transform on Vision

On perspective, when we do a binding, we have option to do ScriptTranform, Why we can do it on VISION ?

Not directly. You have to move your binding to a custom property and perform your transform on a property change script.

Note: propertyChange events have to be checked in some way, so they only fire when the correct property change occurs.


if event.propertyName == 'myCustomProp':
     newValue = event.newValue
     # Do your transform on the new value here.
     # Then, assign the transformed value to the desired property.
     #component.regularProp = transformedProp

You can also use runScript() with a project library script (or component custom method) if you want it to evaluate on a binding even when the designer is not in preview mode.


I do it but when I change iduser, it not show anything on the label.
My syntaxe is incorrect ?

if event.propertyName == 'event.source.iduser':
	user_id = event.newValue
	event.source.getComponent('lbtest').text = "turbine engine " +str(user_id)
if event.propertyName == 'iduser':
	user_id = event.newValue
	event.source.getComponent('lbtest').text = "turbine engine " + str(user_id)
1 Like

merci @pascal.fragnoud

Est ce que je peux également lire une proprieté Custom "city" sur la vue en faisant binding par exemple:

if event.propertyName == 'iduser':
	user_id = event.newValue
        city = # custom
	event.source.getComponent('lbtest').text = ciity + "turbine engine " + str(user_id) 

est ce que ceci est correct ?

Other than the typo in ciity in the last line, that should allow you to add a custom property value to a label, so long as it is a string.

Note that you could also just do an expression binding on the lbtest.text property and achieve the same thing.


Oui, mais comme le dit @lrose, un simple binding fait l'affaire.
Ajoute cet expression binding sur ton label lbtest (note: I don't remember the actual path you need to use to access custom properties. Just use the property browser to select it):

{city_property}  + 'turbine engine ' + {userid_property}

There's no need to use property change scripts just for this.

If you script has other things to do, maybe they can also be replaced by simple bindings.


D'accord, merci.

I agree with @lrose and @pascal.fragnoud; a transform is overkill for this use case. The expression binding is the correct solution for string casting and concatenation.