Share
 
 

Custom Scripts for the External BOM DataField

Learn about using custom scripts in the external BOM DataField property of elements to deliver better BOM reports.

You can use expressions in the DataField property to specify a custom output for the cells. All expressions used in the DataField property begin with the equals sign (=).

To add a custom script to a BOM report, select a cell and modify the DataField from the right pane of the BOM Template Editor dialog.

The text placed between /* and */ in the script is considered a comment and will be ignored.

Use a mathematical expression

Change the DataField property to the desired mathematical calculation. Before making the operations, the tokens need to be cast to an integer or double type. Without a cast, the tokens will be evaluated as strings.

Examples:

  • = (int) IQuantity - 1 /* This script will substract one from the IQuantity token */
  • = (double) ILength + 50 /* This script will add 50 mm to the ILength token */
  • = (double) IQuantity * 1.05 /* This script will multiply ILength with 1.05 */
  • = (double) ILength / 1000 /* This script will divide ILength by 1000 */

Concatenate strings

Change the DataField property for the text box to the following. Here, the tokens are automatically used as strings.

Example:

  • = IQuantity + " parts" /* This script will concatenate IQuantity and the string " parts" */

Use conditional statements

The DataField can be used with simple conditional statements in the form of:

(condition) ? (executed if condiftion is true) : (executed if condition is false)

Multiple conditions can be cascaded together.

Examples:

  • = ((int) IQuantity == 1) ? (IQuantity + " piece") : (IQuantity + " pieces") /* This script will output "1 piece" if the IQuantity equals one and "5 pieces" if IQuantity equals 5 */
  • = (int) IQuantity == 1 ? "One" : ((int) IQuantity == 2 ? "Two" : "Multiple") /* This script will output "One" if the IQuantity equals one, "Two" if IQuantity equals two and "Multiple" otherwise */

Other functions

The DataField can perform additional actions that are defined in C# System class.

Examples:

  • = System.Math.PI /* This script will output the number 3.14159 */
  • = System.Math.Round((double)IWidth) /* This script will output the rounded value of the IWidth token */
  • = System.DateTime.Now.ToString() /* This script will output the current date */
  • = IName.Substring(0, 2) /* This script will output the first two letters of the IName token */

Was this information helpful?