The global class is the main JavaScript class. 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:
Detailed DescriptionThe global class declares the global object in JavaScript that contains the global properties and methods. As well as the core JavaScript methods, PRIMER also defines other additional ones. e.g. Message(), Print() etc. See the documentation below for more details. |
Details of functionsAllocateFlag() [static]DescriptionAllocate a flag for use in the script. See also ReturnFlag() and Model.PropagateFlag(). Once allocated the flag is automatically cleared for all the models currently in PRIMER. |
No arguments
ReturnsFlag Return typeNumber |
ExampleTo allocate a flag var flag = AllocateFlag();
|
No arguments
Returnstrue if in batch mode, false if not Return typeBoolean |
ExampleTo test if PRIMER is in batch mode var batch_mode = BatchMode();
|
The name of the function (or null to remove the function)
ReturnsNo return value |
ExampleTo set function MyDialogueFunction as the dialogue function: DialogueFunction(MyDialogueFunction);
|
DialogueInput(command[string]) [static]DescriptionExecute one or more lines of command line dialogue input. |
Command to execute (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
Returns0: No errors/warnings. Return typeNumber |
DialogueInputNoEcho(command[string]) [static]DescriptionExecute one or more lines of command line dialogue input with no echo of commands to dialogue box. |
Command to execute (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
Returns0: No errors/warnings. Return typeNumber |
ErrorMessage(string[Any valid javascript type]) [static]DescriptionPrint an error message to the dialogue box adding a carriage return. |
The string/item that you want to print
ReturnsNo return value |
ExampleTo print the title of model object m as an error to the dialogue box ErrorMessage("The title is " + m.title);
|
Execute(data[object]) [static]DescriptionExecute a program or script outside PRIMER and get the standard output and error streams. |
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 |
object
Exit(write hook interrupt (optional)[boolean]) [static]DescriptionExit script |
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.
ReturnsNo return value |
ExampleExit with Exit();
|
FlagsAvailable() [static]DescriptionNumber of flags available to be used for AllocateFlag() |
No arguments
ReturnsNumber of flags available Return typeNumber |
ExampleTo get the number of flags available: var flags = FlagsAvailable();
|
GetCurrentDirectory() [static]DescriptionGet the current working directory |
No arguments
ReturnsString containing current working directory Return typeString |
ExampleTo get the current directory: var cwd = GetCurrentDirectory();
|
No arguments
Returnsstring Return typeString |
ExampleTo get the install directory: var install_dir = GetInstallDirectory();
|
The program name string : Valid values are 'All', 'D3PLOT', 'PRIMER', 'REPORTER', 'SHELL',
'T/HIS'
The preference name string
ExampleTo get the preference value: var pref_list = GetPreferenceValue('All', "font_size");
|
GetStartInDirectory() [static]DescriptionGet the directory passed to PRIMER by the -start_in command line argument |
No arguments
ReturnsString containing start_in directory or NULL if not set Return typeString |
ExampleTo get the start_in directory: var start_in = GetStartInDirectory();
|
Getenv(name[string]) [static]DescriptionGet the value of an environment variable |
The environment variable name
ReturnsString containing variable value or null if variable does not exist Return typeString |
ExampleTo get the value for environment variable HOME var home = Getenv("HOME");
|
Labels(type[string], state (optional)[boolean]) [static]DescriptionSet or get labelling of items in PRIMER |
The type of the item (for a list of types see Appendix I of the PRIMER manual). Additionally, to change the visibility of attached or unattached nodes you can use the types "ATTACHED_NODE" and "UNATTACHED_NODE".
If it is provided it is used to set the labelling status of entity. "true" to make items labelled and "false" to make them not labelled.
ReturnsBoolean Return typeBoolean |
ExampleTo turn on beam labels Labels("BEAM", true);To get the labelling status of beams var lab = Labels("BEAM");
|
The name of the function (or null to remove a function)
ReturnsNo return value |
ExampleTo set function MyMacroFunction as the macro function: MacroFunction(MyMacroFunction);
|
Message(string[Any valid javascript type]) [static]DescriptionPrint a message to the dialogue box adding a carriage return. |
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.
ReturnsNo return value |
ExampleTo print the title of model object m as a message to the dialogue box Message("The title is " + m.title);
|
MilliSleep(time[integer]) [static]DescriptionPause execution of the script for time milliseconds. See also Sleep() |
Number of milliseconds to pause for
ReturnsNo return value |
ExampleTo pause for 500 milliseconds MilliSleep(500);
|
NumberToString(number[integer/real], width[integer], pref_int (optional)[boolean]) [static]DescriptionFormats a number to a string with the specified width. |
The number you want to format.
The width of the string you want to format it to (must be less than 80).
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.
ReturnsString containing the number Return typeString |
ExampleTo 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]DescriptionOpen the Oasys manuals at a requested page |
The program manual to open. Can be "primer", "d3plot" or "this"
The page to open in the manual, e.g. "running-this.html"
Returnstrue if successful, false if not Return typeBoolean |
ExampleTo open the T/HIS manual on the running-this.html page OpenManual("this", "running-this.html");
|
PlayMacro(filename[string], options (optional)[object]) [static]DescriptionPlay a macro in PRIMER |
The name of the macro file to play
Options specifying how the macro file should be replayed. If omitted the default values below will be used.
Object has the following properties:
| Name | Type | Description |
| delay | integer | Delay in ms between commands when replaying. If omitted the current value from macro window will be used. |
| pick | boolean | If picks/drags from the macro file should be replayed. If omitted the current value from macro window will be used. |
| terminate | boolean | If the script should be terminated if an error occurs when playing the macro. If omitted the script will be terminated. |
| utf8 | boolean | If the script is UTF-8 encoded. If omitted or false the script is assumed to be ASCII text. |
| variables | object | Object containing names and values for variables in the macro. If null or omitted no variables are used. |
| view | boolean | If views encoded in the macro file for picks/drags should be replayed. If omitted the current value from macro window will be used. |
Returnstrue if an error occured during playback, false otherwise. Return typeBoolean |
The name of the macro file to play
If picks/drags from the macro file should be replayed. If omitted the current value from macro window will be used.
If views encoded in the macro file for picks/drags should be replayed. If omitted the current value from macro window will be used.
Delay in ms between commands when replaying. If omitted the current value from macro window will be used.
Object containing names and values for variables in the macro. If null or omitted no variables are used.
If the script should be terminated if an error occurs when playing the macro. If omitted the script will be terminated.
Returnstrue if an error occured during playback, false otherwise. Return typeBoolean |
Print(string[Any valid javascript type]) [static]DescriptionPrint a string to stdout. Note that a carriage return is not added. |
The string/item that you want to print
ReturnsNo return value |
ExampleTo 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]DescriptionPrint a string to stdout adding a carriage return. |
The string/item that you want to print
ReturnsNo return value |
The minimum build number that is required.
ReturnsNo return value (if the build is not high enough the script will terminate) |
ExampleTo only allow a script to run if the build is >= 2000 Requires(2000);
|
ReturnFlag(flag[Flag]) [static]DescriptionReturn a flag used in the script. See also AllocateFlag() and Model.PropagateFlag(). |
The flag to return.
ReturnsNo return value. |
ExampleTo return flag f: ReturnFlag(f);
|
The name of the script file to run. If the filename is relative then the file will be searched for relative to this script. If not found then the script_directory preference will be used.
If the script will use separate memory from the current script. If it uses separate memory (true) then the 'child' script is completely separated from this script and knows nothing about variables in this script. If it does not use separate memory (false) then the 'child' script will have access to all of the variables in the current script and hence variables must not clash. It is strongly recommended that you use namespaces to stop variable names from clashing. If omitted the script will use separate memory.
ReturnsNo return value |
ExampleTo run script /data/test/child.js using separate memory for the child script RunScript("/data/test/child.js");
|
SetCurrentDirectory(directory path[string]) [static]DescriptionSets the current working directory. |
Path to the directory you would like to change into.
Returnstrue if successful, false if not Return typeBoolean |
ExampleTo change into the directory "/data/test" exists SetCurrentDirectory("/data/test")
|
The program name string : Valid values are 'All', 'D3PLOT', 'PRIMER', 'REPORTER', 'SHELL',
'T/HIS'
The preference name string
The preference value string. If "value" is of zero length, then the option is simply removed from the file if present, and no new entry is made.This argument cannot be null.
If the saved preference should be refreshed. If omitted, the preference will NOT be refreshed. This argument is currently only available in PRIMER JS API and ignored in D3PLOT and T/HIS.
ReturnsAn integer. Returns 0 if the preference is saved succesfully or 1 if unsuccessful Return typeNumber |
ExampleTo save the preference value: var ierr = SetPreferenceValue( 'All', "font_size", 'Default');
|
Sleep(time[integer]) [static]DescriptionPause execution of the script for time seconds. See also MilliSleep() |
Number of seconds to pause for
ReturnsNo return value |
ExampleTo pause for 2 seconds Sleep(2);
|
System(string[Any valid javascript type]) [static]DescriptionDo a system command outside PRIMER. To run an external command and get the output then please use Execute() instead. |
The system command that you want to do
Returnsinteger (probably zero if command successful but is implementation-dependant) Return typeNumber |
ExampleTo make the directory "example" System("mkdir example");
|
Unix() [static]DescriptionTest whether script is running on a Unix/Linux operating system. See also Windows() |
No arguments
Returnstrue if Unix/Linux, false if not Return typeBoolean |
ExampleTo test if the OS is Unix if ( Unix() )
|
Use(filename[string]) [static]DescriptionUse script from a separate file |
Use allows you to include a script from a separate file. This may be useful if
your script is very large and you want to split it up to help with maintenance. Alternatively
you may have a 'library' of common functions which you always want to include in your scripts.
Including the 'library' with Use means that any changes only have to be done in one place.
PRIMER will look for the file in the same directory as the main script. If that fails then
it will look in $OA_INSTALL/primer_library/scripts directory and the script directory specified by
the primer*script_directory preference.
Note that the file is included when the script is compiled, NOT at runtime.
ReturnsNo return value |
ExampleTo include script from file library.js Use("library.js");
|
UuidCreate() [static]DescriptionCreate a UUID (Universally unique ID) |
No arguments
Returnsstring Return typeString |
ExampleTo create a UUID: var uuid = UuidCreate();
|
Visibility(type[string], state (optional)[boolean]) [static]DescriptionSet or get visibility of items in PRIMER |
The type of the item (for a list of types see Appendix I of the PRIMER manual). Additionally, to change the visibility of attached or unattached nodes you can use the types "ATTACHED_NODE" and "UNATTACHED_NODE".
If it is provided it is used to set the visibility. "true" to make items visible and "false" to make them not visible.
ReturnsBoolean Return typeBoolean |
ExampleTo make beams visible Visibility("BEAM", true);To get the visibility status of beams var vis = Visibility("BEAM");
|
WarningMessage(string[Any valid javascript type]) [static]DescriptionPrint a warning message to the dialogue box adding a carriage return. |
The string/item that you want to print
ReturnsNo return value |
ExampleTo print the title of model object m as a warning to the dialogue box WarningMessage("The title is " + m.title);
|
Windows() [static]DescriptionTest whether script is running on a Windows operating system. See also Unix() |
No arguments
Returnstrue if Windows, false if not Return typeBoolean |
ExampleTo test if the OS is Windows if ( Windows() )
|