Oasys.THIS functions¶
- AllocateFlag()¶
Allocate a flag for use in the script. See also
ReturnFlag()
and Once allocated the flag is automatically cleared for all entity types and all the curves currently in T/HIS
- Returns:
Flag (integer)
- Return type:
int
Example
To allocate a flag
flag = Oasys.THIS.AllocateFlag()
- ClearFlag(flag)¶
Clears a flag on all curves and entity types
- Parameters:
flag (Flag) – The flag to return
- Returns:
No return value
- Return type:
None
Example
To clear flag f:
Oasys.THIS.ClearFlag(f)
- DialogueInput(*command)¶
Execute one or more lines of command line dialogue input
- Parameters:
command (string) – 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
- Returns:
No return value
- Return type:
None
Example
To mulitply curves 1 and 2 by 10:
Oasys.THIS.DialogueInputNoEcho("/op mul #1 10 #", "/op mul #2 10 #")Note that each call to DialogueInput starts afresh at the top of the T/HIS command line “tree”, so where multiple commands need to be given at sub-menu levels they need to be included in a single call
- DialogueInputNoEcho(*command)¶
Execute one or more lines of command line dialogue input with no echo of commands to dialogue box
- Parameters:
command (string) – 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
- Returns:
No return value
- Return type:
None
Example
To mulitply curves 1 and 2 by 10:
Oasys.THIS.DialogueInputNoEcho("/op mul #1 10 #", "/op mul #2 10 #")As with DialogueInput above each call starts at the top of the T/HIS command tree structure, so any commands destined for sub-menus must all be arguments to a single call
- DisableGraphWindowUpdates()¶
Disable Graph Window updates
- Returns:
No return value
- Return type:
None
Example
Turn off graph window updates
Oasys.THIS.DisableGraphWindowUpdates()
- DisableMenuUpdates()¶
Disable menu system updates
- Returns:
No return value
- Return type:
None
Example
Disable menu system updates
Oasys.THIS.DisableMenuUpdates()
- EnableGraphWindowUpdates()¶
Enable Graph Window updates
- Returns:
No return value
- Return type:
None
Example
Turn off graph window updates
Oasys.THIS.EnableGraphWindowUpdates()
- EnableMenuUpdates()¶
Enable menu system updates
- Returns:
No return value
- Return type:
None
Example
Enable menu system updates
Oasys.THIS.EnableMenuUpdates()
- ErrorMessage(string)¶
Print an error message to the dialogue box adding a carriage return
- Parameters:
string (Any valid javascript type) – The string/item that you want to print
- Returns:
No return value
- Return type:
None
Example
To print the title of model object m as an error to the dialogue box
Oasys.THIS.ErrorMessage("The title is " + m.title)
- Execute(data)¶
Execute a program or script outside T/HIS and get the standard output and error streams
- Parameters:
data (dict) –
Execute data
- 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:
Dict with properties
- 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:
dict
Example
To run script “example.bat” with arguments “foo” and “bar”:
output = Oasys.PRIMER.Execute( { "program": 'example.bat', "arguments": [ 'foo', 'bar' ]} ) text = output["stdout"] errors = output["stderr"] ecode = output["status"]
- Exit(write_hook_interrupt=Oasys.gRPC.defaultArg)¶
Exit script
- Parameters:
write_hook_interrupt (boolean) – Optional. 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
- Return type:
None
Example
Exit with
Oasys.THIS.Exit()
- GetCurrentDirectory()¶
Get the current working directory
- Returns:
String containing current working directory
- Return type:
str
Example
To get the current directory:
cwd = Oasys.THIS.GetCurrentDirectory()
- GetFtcfVar(name)¶
Get the value of a FAST-TCF variable
- Parameters:
name (string) – The FAST-TCF variable name (case independent)
- Returns:
String containing variable value or None if variable does not exist
- Return type:
str
Example
To get the value for FAST-TCF variable Job
job_name = Oasys.THIS.GetFtcfVar("Job")
- GetInstallDirectory()¶
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 None if not found
- Returns:
string
- Return type:
str
Example
To get the install directory:
install_dir = Oasys.THIS.GetInstallDirectory()
- GetPreferenceValue(program, name)¶
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
- Parameters:
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 None 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:
str
Example
To get the preference value:
pref_list = Oasys.THIS.GetPreferenceValue('All', "font_size")
- GetStartInDirectory()¶
Get the directory passed to T/HIS by the -start_in command line argument
- Returns:
String containing start_in directory or None if not set
- Return type:
str
Example
To get the start_in directory:
start_in = Oasys.THIS.GetStartInDirectory()
- Getenv(name)¶
Get the value of an environment variable
- Parameters:
name (string) – The environment variable name
- Returns:
String containing variable value or None if variable does not exist
- Return type:
str
Example
To get the value for environment variable HOME
home = Oasys.THIS.Getenv("HOME")
- Message(string)¶
Print a message to the dialogue box adding a carriage return
- Parameters:
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
- Return type:
None
Example
To print the title of model object m as a message to the dialogue box
Oasys.THIS.Message("The title is " + m.title)
- MilliSleep(time)¶
Pause execution of the script for time milliseconds. See also
Sleep()
- Parameters:
time (integer) – Number of milliseconds to pause for
- Returns:
No return value
- Return type:
None
Example
To pause for 500 milliseconds
Oasys.THIS.MilliSleep(500)
- NumberToString(number, width, pref_int=Oasys.gRPC.defaultArg)¶
Formats a number to a string with the specified width
- Parameters:
number (integer/float) – 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 (boolean) – Optional. 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:
str
Example
To write the number 1.2345e+6 to a string 10 characters wide
str = Oasys.THIS.NumberToString(1.2345e+6, 10)
- OpenManual(program, page)¶
Open the Oasys manuals at a requested page
- Parameters:
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:
bool
Example
To open the T/HIS manual on the running-this.html page
Oasys.THIS.OpenManual("this", "running-this.html")
- Plot()¶
Updates all the T/HIS graphs
- Returns:
No return value
- Return type:
None
Example
Update all graphs
Oasys.THIS.Plot()
- Print(string)¶
Print a string to stdout. Note that a carriage return is not added
- Parameters:
string (Any valid javascript type) – The string/item that you want to print
- Returns:
No return value
- Return type:
None
Example
To print string “Hello, world!”
Oasys.THIS.Print("Hello, world!")To print the title of model object m with a carriage return
Oasys.THIS.print("The title is " + m.title + "\n")
- Println(string)¶
Print a string to stdout adding a carriage return
- Parameters:
string (Any valid javascript type) – The string/item that you want to print
- Returns:
No return value
- Return type:
None
Example
To print string “Hello, world!” automatically adding a carriage return
Oasys.THIS.Println("Hello, world!")To print the title of model object m, automatically adding a carriage return
Oasys.THIS.Println("The title is " + m.title)
- ReturnFlag(flag)¶
Return a flag used in the script. See also
AllocateFlag()
and
- Parameters:
flag (Flag) – The flag to return
- Returns:
No return value
- Return type:
None
Example
To return flag f:
Oasys.THIS.ReturnFlag(f)
- SetCurrentDirectory(directory_path)¶
Sets the current working directory
- Parameters:
directory_path (string) – Path to the directory you would like to change into
- Returns:
True if successful, False if not
- Return type:
bool
Example
To change into the directory “/data/test” exists
Oasys.THIS.SetCurrentDirectory("/data/test")
- SetFtcfVar(name)¶
Set the value of a FAST-TCF variable. If the variable already exists then it’s value is updated
- Parameters:
name (string) – The FAST-TCF variable name (case independent)
- Returns:
String containing variable value or None if variable does not exist
- Return type:
str
Example
To create a new FAST-TCF variable called run_number with the value “10”
home = Oasys.THIS.SetFtcfVar("run_number","10")
- Sleep(time)¶
Pause execution of the script for time seconds. See also
MilliSleep()
- Parameters:
time (integer) – Number of seconds to pause for
- Returns:
No return value
- Return type:
None
Example
To pause for 2 seconds
Oasys.THIS.Sleep(2)
- System(string)¶
Do a system command outside T/HIS. To run an external command and get the output then please use
Execute()
instead
- Parameters:
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:
int
Example
To make the directory “example”
Oasys.THIS.System("mkdir example")
- Unix()¶
Test whether script is running on a Unix/Linux operating system. See also
Windows()
- Returns:
True if Unix/Linux, False if not
- Return type:
bool
Example
To test if the OS is Unix
if ( Oasys.T/HIS.Unix() )
- UpdateCurveMenu()¶
Updates the scroll bar in the Curve Manager. Useful if your script has created lots of new curves and you want to update the menu (otherwise, the scroll bar range will only be updated when the script exits)
- Returns:
No return value
- Return type:
None
Example
Update curve slider
Oasys.THIS.UpdateCurveMenu()
- WarningMessage(string)¶
Print a warning message to the dialogue box adding a carriage return
- Parameters:
string (Any valid javascript type) – The string/item that you want to print
- Returns:
No return value
- Return type:
None
Example
To print the title of model object m as a warning to the dialogue box
Oasys.THIS.WarningMessage("The title is " + m.title)