Change component attributes based on DB values

I want to change the color, OR, Visability of a component based on a DB value.

I want to change the background color of a Rectangle if a DB entry is set at 1 (or perhaps zero)

I also want to make an item visable if the DB entry is a 1 (or perhaps a 0)

I’ve reviewed the posts here and can’t seem to find anything close. I think what I want to do is use a query to get the DB data, then with a script, look at the value the DB returned, the set the properties accordingly.

THE QUESTION - HOW DO I DO THIS? A brief sample script would go a long way to help me.

Thanks

JOhn

  1. Create an integer dynamic property on an object or container. This will be the FactoryPMI property that represents the PLC value. Select the component then click on the customizer, cntl+U. Bind this property to your SQL query to equal the 0 or 1 that you referred to.

  2. To change the visibility, bind the Rectangles visible property to your dynamic variable. If you need additional logic, use an expression. You can get really fancy with this. The following example will make it visible on a 0 and invisible on a 1.

!{Root Container.my_var}
  1. To change the color, bind that color directly to your dynamic variable. You can graphically build up an integer->color mapping table. This also supports blinking colors. Read more here

I’d just like to chime in here because this seems to be a common point of confusion. Implicit to Nathan’s reply is that you do not use scripting for stuff like this!

We are finding that many new users seem to instinctively jump right to the scripting feature, even to accomplish what should be the most basic tasks. I cannot empasize this enough: Always think property binding before you think scripting! Once you understand what is possible with the different types of property bindings, you will realize that you don’t have to use scripting very frequently at all! Property bindings are, in my opinion, the real magic of FactoryPMI and what make it a joy to use once you understand them.

And just to clarify, the sample code that nathan posted is an expression, not and action script. Expressions are a kind of property binding.

I hope that this clears things up a bit!