Chapter 7 Scripting
This chapter is intended to help familiarize users with the scripting features of Opencontour. This includes a walkthrough of the Create Script module, which utilizes Javascript to manipulate and create unique properties.
Video: Scripting Overview
Quick Access
7.1 Create Script Module
To open the Script window, click the Create Script button in the Utility Menu.
Utility Menu - Create Script

Scripts are useful for adding or editing properties for a chosen layer. The expressions are written in JavaScript and that involve calculations of other properties and/or numbers and can be time dependent.
-
Scripts are used to add predefined properties to the Mineplan used in Quick Charts and Reports.
-
Scripts can be written to run over the Mineplan before, during or after running a schedule.
-
A variable used in a script must either already exist in the layer on which it is working or be defined in the script's previous line.
Create Script Window

7.1.1 Script Input Overview
This section will detail how the inputs work within the Create Script module:
| Input Name | Description |
|---|---|
| # Incl | This first column allows users to select which expressions they would like to select to run when they click Run Script. Pressing the top box will select/de-select all scripts in the window |
| Prop | This column allows users to input the property that they would like to run scripts on to manipulate. A user may also choose to create a new property within this column using pre-existing conditions |
| Script Expression | This box allows the user to input the expression or value that they would like to attribute to the selected property. For more information on how to use Javascript, please navigate to 7.2 JavaScript General Guide |
| Description | Allows the user to make various notes on the script, describe what the script is doing |
7.1.2 Choose Layer
This dropdown menu will allow the user to select the layer than they would like to apply their scripts to. It automatically defaults to the Mineplan layer.
7.1.3 Add Script
This button allows the user to import their script into the project. The script must be in a .JSON format in order to import correctly.
7.1.4 Loaded Scripts
This dropdown displays all of the scripts that are currently available to select within the project. Once a script is selected, it should populate in the input boxes below accordingly.
Scripts may be deleted from this list by clicking the Delete button when the script is selected from the menu.
7.1.5 Script Name
Allows user to manipulate or set a name for the script they are working on.
7.1.6 Boilerplate
Opencontour offers 7 boilerplate scripts that the user may choose to select from and edit if they do not have any scripts setup by themselves. These scripts can be used to set blast and haul physicals, finance prices, and truck information as well.
7.1.7 Saving and Exporting
There are several ways that a user may choose to save and/or export their work within the Create Script module:
- SaveScript - Simply pressing the SaveScript button allows the user to save all the work they have done within the window if they wish to temporarily navigate to another window within the project.
- SaveScript + Export - This combination will enable the user to save the current script that they are working on as a .JSON file.
- SaveScript + Export + All - This combination will allow the user to save all of the loaded scripts in their project as a single .JSON file
7.1.8 Script Order
This feature allows the user to select the order in which they would like to execute multiple scripts at one time.
7.2 JavaScript General Guide
7.2.1 Operators
| Operator | Example | Description |
|---|---|---|
= |
x=y |
Assigns the value of x to the value of y |
+ |
x+y |
Adds the value of x to the value of y |
- |
x-y |
Subtracts the value of y from the value of x |
* |
x*y |
Multiplies the value of x with the value of y |
/ |
x/y |
Divides the value of x by the value of y |
== |
x==y |
Tests if the value of x is equal to y |
!= |
x!=y |
Tests if the value of x is not equal to y |
> |
x>y |
Tests if the value of x is greater than y |
< |
x<y |
Tests if the value of x is less than y |
>= |
x>=y |
Tests if the value of x is greater than or equal to y |
<= |
x<=y |
Tests if the value of x is less than or equal to y |
% |
x%y |
Divides x by y and reports the remainder e.g. 12%5=2 |
** |
x**y |
Places x to the power of y |
7.2.2 Logical Operators
| Logical Operator | Description |
|---|---|
&& |
Logical "and" |
| | | | Logical "or" |
! |
Logical "not" |
7.2.3 Syntax
| Rule | Example |
|---|---|
| Data is in name/value pairs | name: "Joe" |
| Data is separated by commas | name: "Joe", age: 21, backendDeveloper: true |
| Curly braces hold objects | function MyFunction(){alert("Hello world!")} |
| Square brackets hold arrays | ["apple", "banana", "peach", "pear"] |
7.2.4 Decimals
| Operator | Description | Calculated Value | Reported Value |
|---|---|---|---|
+(data.dens*data.vol).toFixed(0) |
No Decimals | 56842.88861132361 | 56843 |
+(data.dens*data.vol).toFixed(5) |
5 Decimals | 56842.88861132361 | 56842.88861 |
7.2.5 Math Objects
| Math Method | Description |
|---|---|
abs(x) |
Returns absolute value of x |
acos(x) |
Returns the arccosine of x, in radians |
asin(x) |
Returns the arcsine of x, in radians |
atan(x) |
Returns the arctangent of x as a numeric value between -π/2 and π/2 radians |
atan2(y,x) |
Returns the arctangent of the quotient of its arguments |
ceil(x) |
Returns x, rounded upwards to the nearest integer |
cos(x) |
Returns the cosine of x, in radians |
exp(x) |
Returns the value of ex |
floor(x) |
Returns x, rounded downwards to the nearest integer |
log(x) |
Returns the natural logarithm (base E) of x |
max(x,y,z,..., n) |
Returns number with the highest value |
min(x,y,z,..., n) |
Returns number with the lowest value |
pow(x,y) |
Returns the value of xy |
random() |
Returns a random number between 0 and 1 |
round(x) |
Rounds x to the nearest integer |
sin(x) |
Returns the sine of x, in radians |
sqrt(x) |
Returns √x |
tan(x) |
Returns the tangent of x |
7.2.6 Math Constants
| Math Constant | Description | Value |
|---|---|---|
| Math.E | Euler's number, base of natural logs | ~2.718 |
| Math.LN2 | Natural log of 2 | ~0.693 |
| Math.LN10 | Natural log of 10 | ~2.303 |
| Math.LOG2E | Base-2 log of E | ~1.443 |
| Math.LOG10E | Base-10 log of E | ~0.434 |
| Math.PI | π | ~3.14159 |
| Math.SQRT1_2 | Square root of √0.5 | ~0.707 |
| Math.SQRT2 | Square root of 2 | ~1.414 |
7.2.7 Opencontour Examples
| Property Equation Entry | Notes |
|---|---|
if(data.au>=1){"H"}else{if(data.au>=0.5){"L"}else{0}} |
Nested if: if(){}else{else{}} Alphanumeric Reference: “H” & “L” |
if(data.au>0.3){1}else{0} |
If: if(){}else{} Greater than: > |
if(data.ag>=110){2}else{if(data.ag>=30.72){1}else{0}} |
Nested if: if(){}else{else{}} Greater than or Equal to: >= |
if(data.class>0&&data.class<3&&data.sulf<1&&data.jcode=="I"){0.64}else{0} |
Logical "And": && Test if a=b: a==b |
if(data.r>5){data.el*((0.102/2)^2*Math.PI)}else{data.el*((0.203/2)^2*Math.PI)} |
Pi: Math.PI Value Squared: ^2 |
if(data.r>=5&&data.walld>0){+(data.walld/0.5).toFixed(0)}else{0},+(0.4*data.ec).toFixed(2) |
0 Fixed Decimal Places: .toFixed(0) 2 Fixed Decimal Places: .toFixed(2) +, Sometimes required before an expression: + |
+(data.pa*settings.bench_height).toFixed(2) |
Project Settings BenchHeight: settings.bench_height |
if(data.pn=="OC1"&&data.ow>0&&data.otns>1){(data.otns*data.au)/data.otns}else{0} |
Grade by pn, for metal data.au |
if(data.pn.substring(0,4)=="pick"){data.otns*data.au}else{0} |
Partial string name, using characters 0‐4 |
if(data.pn=="ph2"){"dump2"}else{"dump1"} |
Alphanumeric Reference: “ph2”,“dump2”&“dump1” |
if(data.pn.includes("GP")){1}else{2} |
Checks for String “GP” in array |
if(data.z=2135&&data.au==null){data.tns}else{0} |
Null reference |
{data.ow+"_"+data.pm} |
Write data.ow_data.pm |
7.2.8 External References
| Website | Website URL |
|---|---|
| MDN Web Docs | https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math |
| w3schools | https://www.w3schools.com/jsref/jsref_obj_math.asp |
7.3 Tutorial Project Part 5: Scripting
For this section of the project, the user will populate scripts for their project using the boilerplate finance scripts offered by Opencontour. These scripts will effect the results visible in the charts and reports later.
7.3.1 Finance Scripting
- Exit the Create Schedule module and navigate to the Create Script module
- The Create Script module is capable of running many different Javascript functions, but for schedule reporting, the most relevant will be finance scripting
- Under the Boilerplate dropdown, locate Finance_Script. Then, hit Load
- Once the scripts are populated, ensure they are relevant to the specific metal that the mineplan is for. They are built to calculate for Gold, and may need to be modified if another metal is involved
- The window should now look like this:
Boilerplate Finance Scripts

- Once this is completed, ensure the Choose Layer dropdown has the Mineplan layer selected. Click Run Script
- A pop-up should appear indicating that the scripts were calculated for mineplan features. This is what it looks like:
Scripts Pop-Up Window
