Change the expression or reference of a custom property at runtime
- Last UpdatedJul 16, 2024
- 3 minute read
You can change the expression or reference of a custom property at runtime by calling the SetCustomPropertyValue() method on the graphic using a client script:
SetCustomPropertyValue(System.String name, System.String value, System.Boolean isConstant);
You can select this method using the Element Browser from within the Industrial Graphic Editor.
This method has three parameters:
-
name - Name of the custom property to be modified on the graphic. This parameter is of type string, and it can be a reference or a constant.
-
value - The new value to be set. This parameter is of type string, and it can be an expression, reference, or constant. If the value is given in quotes ("), then the value is considered a constant. If the value is given without quotes, then the value of the expression is considered a reference.
-
isConstant - A flag that indicates whether the new value will be evaluated as a constant or a reference. This parameter is of type Boolean. If it is set to True (1), then the new value will be treated as a constant. If it is set to False (0), then the new value will be treated as a reference. This parameter only applies when the value parameter is a reference or constant and the custom property specified in the name parameter is a string or time type. This parameter has no meaning if the custom property is an integer, float, Boolean, or double type.
Note: The isConstant parameter does not override the type of input for the value parameter. The value parameter itself can be either a constant or a reference depending on whether it is enclosed in quotes. The isConstant parameter is only determining how the actual value (coming from the value parameter) is evaluated.
The whole expression or reference of the custom property is replaced with the new value, regardless if it is overridden or not. No partial replacement is supported.
Only public custom properties on the graphic can be changed.
When the method executes, it overrides any modifications done by previous IOSetRemoteReference() calls from a native InTouch script.
For an example of configuring the custom property as a reference, say you have a Motor_001 object with the string attribute name "State" that stores the current state of the motor ("Running" or "Stopped"). You also have an Industrial graphic that has the string data type custom property "MotorState." The following script code will set the MotorState custom property to Motor_001.State in runtime:
GraphicA.SetCustomPropertyValue("MotorState","Motor_001.State",False);
As a result of the call, the function will set the string custom property GraphicA.MotorState to "Motor_001.State" as a reference. The string custom property GraphicA.MotorStatus will resolve that reference and update its value with the reference value ("Running" or "Stopped").
For an example of configuring the custom property as a constant, say you have a Motor_001 object with the Boolean attribute name "State" that reflects the current state of the motor (True or False). You also have an Industrial graphic that has the string data type custom property "MotorState." The following script code causes the MotorState custom property to hold the state of equipment—"Running" or "Stopped"—as text based on the value returned for Motor_001:
IF Motor_001.State THEN
GraphicA.SetCustomPropertyValue("MotorState","Running",True);
ELSE
GraphicA.SetCustomPropertyValue("MotorState","Stopped",True);
ENDIF;
As a result of the call, the function will set the string custom property GraphicA.MotorState to "Running" or "Stopped," depending on the value of Motor_001.State.