API for dynamic links¶
Introduction
The APIs described below set/remove dynamic links on the variables. They are supplied by the IUAVariable
C# class.
IUAVariable.SetDynamicLink(source, mode)¶
Sets a dynamic link whose source is the variable indicated in the first argument. The second argument (optional) sets the dynamic link mode.
void SetDynamicLink(IUAVariable source, DynamicLinkMode mode);
Arguments
source
IUAVariable
BrowseName of the source variable.
mode
DynamicLinkMode
Link mode:
DynamicLinkMode.Read (default): read (from source node to parent)
DynamicLinkMode.Write: write (from parent to source)
DynamicLinkMode.ReadWrite: read and write (bidirectional)
Example
Below is an example in which the API sets a read dynamic link on the Speed property (whose node is represented by SpeedVariable
) of the Motor1 object. The link source is the Text property of the SpeedLabel object:
var myObj = Owner.Get<Motor>("Motor1");
var speedValue = Owner.GetObject("SpeedLabel").GetVariable("Text");
myObj.SpeedVariable.SetDynamicLink(speedValue, DynamicLinkMode.Read);
IUAVariable.SetDynamicLink(source, sourceArrayIndex, mode)¶
Sets a dynamic link whose source is the array indicated in the first argument and specifically the cell indicated in the second argument. The third argument (optional) sets the dynamic link mode.
void SetDynamicLink(IUAVariable source, uint sourceArrayIndex, DynamicLinkMode mode);
Arguments
source
IUAVariable
BrowseName of the source array.
sourceArrayIndex
uint
Cell of the source array.
mode
DynamicLinkMode
Link mode:
DynamicLinkMode.Read (default): read (from source node to parent)
DynamicLinkMode.Write: write (from parent to source)
DynamicLinkMode.ReadWrite: read and write (bidirectional)
Example
Below is an example in which the API sets a read dynamic link on the Speed property (whose node is represented by SpeedVariable
) of the Motor1 object. The link source is the second cell of the SpeedList array:
var myObj = Owner.Get<Motor>("Motor1");
var speedValue = Project.Current.FindVariable("SpeedList");
myObj.SpeedVariable.SetDynamicLink(speedValue, 2, DynamicLinkMode.Read);
IUAVariable.ResetDynamicLink()¶
Remove a dynamic link set on a variable.
void ResetDynamicLink();
Example
Below is an example in which the API removes the dynamic link set on the Text property (whose node is represented by TextVariable
) of the project object corresponding to myLabel
:
myLabel.TextVariable.ResetDynamicLink();
See also
Related concepts
Related procedures
References