global class

The following pages list global class functions from PRIMER which can be used in D3PLOT.

Most of the D3PLOT functions are also in the global scope, but to make them easier to locate, they are presented in different categories (e.g. Contacts, CutSection, Data) in subsequent sections. They are also listed below in alphabetical order.

Class functions

D3PLOT functions

Details of functions

AllocateFlag() [static]

Description

Allocate a flag for use in the script. See also ReturnFlag(). Once allocated the flag is automatically cleared for all the models currently in D3PLOT.

Arguments

No arguments

Returns

Flag to use

Return type

Flag

Example

To allocate a flag

var flag = AllocateFlag();


DialogueInput(command[string]) [static]

Description

Executes one or more command-line syntax commands. There is no limit to the number of lines that may be specified in a single call. See Dialogue Command Syntax for a full list of command-line commands

The DialogueInputNoEcho variant is identical, except that it suppresses the echo of the commands to the dialogue box.

D3PLOT provides a full command-line syntax as an alternative to graphical user interface commands, and a sequence of such commands may be provided here.

Note that:

  • Each call to DialogueInput starts at the top of the D3PLOT command-line "tree", at the D3PLOT_MANAGER>>> prompt
  • Each call is autonomous, there is no "memory" of where in the command-line tree previous commands finished.
  • However within a single call the current command-line tree is remembered from one line to the next.
  • Commands are not case-sensitive, although filenames and titles in command strings are.

Therefore commands which require more than one line of input to complete must be specified in a single call; and it makes sense to group a sequence of related commands together in a single call, although this is not mandatory.

If this succeeds it returns true, otherwise false.

Arguments

  • command (string)

    Command to be executed (as if it had been typed into the dialogue box)

    This argument can be repeated if required
    Alternatively a single array argument containing the multiple values can be given

    Returns

    No return value

    Example

    // Blanks all solids.
    // Unblanks solids 1 to 10.
    // Performs a hidden line plot.
    // All commands are echoed to the dialogue box
    DialogueInput("BLANK SOLID ALL", "UNBLANK SOLID 1 to 10", "HIDDEN");
    


    DialogueInputNoEcho(command[string]) [static]

    Description

    Executes one or more command-line syntax commands. There is no limit to the number of lines that may be specified in a single call. See Dialogue Command Syntax for a full list of command-line commands

    This does not echo the commands to the dialogue box.

    See DialogueInput for more information.

    Arguments

  • command (string)

    Command to be executed (as if it had been typed into the dialogue box)

    This argument can be repeated if required
    Alternatively a single array argument containing the multiple values can be given

    Returns

    No return value

    Example

    // Read state 10
    // Performed a shaded ("greyscale" in command-line syntax)plot
    // Create a JPEG format file "image.jpg"
    // Command is not echoed to the dialogue box.
    DialogueInputNoEcho("STATE10", "/GREY GO", "/IMAGE jpeg image.jpg");
    


    ErrorMessage(string[Any valid javascript type]) [static]

    Description

    Print an error message to the dialogue box adding a carriage return.

    Arguments

  • string (Any valid javascript type)

    The string/item that you want to print

    Returns

    No return value

    Example

    To print the title of model object m as an error to the dialogue box

    ErrorMessage("The title is " + m.title);


    Execute(data[object]) [static]

    Description

    Execute a program or script outside D3PLOT and get the standard output and error streams.

    Arguments

  • data (object)

    Execute data

    Object has the following properties:

    Name Type Description
    arguments (optional) Array of strings The arguments to pass to program
    program string The program you want to run. Note that on Linux this will consider PATH when resolving executable filenames without an absolute path. If you want to run something from the current directory and you do not have '.' in your PATH then you will need to write './something' as the program.

    Returns

    Object with the following properties:

    Name Type Description
    status integer The exit code from the program/script
    stderr string The standard error output from the program/script
    stdout string The standard output from the program/script

    Return type

    object

    Example

    To run script "example.bat" with arguments "foo" and "bar":

    var output = Execute( { program: 'example.bat', arguments: [ 'foo', 'bar' ]} );
    var text   = output.stdout;
    var errors = output.stderr;
    var ecode  = output.status;


    Exit(write hook interrupt (optional)[boolean]) [static]

    Description

    Exit script

    Arguments

  • write hook interrupt (optional) (boolean)

    If Exit() is called from a write_hook.js script, the first argument will be processed as in the following: If the argument is provided and set to "true", it is used to interrupt the write out of the model, so that the script exits without anything being written out. An argument value of "false" exits the script and allows the model to be written out as normal. An example of this function's use in a Write Hook script can be found at $OA_INSTALL/primer_library/scripts/hooks/example_write_hook.js.

    Returns

    No return value

    Example

    Exit with

    Exit();


    ExitTHisLink() [static]

    Description

    Exits the T/HIS link from D3PLOT

    Arguments

    No arguments

    Returns

    No return value


    GetCurrentDirectory() [static]

    Description

    Get the current working directory

    Arguments

    No arguments

    Returns

    String containing current working directory

    Return type

    String

    Example

    To get the current directory:

    var cwd = GetCurrentDirectory();


    GetInstallDirectory() [static]

    Description

    Get the directory in which executables are installed. This is the OA_INSTALL environment variable, or if that is not set the directory in which the current executable is installed. Returns NULL if not found

    Arguments

    No arguments

    Returns

    string

    Return type

    String

    Example

    To get the install directory:

    var install_dir = GetInstallDirectory();


    GetPreferenceValue(program[string], name[string]) [static]

    Description

    Get the Preference value with the given string in the any of admin ("OA_ADMIN") or install ("OA_INSTALL") or home ("OA_HOME") directory oa_pref

    Arguments

  • program (string)

    The program name string : Valid values are 'All', 'D3PLOT', 'PRIMER', 'REPORTER', 'SHELL',
    'T/HIS'

  • name (string)

    The preference name string

    Returns

    : String containing preference value or null if preference string is not present in any oa_pref. Also if none of the above environment variables are not present, then API simply returns null. While returning preference value, locked preference value in admin and then install oa_pref takes precedence over home oa_pref. If preference is not locked in any of these oa_pref, preference in home directory oa_pref is returned.

    Return type

    String

    Example

    To get the preference value:

    var pref_list = GetPreferenceValue('All', "font_size");


    GetStartInDirectory() [static]

    Description

    Get the directory passed to D3PLOT by the -start_in command line argument

    Arguments

    No arguments

    Returns

    String containing start_in directory or NULL if not set

    Return type

    String

    Example

    To get the start_in directory:

    var start_in = GetStartInDirectory();


    Getenv(name[string]) [static]

    Description

    Get the value of an environment variable

    Arguments

  • name (string)

    The environment variable name

    Returns

    String containing variable value or null if variable does not exist

    Return type

    String

    Example

    To get the value for environment variable HOME

    var home = Getenv("HOME");


    Message(string[Any valid javascript type]) [static]

    Description

    Print a message to the dialogue box adding a carriage return.

    Arguments

  • string (Any valid javascript type)

    The string/item that you want to print. If '\r' is added to the end of the string then instead of automatically adding a carriage return in the dialogue box, the next message will overwrite the current one. This may be useful for giving feedback to the dialogue box when doing an operation.

    Returns

    No return value

    Example

    To print the title of model object m as a message to the dialogue box

    Message("The title is " + m.title);


    MilliSleep(time[integer]) [static]

    Description

    Pause execution of the script for time milliseconds. See also Sleep()

    Arguments

  • time (integer)

    Number of milliseconds to pause for

    Returns

    No return value

    Example

    To pause for 500 milliseconds

    MilliSleep(500);


    NumberToString(number[integer/real], width[integer], pref_int (optional)[boolean]) [static]

    Description

    Formats a number to a string with the specified width.

    Arguments

  • number (integer/real)

    The number you want to format.

  • width (integer)

    The width of the string you want to format it to (must be less than 80).

  • pref_int (optional) (boolean)

    By default only integer values inside the single precision 32 bit signed integer limit of approximately +/-2e9 are formatted as integers, all other numeric values are formatted as floats. With this argument set to TRUE then integer values up to the mantissa precision of a 64 bit float, approximately +/-9e15, will also be formatted as integers.

    Returns

    String containing the number

    Return type

    String

    Example

    To write the number 1.2345e+6 to a string 10 characters wide

    var str = NumberToString(1.2345e+6, 10);


    OpenManual(program[string], page[string]) [static]

    Description

    Open the Oasys manuals at a requested page

    Arguments

  • program (string)

    The program manual to open. Can be "primer", "d3plot" or "this"

  • page (string)

    The page to open in the manual, e.g. "running-this.html"

    Returns

    true if successful, false if not

    Return type

    Boolean

    Example

    To open the T/HIS manual on the running-this.html page

    OpenManual("this", "running-this.html");


    Print(string[Any valid javascript type]) [static]

    Description

    Print a string to stdout. Note that a carriage return is not added.

    Arguments

  • string (Any valid javascript type)

    The string/item that you want to print

    Returns

    No return value

    Example

    To print string "Hello, world!"

    Print("Hello, world!");

    To print the title of model object m with a carriage return

    print("The title is " + m.title + "\n");


    Println(string[Any valid javascript type]) [static]

    Description

    Print a string to stdout adding a carriage return.

    Arguments

  • string (Any valid javascript type)

    The string/item that you want to print

    Returns

    No return value

    Example

    To print string "Hello, world!" automatically adding a carriage return

    Println("Hello, world!");

    To print the title of model object m, automatically adding a carriage return

    Println("The title is " + m.title);


    ReturnFlag(flag[Flag]) [static]

    Description

    Return a flag used in the script. See also AllocateFlag().

    Arguments

  • flag (Flag)

    The flag to return

    Returns

    No return value

    Example

    To return flag f:

    ReturnFlag(f);


    SetCurrentDirectory(directory path[string]) [static]

    Description

    Sets the current working directory.

    Arguments

  • directory path (string)

    Path to the directory you would like to change into.

    Returns

    true if successful, false if not

    Return type

    Boolean

    Example

    To change into the directory "/data/test" exists

    SetCurrentDirectory("/data/test")


    Sleep(time[integer]) [static]

    Description

    Pause execution of the script for time seconds. See also MilliSleep()

    Arguments

  • time (integer)

    Number of seconds to pause for

    Returns

    No return value

    Example

    To pause for 2 seconds

    Sleep(2);


    StartTHisLink() [static]

    Description

    Starts the T/HIS link from D3PLOT

    Arguments

    No arguments

    Returns

    No return value


    System(string[Any valid javascript type]) [static]

    Description

    Do a system command outside D3PLOT. To run an external command and get the output then please use Execute() instead.

    Arguments

  • string (Any valid javascript type)

    The system command that you want to do

    Returns

    integer (probably zero if command successful but is implementation-dependant)

    Return type

    Number

    Example

    To make the directory "example"

    System("mkdir example");


    Unix() [static]

    Description

    Test whether script is running on a Unix/Linux operating system. See also Windows()

    Arguments

    No arguments

    Returns

    true if Unix/Linux, false if not

    Return type

    Boolean

    Example

    To test if the OS is Unix

    if ( Unix() )


    WarningMessage(string[Any valid javascript type]) [static]

    Description

    Print a warning message to the dialogue box adding a carriage return.

    Arguments

  • string (Any valid javascript type)

    The string/item that you want to print

    Returns

    No return value

    Example

    To print the title of model object m as a warning to the dialogue box

    WarningMessage("The title is " + m.title);


    Windows() [static]

    Description

    Test whether script is running on a Windows operating system. See also Unix()

    Arguments

    No arguments

    Returns

    true if Windows, false if not

    Return type

    Boolean

    Example

    To test if the OS is Windows

    if ( Windows() )