This post describes:
A method to do conditional formatting (as in Excel) of a Text Field’s background color.
A trick to show symbols in a Text Field.
The Sample Model
Download the model HTML text boxes - Part 3.ebs on my Ebsilon Tips OneDrive to see the tricks described in this post.
Conditional Formatting
In the first screenshot, both cells in the second row had their background color (bgcolor) set to white. But just like in “regular” text boxes, you can use {expression} syntax. For example, the if-test enclosed in curly brackets
<td bgcolor = {InDesignMode($) ? "yellow" : "silver"}>
uses a function called “InDesignMode” which looks at “the thing it’s attached to” and returns True or False. If the object is in Design Mode, the text evaluates to
<td bgcolor = "yellow">
If it’s not in Design Mode, the text becomes
<td bgcolor = "silver">
This is seen in the following screenshot, taken from the Design profile of the HTML text boxes - Part 3.ebs model. The bottom-right cell has the conditional formatting of the background color:
Bonus Trick
In a standard Text Field, you can chose a font, but that font is used for the entire Text Field. With HTML, you change fonts freely within the body of text. This lets you use symbolic fonts such as Wingdings or Webdings to embed characters.
Here’s the syntax to used in this example to set the font of the bottom-right cell to red, 16-point, Webdings:
<font size="16" face="webdings" color="red">
And rather than static text, the bottom-right cell has an expression with an if-test:
{InDesignMode($)? "a" : "x"}
In Webdings font, “a” is the Check Mark symbol, and “x” is the “No” symbol.
The InDesignMode function
You probably don’t really need to have this information displayed on a heat balance diagram, but the HTML text fields was a useful way to demonstrate what it does.
A more likely application for this function is in a Macro that uses custom Kernel Scripting to do engineering calculations, where you probably need to determine whether it is in Design mode or not.
This is not as simple as one might think. By convention, the specification variable FMODE can be set to GLOBAL, Local Design, or Local Off-Design. But we also have the profile’s “light bulb” to consider. It’s usually on (Design Mode) in the Design profile, and off (Off-Design) in sub-profiles:
So, we have 6 possible combinations to consider.
The status of the “light bulb” is given by the variable “@calcoptions.sim.globalmode”. Thus, the six combinations are:
In a text field (or specification), an {expression} with some nested if-tests can be used to evaluate these combinations:
{ $.FMODE = -1 ? "Design" :
($.FMODE = 0 ? (@calcoptions.sim.globalMode = 0 ? "yellow" :"silver") : "silver")}
($.FMODE = 0 ? (@calcoptions.sim.globalMode = 0 ? "yellow" :"silver") : "silver")}
That’s hard to read (and hard to write). Compare that to what I showed before:
{InDesignMode($) ? "yellow" : "silver"}
“Clarity is key”, I always say.
The Source Code
The attached model has an internally-stored EbsScript with the code for the function “InDesignMode”:
This code considers the 6 combinations and returns True or False.
As described in this post — Custom Defined Functions — there are some extra things you need to do to make a function available in text fields and other EbsScripts. Take a look at it.