I came across an Ignition component named PMILabel. I hope, I can reuse it for my needs instead of taking care of custom expression execution. I’d like to dynamically add/remove pmiLabels with dynamic title expression, for example now(1000). Could you provide a simple example with a usage of AbstractVisionPanel and PMILabel?
Ignition windows are not designed to have components added or removed in a running client. There’s a whole bunch of undocumented and semi-documented stuff that goes on in the designer to set up the saved structure of a window so it opens with everything it needs. The only supported way to add/remove true components is through the template repeater and canvas.
If you have exotic/dynamic binding needs, use runScript(), or possibly my own objectScript(). Or create your own expression function that encapsulates the exotic logic you want.
Ignition windows are not designed to have components added or removed in a running client.
Ooops! Let's omit my wish to dynamically add/remove components in a running client. According to the Expression Binding tutorial, it is possible to bind expressions to ignition labels. If I am not mistaken, the label component is a PMILabel. I want to use this component in module development. How can I programmatically (in Java) bind label's text property to an expression?
e.g.
String expression = "now(1000)";
PMILabel label = new PMILabel();
// which of the following should be set?
label.setName(expression);
label.setPath(expression);
label.setPropertyValue("PROPERTY_NAME_UNKNOWN_FOR_ME", expression);
// After starting up the pmiLabel component it is expected to have dynamic
// title showing date time string
label.startupComponent(visionClientContext);
You don’t. Binding is a design-time operation, and the binding itself is stored in the window – it’s not part of the component.
Since you’re in Java, you simply need to override the getText() method of the PMILabel to run your computation (or run it once and cache it – depending on your logic requirements), and override the setText() method to discard any external attempt to override your logic. If the repeated update behavior is important, you’ll need to run your own swing Timer to trigger the updates. Whatever logic you are trying to perform with a binding, you need to simply write a private java method in your component that performs the equivalent (purely in java), calling it as needed to deliver the value for getText().