Hello!
I got an interesting question and thought it would be nice to share the answer here.
Question: How can I make a status bar that is dynamic/flexible in AIMMS?
This is how I tried it, but it didn't work:
StringParameter sp_fixedStatusBar {
IndexDomain: (webui::indexApplicationExtension,webui::indexStatusBarSpec);
Definition: {
data
{
( 1, icon ) : "aimms-glass" ,
( 1, color ) : "red" ,
( 1, text ) : "sp_context",
( 1, tooltip ) : "sp_statusTooltip" ,
( 1, procedure ) : "pr_toggleDeveloper",
( 1, state ) : "Active"
}
}
}
For those unfamiliar with the data { } construct, this may be a pitfall, since you imagine that the string parameter could be used like above - but it doesn't work that way.
This construct only allows you to add data - it doesn't cater for the dynamic/flexible part.
But there are two solutions.
Dynamic definition
Probably the simplest solution to this, is just to switch from the data { } construct to the { } construct, as below:
StringParameter sp_dynamicStatusBar {
IndexDomain: (webui::indexApplicationExtension,webui::indexStatusBarSpec);
Definition: {
{
( '1', 'header' ) : "",
( '1', 'icon' ) : "aimms-glass",
( '1', 'color' ) : "red",
( '1', 'text' ) : sp_context,
( '1', 'tooltip' ) : sp_statusTooltip,
( '1', 'procedure' ) : "pr_toggleDeveloper",
( '1', 'state' ) : "Active"
}
}
}
Please note that:
- You need now to place simple quotes around the elements you want to define the value
- You need to remove the double quotes from the string parameters
This allows for the status bar to be flexible and updated automatically when values change.
Initial values or Procedure defined
The other solution is to not make the status bar string parameter defined. Either initialize it with the initial values option, or by a procedure that fills it out.
Like for the above, you could update the text via a procedure, like:
sp_dynamicStatusBar('1','text') := "My new text";
Please note that sp_dynamicStatusBar cannot be “defined” anymore, or else you will get an error.
You can download an example of this working in the Vessel Scheduling example: https://how-to.aimms.com/Articles/590/590-vessel-scheduling.html
Hope it helps!