Check class

The Check class enables you to access model checking in PRIMER. More...

The PRIMER JavaScript API provides many class constants, properties and methods. For Arup to be able to extend and enhance the API in the future any constant, property or method names beginning with a lowercase or uppercase letter are reserved.
If you need to add your own properties or methods to one of the existing classes then to avoid any potential future conflict you should ensure that the name begins with either an underscore (_) or a dollar sign ($) or the name is prefixed with your own unique identifier.
For example if company 'ABC' need to add a property called 'example' then to avoid any potential future conflict use one of:

Class functions

Check constants

Constants for Dashboard

Name Description
Check.ERROR Dashboard check gave error(s)
Check.OK Dashboard check status OK
Check.UNKNOWN Dashboard check status unknown (not run)
Check.WARNING Dashboard check gave warning(s)

Constants for dashboard health colour

Name Description
Check.BLACK Colour black
Check.BLUE Colour blue
Check.CYAN Colour cyan
Check.DARKBLUE Colour dark blue
Check.DARKGREEN Colour dark green
Check.DARKGREY Colour dark grey
Check.DARKRED Colour dark red
Check.GREEN Colour green
Check.GREY Colour grey
Check.LIGHTGREY Colour light grey
Check.MAGENTA Colour magenta
Check.ORANGE Colour orange
Check.RED Colour red
Check.WHITE Colour white
Check.YELLOW Colour yellow

Detailed Description

The Check class is used add checks to PRIMER using JavaScript. Two different types of checks can be added:

  • Individual checks for each node, part, shell etc in a model.
  • Custom checks that can reference multiple entities for checking in a model
PRIMER will look in 3 locations for additional JavaScript checks to run when doing checking:
  • OA_ADMIN/primer_library/scripts/checks
  • OA_INSTALL/primer_library/scripts/checks
  • HOME/primer_library/scripts/checks
The directories OA_INSTALL/primer_library/scripts etc can be changed with the primer*script_dir preference.
For individual checks PRIMER will look in these directories for a script with the name 'class_name.js'. For example if you wanted to write a script that will be run for every part in a model the script should be called 'Part.js'.
For custom checks PRIMER will look in these directories for a script called 'custom.js'. This obviously means that there can only be one custom script in each directory. These filenames are case sensitive.
Individual scripts will be called with 3 arguments:
arguments[0] = Name of the script
arguments[1] = model object
arguments[2] = Item object
Individual scripts can add warnings or errors by using the Warning() or Error() methods of the appropriate class. For example for a Part the script can call the methods Part.Error() and Part.Warning(). The script should not call the Error() and Warning() methods of other classes.
As a simple example of an individual check, suppose you wanted it to be an error if any shell parts in your model did not use type 16 shells. Add a script called 'Part.js' in the directory 'OA_INSTALL/primer_library/scripts/checks' (or one of the other directories) containing:

// arguments[0] is name of script
var m = arguments[1];	// arguments[1] is model pointer
var p = arguments[2];	// arguments[2] is part pointer

if (p.exists && p.secid)
{
    var s = Section.GetFromID(m, p.secid);
    if (s.exists && s.type == Section.SHELL && s.elform != 16)
        p.Error("Shell part elform not 16", "Fictional company policy is to use elform 16 for shell parts");
}

Custom scripts will be called with 2 arguments:
arguments[0] = Name of the script
arguments[1] = model object
Custom scripts can add warnings or errors by using the static Check.Error() and Check.Warning() methods. The script should not call the Error() and Warning() methods of other classes.
As a simple example of a custom check, suppose a dummy uses node 1000 for the H-point and this should be at coordinates (1000, -500, 100) within tolerance of 0.1 for an analysis . You do not want to run a check for every node in the model (i.e. an individual check). You just want to check that node 1000 is at the correct coordinates. To do this you could create a script called 'custom.js' in the directory 'OA_INSTALL/primer_library/scripts/checks' (or one of the other directories) containing:

// arguments[0] is name of script
var m = arguments[1];	// arguments[1] is model pointer

var n = Node.GetFromID(m, 1000);
if (!n)
    Check.Error("No H-point node", "Model does not contain node for dummy H-point");

if (!n.exists)
    Check.Error("H-point node not defined", "Dummy H-point node is referred to but not defined");

var dx = n.x - 1000;
var dy = n.y - (-500);
var dy = n.z - 100;
var d = Math.sqrt(dx*dx + dy*dy + dz*dz);
if (d > 0.1)
    Check.Error("H-point not at correct position", "Dummy H-point is "+d+"mm away from target position");

See the documentation below for more details.

Details of functions

AddDashboardComment(comment[string]) [static]

Description

Adds a comment for a user dashboard check. Multiple comments can be added. Call this function as many times as required.
This function should only be called from a user JavaScript dashboard script.

Arguments

  • comment (string)

    The comment to add.

    Returns

    No return value

    Example

    To add a comment:

    Check.AddDashboardComment("This is a comment");


    AddDashboardHealth(model health[String], Health text colour (optional)[constant], Health button colour(optional)[constant]) [static]

    Description

    Allows the user to add the value of model health based on the other dashboard results
    This function should only be called from model_health.config.js which should be placed with the other user defined dashboard scripts.

    Arguments

  • model health (String)

    Text which will be displayed on the dashboard panel and the summary files.

  • Health text colour (optional) (constant)

    Colour of the model health text. The default colour is Black.

  • Health button colour(optional) (constant)

    Colour of the model health button. The default colour is dark grey.

    Returns

    No return value

    Example

    To add computed health as "Model Health 85.1%" and the text colour to red and the button colour to green

    Check.AddDashboardHealth("Model Health 85.1%",Check.RED,Check.GREEN);


    Error(message[string], details (optional)[string]) [static]

    Description

    Adds a custom error. This function should only be called from a custom JavaScript check script. See the details in the Check class for how to do this.

    Arguments

  • message (string)

    The error message to give

  • details (optional) (string)

    An optional detailed error message

    Returns

    No return value

    Example

    To add an error message "My custom error":

    Check.Error('My custom error');


    GetAllDashboards() [static]

    Description

    Returns data from all the dashboards that are defined.
    This function should only be called from model_health.config.js which should be placed with the other user defined dashboard scripts.
    The dashboard properties are:

    • result (Overall result of the dashboard)
    • title (dashboard title)
    • message1 (First message of the dashboard)
    • message2 (Second message of the dashboard)
    • comments (Array of comments on the dashboard)

    Arguments

    No arguments

    Returns

    Array of dashboard objects

    Return type

    Array

    Example

    To get the status of all the dashboards:

    Check.GetAllDashboards();

    For more details on how to use this function, please take a look at the example script model_health.config.js which is present in the dashboard scrips folder


    KeyoutHook(interrupt flag[boolean]) [static]

    Description

    Used to proceed with or abort the keyout operation (Ansys LS-DYNA output) from the keyout_hook.js script. The current hooks are launched just before the keyout operation from the model write tab, writing from the dialogue box and during keyout from the include tree. Please look at the example_keyout_script.js for an example of its usage.

    Arguments

  • interrupt flag (boolean)

    If this flag is set to true then keyout is aborted else keyout proceeds as usual.

    Returns

    No return value

    Example

    To abort a keyout, set the following line in keyout_hook.js:

    Check.KeyoutHook(true);


    SetDashboardMessage(first[string], second (optional)[string]) [static]

    Description

    Adds a message for a user dashboard check. Each dashboard can currently show two messages.
    This function should only be called from a user JavaScript dashboard script.

    Arguments

  • first (string)

    The first message to add.

  • second (optional) (string)

    The second message to add.

    Returns

    No return value

    Example

    To add the message with two lines:

    Check.SetDashboardMessage("This is a message", "shown on two lines");

    To add the message with one line:

    Check.SetDashboardMessage("This is a single message");


    SetDashboardStatus(status[constant]) [static]

    Description

    Sets the status of a user dashboard check.
    This function should only be called from a user JavaScript dashboard script.

    Arguments

  • status (constant)

    The status. Can be Check.OK, Check.WARNING, Check.ERROR or Check.UNKNOWN.

    Returns

    No return value

    Example

    To set the status to OK (green):

    Check.SetDashboardStatus(Check.OK);


    Warning(message[string], details (optional)[string]) [static]

    Description

    Adds a custom warning. This function should only be called from a custom JavaScript check script. See the details in the Check class for how to do this.

    Arguments

  • message (string)

    The warning message to give

  • details (optional) (string)

    An optional detailed warning message

    Returns

    No return value

    Example

    To add a warning message "My custom warning":

    Check.Warning('My custom warning');