I want to bind a parameter from the return of a python script.
But my script does not get evaluated, as you can see, I put "1" on expression and use a script transform - I used to do this but just found that this is bad strategy.
How can I get the script evaluated, when each parameters used on the script changes.
Transforms are only evaluated if their parent is re-evaluated. A static expression value like 1 is only evaluated once at first load. You need to use an expression structure binding and bind to all of your props you want to monitor for this to evaluate when these props change
I think You can also include all your props in a group (object/array) and just monitor the group prop itself
You could use asList() in an expression binding to produce a composite of several "monitored" tags/properties to pass to your transform as value. Something like this:
if you do this, I recommend exploding back to local variables in the first line of the script transform:
def transform(self, value, quality, timestamp):
prop1, prop2, tag1, tag2 = value
.... the rest of the transform ....
This approach can also be used with expression transforms to ensure source values or sub-expressions are evaluated only once before inclusion in a larger expression.
I am playing with expression structure now..
On expression Editor. I added tags. But how do you make the tags dynamic such as below:
I want to make the motor index number to be dynamic:
Putting curly braces into a string doesn't create a binding. Click on the chain link icon in the left gutter next to the property to open the binding editor.
{ And consider going through Inductive University, so you get all of these basics at a steady pace. }
I see. but there is no indirect binding in this option only expression binding..
I made a work around by doing this on a custom parameter, where I can use Indirect Binding.
I see, is there any native way to accomplish similar thing? I dont opose to use the SimulationAids module, but would need to consult with customers if they apporve.
This I only set once and not tend to change. Thus this does not need to be triggered in runtime.
I set 1 in the expression.
But I ran into issues where the parameter will be set to null.
Is there a property I can monitor that change during startup, to use it to trigger this script?
@Eugene49 Just to be clear, you generally should not be assigning "magic" values like colour hex's directly to style properties like backgroundColo(u)r if you want to have any hope of maintaining a theme throughout your project. Ditch these in favour of Perspective Styles, as @lrose suggested
do you guys mean. If you want to set label's font color to green. you would rather create a style, set font color to green and apply the style?
Hypothetically, Say I have 4 layers of nested flex container.
Each layer uses different background color.
You would rather create 4 styles. Layer1 .. Layer4 styles. Apply these style to each flex container respectively.
What I did, I created 4 global variables in python, and pass those variables to background of each flex? To remain consistent project wide.
What is wrong with this?
Also, if I decided to create a css theme file.
Would I able to distinguishly identify the 4 flex container above and set different color to them?
Or theme can only be applied as per component type.
Anyway, my problem is not about the strategy above nor the choice to use expression vs python script.
Python is more readable for me. Is there an advantage favoring the use of expression?
My problem is, for some reason, the parameter forgets the value that was set to it, during saving/closing/reopening of view.. and since the binding does not get triggered, it returns an error.
Expressions are more performant than script transforms and will reduce the load on your gateway. This is especially important for larger systems
The whole scripting engine restarts every time you save the project.
Using Perspective Styles are far more performant than reading variables from script libraries within a script transform, they're also far more obvious and user friendly for other engineers when maintaining or extending a project. Design for performance and user experience first; script transforms should only ever be the last option if you can't achieve the same thing via other methods (e.g. tag / expression bindings)
Yes, I would create 4 styles in that case, assuming they're used in more than one place.