Script

Script editor is used to write Java scripts for manipulation or analysis of point data. This may be useful for calculating new fields or adjusting missing or default values as well as changing display attributes.

Scripts operate on point objects. An object must be selected for the script to work.

  1. Go to Edit > Object > Script. This will open a new panel.

  2. Write the required script in the top window.

  3. Enter the location to save the script in the Script field.

  4. The debugging window displays the changes the script will make to the selected data.

  5. Press the Test script button to show the changes the script will make in the debugging window.

  6. When complete, press Apply script to selection to run the script.

NoteScripting in GeologyCore follows the JavaScript syntax.

Point Script

The Object/Script option allows a simple Java script to be created to add or edit point attributes and adjust colouring.

Note:  More advanced data manipulation, using Python code, is available through the Online Python SDK Help.

The following is an example of a script to create a gold topcut field in a set of sample points and then adjust point visibility to display only points with positive grade values:

/*1 define topcut value*/
var topcut = 20;

/*2 add new variables*/
p.au_cut = -999;

/*3 calculate variable*/
if (p.au > topcut)
{
    p.au_cut = topcut;
}
else
{
    p.au_cut = p.au;
}
			
/*4 replace blank values with default*/
if (isNaN(p.au_cut))
{
    p.au_cut = -999;
}
			
/*5 make default values invisible*/
if (p.au_cut < 0)
{
    p.Visible = false;
}
else
{
    p.Visible = true;
}

1. Setting temporary variable

The var keyword will create a locally scoped variable which will last for the processing of a single point. This avoids having to create attributes which will only be needed for a single operation. JavaScript variables are dynamically typed, meaning the data type does not need to be specified.

Example: To define a topcut value of 20

var topcut = 20;

2. Adding and Deleting variables

To add a new variable, set the default value.

Example: To add au_cut field to samples

p.au_cut = -999;

Note:  The samples can be created using the Split by length modifier in the Domain Manager and the Point Extract tool.

This must be done outside of any guards, such as if or while statements, since it will need to be applied to every point before processing. It's also recommended to declare any new variables at the top of your script.

To delete, use the Delete macro. Since the delete macro is applied to the entire dataset at once, we needn't use the 'p.' namespace.

Delete(myAttribute);

3. Populate variable from a conditional formula

Note that variable names containing spaces can be called with the notation p[“<variable>”].

For example: LENGTH = p[“Bottom Depth”] – p[“Top Depth”]

if (p.au > topcut)
{
    p.au_cut = topcut;
}
else
{
    p.au_cut = p.au;
}

4. Set missing values to a default

If the referenced point is out of bounds and does not refer to a point in the dataset, any attributes will return a NaN value. This can be checked by using the built-in isNaN function. For example:

if (isNaN(p.au_cut))
{
    p.au_cut = -999;
}		

5. Visibility

Visible is a built-in attribute which can be used to change the visibility of a point, and is useful for filtering operations. It is used to hide points that have default value for grade. The Visible attribute can be set to 'true' or 'false'. For example:

if (p.au_cut < 0)
{
    p.Visible = true;
}
else
{
    p.Visible = false;
}

Note:  The visibility can later be adjusted with the Query and Filter, Attributes, and Show all options.