0% found this document useful (0 votes)
2K views

META Automation Users Guide

ELEMENTOS FINITOS

Uploaded by

June Tolp
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

META Automation Users Guide

ELEMENTOS FINITOS

Uploaded by

June Tolp
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 245

META Automation

User’s Guide
META Post Processor Automation User’s Guide

Updated in PDF form for version 18.0.1, October 2017


COPYRIGHT © 1990-2017 BETA CAE Systems
ALL RIGHTS RESERVED.

The META Automation User's Guide is an integral part of the META software.
This User's Guide, in whole or in part, may not be copied, reproduced, translated, transferred, or
reduced to any form, including electronic medium or machine-readable form, or transmitted or
publicly performed by any means, electronic or otherwise, unless BETA CAE Systems consents in
writing in advance.
Use of the software and its documentation has been provided under a software license agreement.
BETA CAE Systems assumes no responsibility or liability for any damages or data loss caused by
installation or use of the software.
Information described in this documentation is furnished for information only, is subject to change
without notice, and should not be construed as a commitment by BETA CAE Systems. BETA CAE
Systems assumes no responsibility or liability for any errors or inaccuracies that may appear in this
manual.
The software and its documentation contain valuable trade secrets and proprietary information and
are protected by copyright laws. Unauthorized use of the software or its documentation can result in
civil damages and criminal prosecution.
All other company and product names, mentioned in the software and its documentation, are
property, trademarks or registered trademarks of their respective owners.
This User's Guide serves as a reference of the automation abilities and interface of META,
presenting an outline of used functions for viewing results with META.
If you have any questions about this User‟s Guide, or would like to contribute by reporting errors or
omissions you have found in it, please contact BETA CAE Systems at: [email protected].

BETA CAE Systems International AG


D4 Business Village Luzern
Platz 4, CH-6039 Root D4
Switzerland
http://www.beta-cae.com
Queries & Services: [email protected]
1. Introduction

1. Introduction
META offers a variety of tools and functions for automating the post-processing. The most
important of them are:
- Variables
- Built-in Functions
- Session files
- Scripting language
- User Toolbars
Variables store static, dynamic or string values. They are used to communicate these data between
different tools but they can also be used in commands, in sessions and in scripting language. For
more information check APPENDIX VARIABLES
Built-in Functions are expressions which can return different types of values like field or curve data
for specified entities, results or states. The Built-in Functions can be used to fill variables, as
arguments in the Adv. Filter and in scripting language. For more information check APPENDIX
Build in functions.
Session files are text files containing a series of META commands. When executed, each
command is applied sequentially. For more information check Session Files chapter.
Scripting is C-like programming language which can be used for advanced automation procedures.
Scripts can run as standalone files or used inside session files and user toolbars. Through scripts it
is easier to create and handle conditional statements, store in the memory tabular data and apply
complex procedures. It is also possible to create custom windows. For more information check
Scipting chapter
User Toolbars are custom toolbars designed to hold custom functionality. They can contain widgets
like buttons, textboxes, checkboxes etc. Commands, whole sessions or scripts can be assigned
and applied when each widget is used. For more information check Toolbar Designer

BETA CAE Systems 1 META Automation User’s Guide


2. Session Files
Table of Contents

2.1. Introduction ................................................................................................................................ 3


2.2. Syntax ........................................................................................................................................ 4
2.2.1. General .............................................................................................................................. 4
2.2.1. Conditional statements ....................................................................................................... 6
2.3. Settings ...................................................................................................................................... 7
2.4. The options session command .................................................................................................. 7
2.5. Session Editor ............................................................................................................................ 8
2.5.1. Interface ............................................................................................................................. 8
2.5.2. Main menu ......................................................................................................................... 9
2.5.3. Toolbar buttons ................................................................................................................ 12
2.5.4. Editor................................................................................................................................ 14
2.5.5. View options ..................................................................................................................... 16
2.5.6. Commands description .................................................................................................... 18
2.5.7. Set Parameters ................................................................................................................ 19
2.5.8. Create package ................................................................................................................ 22
2.5.9. Create User Toolbar......................................................................................................... 24
2.5.10. Snippets ......................................................................................................................... 25
2.6. How to (Session Editor) ........................................................................................................... 26
2.6.1. Run sessions using keyboard shortcuts ........................................................................... 26
2.6.2. Debug a session .............................................................................................................. 27
2.6.3. Ask for user input when loading files ................................................................................ 28
2.6.4. Parameterize a session that creates annotation from Adv.Filter ...................................... 29
2.6.5. Avoid common mistakes when creating sessions ............................................................ 29
2.6.6. Create a toolbar from a session / a part of session .......................................................... 30
2. Session Files

2.1. Introduction

Session files (or Sessions) are text files containing a series of META commands. When executed,
each command is applied sequentially.
An example of a session file follows:

$ Session File written by META_post version:6.8.2


window size 1488,1030
read geom Fluent /home/beta.cas
0:read appendfun Fluent /home/beta.dat all Pressure
0: options state 1
view default isometric
annotation add onnodes pick "id=\$id, val=\$val"
mouse 1 0.504032 0.609709 0
mouse 1 0.504032 0.609709 0
option enter

Sessions can be created:


- Automatically in the META_post.ses file. While META runs, all commands executed from the
GUI or the Command Line are stored in this file located in the current directory (the directory from
where the software is called). Additionally if any script runs during this period, it is added too in the
file.
- Through the File > Save Session option of the Main Toolbar. This actually saves the contents of
the META_post.ses file in a custom file.
- Through the Session Editor.

A session file can be executed through:


- The Session option of the META Launcher.
- The -s <filename> running option.
- The File > Open Session/Script menu of the Main Toolbar.
- The Session Editor.
- User toolbars by calling the read session command.
- Keyboard shortcuts.

Sessions can be edited and parameterized in the Session Editor.

BETA CAE Systems 3 META Automation User’s Guide


2. Session Files

2.2. Syntax

2.2.1. General
Lines Each line must contain one META command.

Comments A line can be commented out by adding the # or $ characters in the beginning.

Variables Variables can be used in the place of names, values or parameters by adding
the $ character in front of the variable name. For example:
options state $full_load
If necessary, the variable name must be added inside the { and } characters
to declare when the variable‟s name ends. For example:
write png ${model_name}_top_view.png

Arguments Argument parameters can be used in session files when executing a session
with the -s running option.
They are denoted within the session with the $ character followed by an
integer.
For example:
When executing a session with the system command:
meta_post64.sh –s reforces.ses file.op2 Rotational
and the session contains the line:
read fun Nastran /home/user/$0 all SPCForces, $1
The $0 will be replaced by file.op2 and the $1 by Rotational
Remarks
Counting arguments starts from 0.
Arguments must be separated with space.
If the string of an argument contains a space character, then it is mandatory to
enclose is in double quotes “”.

Script It is possible to include a script within a session by adding it between the


keywords #!script and #!EOF.

Disable redraw Add the ! character in front of a line to disable screen redraw when executing
the command. This results to faster execution time.
Remarks
To disable redraw during all session or for more lines, use the commands:
options session controldraw disable
options session controldraw enable

BETA CAE Systems 4 META Automation User’s Guide


2. Session Files

Relative Paths Paths written in a session can be relative. A relative path has the
following syntax:
-Folder1
-Folder1_1 ./FolderIn_1/file.extension
-Folder1_2 ../FolderOut_1/file.extension, ../../Folder1/file.extension
- FolderOut Relative paths in a session indicate to the current directory.
-Current_Directory
As current directory is considered:
-FolderIn_1
-FolderIn_2 - The session‟s directory
-FolderOut_1 - The META_CUR_DIR, the directory form where META is launched
-FolderOut_2 In case the file is not found in the session‟s directory, META search in
the META_CUR_DIR.

BETA CAE Systems 5 META Automation User’s Guide


2. Session Files

2.2.1. Conditional statements


The following conditional statements are supported:

#if $<variable name><condition><value>


#else
#elseif $<variable name><condition><value>
#endif
#:<label>
#goto <label>
Remarks
- In if expressions META does not support logical expressions with string variables

Example 1
A dialog opens asking to enter the value 1 or 2 representing the top or bottom view respectively.
The session checks the input and applies the respective view or posts a warning if the input is not
correct. In this case the dialog opens again.
#:start
options var valuelbltext value Give_View_(1=TOP, 2=BOTTOM)
options var view “$value”
#if $view==1
view default top
#goto end
#elseif $view==2
view default bottom
#goto end
#endif
options var view 0
options warning value should be 1 or 2
#goto start
#:end

Example 2
Multiple snapshots of the model are stored into the current directory. The session waits for manual
change of view. When the Enter button is pressed, a picture is saved. A dialog opens asking for
numerical input 1 or 0 representing the option Yes or No. Depending on the input, more pictures
can be taken:
options var root ${META_CUR_DIR}
options message Your snapshot will be stored in $root directory
options var file_name 1
#:start
options session wait select your snapshot view and press ENTER
write tif "$root/$file_name.tif" 0
options var valuelbltext cont Continue with Snapshots (Y-1/N-0)?
#if $cont==1
options var file_name "$file_name+1"
#goto start
#endif

BETA CAE Systems 6 META Automation User’s Guide


2. Session Files

2.3. Settings

The following settings can be found in Global Settings > General of the Settings card.

Pause execution on error The session pauses when a command is not executed correctly.
User action is needed to continue execution.

Session decoding unicode Decode ASCII files as Unicode; otherwise the file is decoded
according to the local settings.
Note that the language environmental variable should also be set,
e.g.: setenv LANG POSIX

2.4. The options session command

Through the options session... command it is possible to set the behavior of a session while
running. The most useful commands are:

options session controldraw disable Disable/Enable redraw during executions of


options session controldraw enable commands.
Remarks
To disable redraw for one command only, add
the ! character in front of the line.

options session controldraw push Save the current status of the controldraw
command.

options session controldraw pop Returns to the saved status of the controldraw
command.

options session forcedraw Force a redraw. A redraw is applied even when


controldraw is disabled.

options session pause Session‟s execution paused. Execution of the


session is continued by typing the command
options session continue in the
command editor.

options session continue Session‟s execution will be continued when the


options session pause command has
been applied.

options session sleep <ms value> Session‟s execution stops for a period of
milliseconds, equal to the value which is set.

options session wait <message> Session‟s execution stops presenting the


message in META info window. Execution
continues pressesing the ENTER key.

BETA CAE Systems 7 META Automation User’s Guide


2. Session Files

2.5. Session Editor

2.5.1. Interface
The Session Editor is a complete tool to create, open, edit, run and debug sessions.
The Session Editor window can be invoked through:
Tools > Session Editor from the Main Toolbar.

Main menu Toolbars

Editor

Set Parameters window


Output window

Main menu Contains functions distributed under the File, Edit, Project, Tools, Script,
Windows and View drop down menus.

Toolbars Contains buttons distributed under the Files Options, Edit Options, Project and
Tools toolbars.

Editor This is the text area where the session is written or tested. Every open session
file is located under a separate tab. The asterisk next of the session name on
tab label declares an unsaved session.

Output window Displays information (statistics, errors and warnings) of the session.

Set Parameters Contains functions for handling the parameters and also for creating variables.
window

Remarks
- All the windows inside the Meta Session Editor are totally customizable as all the other windows in
META. They can be moved, resized and docked.

BETA CAE Systems 8 META Automation User’s Guide


2. Session Files

2.5.2. Main menu


The main menu contains the following functions:

File

New An empty, named Untitled.ses, session file is created. A new


tab in the main window area is added.

Open The file manager opens to browse a session file (i.e. *.ses). A new
tab, having the name of the session, is added in the main window.
There is no restriction regarding how many sessions can be
remained opened simultaneously.

Open Current Session Open the current session from the META_post.ses file.

Open Recent File Open recently edited session files.

Reload session Reload session from file.

Run Compressed Package Load and run a compressed package. A package is a group of files
in a folder that contains all the necessary files in order to run a
session (see 2.5.8. Create package, pg.22).

Save, Save As, Save All, Save session files.


Selected lines

Print Open the Print dialog and print the session.

Exit Exit the Session Editor.

Edit Text options (Cut, Copy, Paste, Replace, etc)

Project

Run Run the current session file without stopping at breakpoints.


To stop the execution of the session at any time, press the Esc or
the Pause Break key.

Run Selected Lines Run only the selected session lines.

Record Recording and type automatically the applied META commands.


Recorded commands can be written in a new session file or added
in the current session file. All the applied commands are real time
passed in the session file. In order to stop recording the Record
button or the F4 key should be pressed.

Insert Breakpoint Insert a breakpoint at current line. Breakpoints can be used to stop
execution of session while debugging.

Clear Breakpoints Clear all inserted breakpoints

Debug Run and pause the session execution when a breakpoint is met.
Press the Enter key to continue execution line by line.

BETA CAE Systems 9 META Automation User’s Guide


2. Session Files

Go to Next Breakpoint When session is paused in a breakpoint, continue execution until


the next breakpoint is met.

Tools

Check Session For Errors Searches the session file and displays in the Output window warning
and error messages for anything found not according to the rules of a
session file.
By double clicking on a message the corresponding line in the
session will be highlighted in the session. Pressing Ctrl+> or Ctr+<
keys the cursor will navigate to the next or previous position of the
session referred to by an error or warning.

Create User Toolbar Automatically create a User Toolbar from all or selected lines (see
2.5.9. Create User Toolbar,pg.24).

Environment Variables A list with all Environment Variables is displayed.


Double click one a variable to add it in the session text. The variable
is added having a “$” as a prefix and the variables name enclosed in
brackets { }.

Snippets Open the Snippets tool. Snippets are parts of code that can be saved
for use on other parts of the same or of a different script or session
(see 2.5.10. Snippets, pg.25).

Create Package Open the Create Package window. A package is a group of files in a
folder that contains all the necessary files in order to run a session
(see 2.5.8. Create package, pg.22).

Suppress Redundant Keep only the last command when a series of the same commands
Commands are applied. The function is applied only on commands which when
removed, the final state will not be altered.
When a session is recorded from it might contain many unnecessary
commands making it hard to use or edit and slowing down its
execution.
An example is a series of commands that change the view of the FE
model, only the last one is necessary.

Encrypt Session Save the currently session in encrypted/binary format.


Remarks
Encrypted sessions can be executed but not edited.
It is possible to encrypt a session with a password using the
command:
encrypt <source file name> <password> <destination file name>
A session encrypted through this way could also encrypted by using
the command:
decrypt <source file name> <password> <destination file name>
Session files encrypted with a password must be decrypted before
execution, else they cannot be executed.

BETA CAE Systems 10 META Automation User’s Guide


2. Session Files

Command Description Get information about the syntax of the command of the selected
line and also suggestions about correction of a syntax fault.

Insert / Remove Comment Comment or uncomment selected lines.

Script

Write Script Add in the session text the required keywords that enable the
insertion of Python / BETA scripting language within the session,
e.g.:
#!script
#include "meta_structs"
def main()
{
//type your code here
}
#!EOF
(see 4. Scripting, pg.65).

Remove Redundant Redundant script code lines are removed.

Smart Check Lines inside session that seems to be BETA scripting code lines are
identified. The indicator #!script line can be added before a
script starts.

Windows Show or hide the Set Parameters and Output windows.

View

Zoom In / Out Zoom the text in and out.

Options Invoke the options card to set up the General Options and Colors.

BETA CAE Systems 11 META Automation User’s Guide


2. Session Files

2.5.3. Toolbar buttons


All toolbars contain buttons as shortcuts for the most used functions found under the Main Menu.

An empty, named Untitled.ses, session file is created. A new tab in the main
window area is added.

The file manager opens to browse a session file (i.e. *.ses). A new tab, having
the name of the session, is added in the main window. There is no restriction
regarding how many sessions can be remained opened simultaneously.

Open the current session from the META_post.ses file.

Save active / Save as / Save all sessions.

Open the Print dialog and print the session.

Undo and redo editing actions in the current edited session.

Functions Cut, Copy and Paste can be applied in session text within and between
windows.

The Find window opens, to search a desired text in the session. Searching
parameters can also be defined.

Run the current session file without stopping at breakpoints.


To stop the execution of the session at any time, press the Esc or the Pause
Break key.

Run only the selected session lines.

Recording and type automatically the applied META commands.


Recorded commands can be written in a new session file or added in the current
session file. All the applied commands are real time passed in the session file. In
order to stop recording the Record button or the F4 key should be pressed.

Insert a breakpoint at current line. Breakpoints can be used to stop execution of


session while debugging.

Clear all inserted breakpoints

Run and pause the session execution when a breakpoint is met.


Press the Enter key to continue execution line by line.

When session is paused in a breakpoint, continue execution until the next


breakpoint is met.

BETA CAE Systems 12 META Automation User’s Guide


2. Session Files

Searches the session file and displays in the Output window warning and error
messages for anything found not according to the rules of a session file.
By double clicking on a message the corresponding line in the session will be
highlighted in the session. Pressing Ctrl+> or Ctr+< keys the cursor will navigate to
the next or previous position of the session referred to by an error or warning.

Automatically create a User Toolbar from all or selected lines (see 2.5.9. Create
User Toolbar, pg.24).

A list with all Environment Variables is displayed.


Double click one a variable to add it in the session text. The variable is added
having a “$” as a prefix and the variables name enclosed in brackets { }.

Add in the session text the required keywords that enable the insertion of Python /
BETA scripting language within the session, e.g.:
#!script
#include "meta_structs"
def main()
{
//type your code here
}
#!EOF
(see 4. Scripting, pg.65).

Redundant script code lines are removed.

Lines inside session that seems to be BETA scripting code lines are identified. The
indicator #!Script line can be added before a script starts.

BETA CAE Systems 13 META Automation User’s Guide


2. Session Files

2.5.4. Editor
The Editor is a specialized text editor where all open session are listed in separate tabs.

Tabs Each session is placed under a different tab. All functions are applied to the
active tab.
If a session file being edited has not been saved, its name on the corresponding
tab will be marked with an asterisk.
Single click on a tab to activate it.
Use the arrows on the right to scroll between tabs.

Lines All lines are numbered. The number of lines which contain breakpoints are
highlighted.

Text Each line contains a command and its parameters.


The text is colored according to the type of the word (see 2.5.5. View options,
pg.16).

BETA CAE Systems 14 META Automation User’s Guide


2. Session Files

Controls

Tab key Auto complete functionality.


A list with all possible commands opens. Select the required
command and press the tab key again to add it in the text.

Single click on row’s number Add a breakpoint.

Double click on text Select word and create a breakpoint.

Right click Open the context menu which contains text editing functions.

BETA CAE Systems 15 META Automation User’s Guide


2. Session Files

2.5.5. View options


The Options card is opened from the View > Options of the Main Menu.

General Options

Gui settings Set the GUI‟s font.

Editor settings Set the editors font.

Parameter Name Set created parameters will be named automatically or if a custom


name will be asked in a dialog box.

Open File Open new files in new or the current tab of the editor.

Recent Files Set the number of recent files to be kept in File > Open Recent File
menu.

Autosave Enable to automatically save open session files.


Set the saving intervals in Save every (in min) option.

BETA CAE Systems 16 META Automation User’s Guide


2. Session Files

Colors

Fonts Colors When writing a session text is colored differently, according to certain
rules.
Change the color by pressing on the respective button.

Normal Plain text.

Filename Filenames including the directory.

Value Command‟s arguments where values are entered.

Comment Comments are lines that start with the $ or # characters. Comments do
not affect the session.

Parameter Name Parameters, like variables.

Parameter Value Values of parameters

Script Indication The keywords #!script and #!EOF

if – goto – labels All condition statements.

Linecount Text The color of the numbers showing the line‟s row.

BETA CAE Systems 17 META Automation User’s Guide


2. Session Files

Background Colors

Text The background color of the editor.

Linecount The background color of the line numbers

Current Statement When running the session in debugging mode, the current line is
highlighted.

Breakpoint If a breakpoint exists in a line, its background color.

Ouput Background color of the Output window.

2.5.6. Commands description


A quick overview of the current session line command is available through Tools > Command
Description.

Command in Line Change the referenced line number to view the description for
another line.

Command Type another command, even if it is not present in the session file
and press the Enter key to view its description.

Argument Each argument of the command is listed separately.

Description View description, help and suggestions for the command and its
arguments.
In case there is a fault, it is noted with a respective message.

BETA CAE Systems 18 META Automation User’s Guide


2. Session Files

2.5.7. Set Parameters


In Set Parameters card a series of functions are available to easily handle and parameterize any
values, variables, files and directories within a session file.

List Anything that can be parameterized can be listed. The contents of the
list depend on the function selected on the right side of the tool.
Any actions are applied only to checked entities.
Hits: Shows how many times an entity is present in the session. Each
entity is listed only once even if it has more than one hit.
Expand the tree to see the line and the command where the entity is
used.

Filenames List all filenames found in the session including their path.

Directories List all directories found in the session.

Values List all values found in the session. Values can be numbers but also
ranges, type of results, names or advanced filter arguments.

Env. Variables List any environmental variables present in the session.

Clear Empty the list.

Uncheck All Uncheck all entities from the list.

Custom Name When enabled, a name will be asked when creating new parameters.
Else, they will be named automatically.

BETA CAE Systems 19 META Automation User’s Guide


2. Session Files

Static Parameter Each selected filename, directory or value will be replaced by a variable and
the respective command that creates this variable will be added in the top of
the session. This way it is easy to control any parameters without having to
search for them in large session files.
For example the line:
options state 4
will become:
options state ${p0}
and the following line will be added in the top of the session:
opt var add p0 4

Dynamic Parameter Replace selected filenames, directories or values by a variable to be created


when running the session. The difference between the static and dynamic
parameter is that the value of the latter is defined by the user when running
the session.
For this reason for each selected parameter a dialog opens asking to set the
type of the variable to be created. Depending on the selection the respective
command is written on the top of the session.

For example, when creating a dynamic parameter from a filename:

The line:
read dist Nastran /home/user/file.op2 all Displacements
will become:
read dis Nastran ${p0} all Displacements
and the following line will be added in the top of the session:
opt var filetext p0
All commands created by this function are openening dialogs where the user
enters or pick the required value, file or entity.

Change Replace the value of the selected parameters.

Parameters List all parameters set by the tool or any variables to be created with this
session. At the same time a new set of functions become available:

BETA CAE Systems 20 META Automation User’s Guide


2. Session Files

Static to Dynamic Convert selected static parameters to dynamic. As for the Dynamic
Parameter function, a dialog comes up for each selected parameter in order
to select its type.

Dynamic to Static Convert dynamic parameter to static. A dialog comes up asking to enter the
value of the parameter.

Delete Parameter Delete selected parameters. If a parameter is dynamic, the value must be
entered.

Merge Parameters Merge two or more parameters to a new one with name, type
(static/dynamic) and value (in case of a static parameter).
Add a description.

BETA CAE Systems 21 META Automation User’s Guide


2. Session Files

View Description Review and edit the parameter‟s description.


Remarks
- Once a description is added, it appears in the session main text area as a
comment before the definition of the parameter. The description can be
changed by double clicking with the Left Mouse button either in the
Parameter’s Description window or over the Description column of Set
Parameters window. It can also be changed by directly editing the
comment in the session main text area.

Change Value Change the value of static parameters

Change Type Change the type of dynamic parameters

Rename Rename selected parameters

Search for, Find Search and create parameter from any text.

2.5.8. Create package


A package is a group of files in a folder that contains all the necessary files in order to run the
session. This way the session can be executed in a distant place, where the referent files are not
available, having only the package.
By pressing Tools > Create Package the Create Package window, which is depicted below, opens.

Create

BETA CAE Systems 22 META Automation User’s Guide


2. Session Files

Folder The session file and any files referred in the session will be copied to the
target folder.

Compressed File Create a compressed file which will contain all the needed files and the
session

Both Create a folder and a compressed file.

Target Folder Set where the session file and the files will be created.

Compressed File Set the path and name of the compressed file.

Password Protected Protect the file with a password. A dialog will ask for the password when
pressing the OK button.

Compression Level Set the compression level for the compressed file.

OK Create the package. Only files checked in the list will be included. All
paths within the session will change from absolute to relative.

Preview See how the contents of the new folder or compressed file will be
structured.

Files list

The initial locations of all files that are referred in the session as well as the path of the session are
listed.

Control which files are going to be included in the created package by checking the corresponding
check box ahead of each file.

To review the dependencies between the files, select the Show Dependencies option from the
context menu.

BETA CAE Systems 23 META Automation User’s Guide


2. Session Files

2.5.9. Create User Toolbar


It is possible to automatically
create a User Toolbar through the
option Tools > Create User
Toolbar. The dialog on the left
appears.

Save as session Save the selected lines in a session file. The user toolbar will execute the
commands from this file.

Add directly All commands will be added directly to the User Toolbar.

In case that static parameters are present within


the selected lines, there is the possibility to
automatically add in the toolbar related
textboxes.
Press on the Yes button to configure:

Textbox A textbox will be created for each selected parameter.

File Textbox A file textbox will be created for each selected parameter.

Directory Textbox A directory textbox will be created for each selected parameter.

Add all parameters as Enable the respective textbox to create the corresponding type of textbox
... for each parameter.

Once the toolbar has been created it will be listed under the Toolbars drop down menu. The user
can save, edit and delete the created toolbar through the Toolbars > Toolbar Designer (see 3.
Toolbar Designer, pg.32).

BETA CAE Systems 24 META Automation User’s Guide


2. Session Files

2.5.10. Snippets
Snippets are parts of code that can be saved for use on other parts of the same or of a different
script or session.
Invoke the Snippets tool from Tools > Snippets.

A text editor similar with the Session Editor’s text is available.

Create a new snippet.

Snippet name Enter a name for the selected snippet. Use the Save button to store the name.

Snippet list All available snippets are listed.

Delete selected snippet.

Save selected snippet. Snippets are stored in the snippets.xml file created in
the current directory (where META is called from).

Export current snippet to the Session’s Editor’s current tab. The snippet is
inserted at the current cursor position.

Execute snippet‟s commands.

Record commands from META.

BETA CAE Systems 25 META Automation User’s Guide


2. Session Files

2.6. How to (Session Editor)

2.6.1. Run sessions using keyboard shortcuts


A session file can be run through shortcut keys by pressing the Ctrl+Shift+<key> keys combination.
The following conditions must be applied:

The session‟s filename should be a single character that corresponds to keyboard‟s key.

The session must be present in one of the following directories:


1. Current working directory: This is where the program is called from.
2. The Project Directory. This is the directory defined either with the -d running option or by setting
the POST_DIR environment variable.
3. The directory ./BETA/META. This is under HOME directory.
4. The home directory of the user (HOME).
5. The Group directory. This is the directory defined either with the -groupdir running option or
by setting the META_GROUP_DIR environment variable.
6. The default directory. This is the $META_POST_HOME/config directory.

For example a session saved as h.ses in the current directory will run by pressing the Ctrl+Shift+H
keys.

BETA CAE Systems 26 META Automation User’s Guide


2. Session Files

2.6.2. Debug a session


As a first step, it is recommended to check for errors or warning before running a session. To do so:

4 1

3
2

1. Press the F7 key or press on the Check 3. Click on the number of the required line.
Session File For Errors button. The respective line number is highlighted.
2. Warnings or errors appear in the Output 4. Press the Shift+F5 button or press on the
window. Double click on each warning or Debug Current Session File button.
error to go to the respective line and correct
the errors manually. 5. The session runs but pauses just before the
breakpoint. The command to be executed
Even if no errors or warning appear, it is is highlighted.
still possible that the session does not
produce the required result. In this case, it 6. Continue running the session line by line by
pressing the Enter key or the middle mouse
is recommended to insert a breakpoint in a
line up to which the session runs as button to check the result of every executed
expected and then run the session line by command until the error is located.
line. To do so: 7. Exit debugging mode press the Esc button.

BETA CAE Systems 27 META Automation User’s Guide


2. Session Files

2.6.3. Ask for user input when loading files


It is possible to replace filenames with commands which open the File Manager and ask for
interactive selection of a file when the session runs.
Assuming that in a session file the following line is present:
read geometry Nastran /home/user/model.nas

1. Press on the Filenames


button in the Set
Parameters window.
1
All files including their
path are listed.

2 2. Check the box in front of


the file.

3. Press on the Dynamic


Parameter button.

4. Select Filename as and


press on the OK button.

4
The line will change to:
read geometry Nastran $p0
At the top of the session the following line will be written:
opt var filetext p0
When the session will be executed, the File Manager will come up.

BETA CAE Systems 28 META Automation User’s Guide


2. Session Files

2.6.4. Parameterize a session that creates annotation from Adv.Filter


If a session recorded from META creates annotations using the Advanced Filter and then
commands exist that they refer to these annotations they need to be modified.
This is necessary because the Advanced Filter may return a different number of annotations if used
in another model.
For example, the following lines create by Adv. Filteri 4 annotations. Then the precision of the text
is changed.
annotation add onnode advfilter active add:Nodes:tnodedisp:>0.27:Keep All
annotation text 1-4 precision 2
To make sure that the last command will work no matter how many annotations are going to be
created, the annotations ids range needs to be replaced with the variable
$ADV_FILTER_ANN_IDS.
annotation text $ADV_FILTER_ANN_IDS precision 2
This variable is created automatically every time annotations are created by the Advanced Filter.

2.6.5. Avoid common mistakes when creating sessions


- Avoid using in commands the pick option. Use ids, names or the Advanced Filter instead to have
a better control of the session.
- When special characters are used on an external editor make sure that they are correctly read.
Else you may need to enable the Session Decoding Unicode in General Settings.
- If any path or filename contain the space character include it in double quotes.
- Take in account that not all workstations have the same screen size. Always set the windows or
image size before exporting images.

BETA CAE Systems 29 META Automation User’s Guide


2. Session Files

2.6.6. Create a toolbar from a session / a part of session


It is possible to create a toolbar that will execute a session file or a part of a session from within the
session editor.

1. Open or create the session that is to be used with the toolbar. All filenames / values that should be
input through toolbar entities (textboxes, filetextboxes, etc.) need to be parameterized first and
exist as static parameters in the session. Select some lines of the session or do not select anything
so that all session is used.
2. Press the Create User Toolbar button.
3. In the dialog box Press Yes to add static parameters as textboxes.

4. Select the filename


parameters and press File
Textbox to create toolbar file
textboxes for these
parameters.

BETA CAE Systems 30 META Automation User’s Guide


2. Session Files

5. If Save as session is
selected, the session/part of
session will be saved as a
session file and this session
file will be executed from the
toolbar. If Add directly is
selected, the session/part of
session will be saved
directly as commands inside
the toolbar.

BETA CAE Systems 31 META Automation User’s Guide


3. Toolbar Designer
Table of Contents

3.1. General .................................................................................................................................... 33


3.2. Interface ................................................................................................................................... 33
3.2. Context menu, create new items, save and delete selected items .......................................... 36
3.3. Item Properties ........................................................................................................................ 37
3.3.1. Introduction ...................................................................................................................... 37
3.3.2. Toolbar properties ............................................................................................................ 37
3.3.3. Group properties .............................................................................................................. 38
3.3.4. Menu properties ............................................................................................................... 38
3.3.5. Tab properties .................................................................................................................. 39
3.3.6. Button properties .............................................................................................................. 39
3.3.7. Toggle button properties .................................................................................................. 40
3.3.8. Checkbox properties ........................................................................................................ 41
3.3.9. Radio button properties .................................................................................................... 42
3.3.10. Slider properties ............................................................................................................. 43
3.3.11. Textbox properties ......................................................................................................... 44
3.3.12. Filetextbox properties ..................................................................................................... 45
3.3.13. Directory textbox properties ........................................................................................... 47
3.4. Editing the commands list - Property editor ............................................................................. 48
3.5. How to (Toolbar Designer) ....................................................................................................... 51
3.5.1. Create a toolbar ............................................................................................................... 51
3.5.2. Define a radio button ........................................................................................................ 52
3.5.3. Define a checkbox............................................................................................................ 53
3.5.4. Define a textbox and assign its functionality by recording actions ................................... 54
3.5.5. Add textbox arguments .................................................................................................... 56
3.5.6. Add history ....................................................................................................................... 58
3.5.7. Add file textbox with wildcards ......................................................................................... 59
3.6. Summary Table of the keywords used within toolbars ............................................................. 61
3. Toolbar Designer

3.1. General

Unlimited number of toolbars can be created in META. These toolbars hold buttons that have one
or more commands assigned to them. All created user toolbars are held under the Toolbars drop-
down menu of META general interface. Some toolbars may also be selected to be shown in the
context menu of a 3d Window. The toolbars can be defined either directly in META through the
Toolbar Designer tool or inside the META_post.defaults file using a text editor.

3.2. Interface

This tool is used for the interactive creation / modification of toolbars. It is invoked from the Toolbars
pull-down menu: Toolbars>Toolbar Designer.
The first time this tool is opened, it appears as a list of all currently available toolbars in META.
These are the toolbars that META has read from the various META_post.defaults file upon
launching. This list appears as it is shown in the picture below:

The toolbars are listed in a tree form. As soon as an item from the list is selected, a different section
appears in the right side of the list. Toolbars that have been edited but not saved in the defaults file
are highlighted in orange. The following picture provides an overview of the interface.

BETA CAE Systems 33 META Automation User’s Guide


3. Toolbar Designer

In the interface the following can be found:

Property Viewer A list with all available toolbars in a tree form. The list contains the following
columns:
- Item: Names of the different items are enlisted. As Items are regarded all
buttons, checkboxes, textboxes, etc. of a toolbar and the toolbar itself
- Type: The type of each item is enlisted.
- Source Defaults File (only for Toolbar Items):It contains the default file a
toolbar has been read from
- Target Defaults File (only for Toolbar Items): It contains the file-path, where
the toolbar will be saved. The Target Defaults File comprises one of the
properties of a toolbar and can be modified. Moreover, the Target defaults File
can be any of the *.defaults files that META has read upon launching.

Propeties The section on the right side includes the properties that have been specified
for the selected item. These properties and consequently the layout of this
section depend upon the Type of the selected Item. The most commonly met
fields on the top part of this section are:

BETA CAE Systems 34 META Automation User’s Guide


3. Toolbar Designer

- Name
- Label
- info-tip
- Image
- Color of:
- Text
- Background
- Orientation
- Horizontal
- Vertical

The bottom part of the Properties section includes the commands that have
been assigned to the selected item (obviously all commands are not available
for all Types of items). These commands cannot be edited directly, but in the
Property editor tab which can be accessed either by pressing the Edit
commands list button or by selecting the tab itself. All items respond to one, two
or zero Command fields (see 3.3. Item Properties, pg.37).

Create New Create a new toolbar in the list


Toolbar

Load Load toolbars that have been saved in any ASCII file. This file does not have to
be one of the META_post.defaults file that META reads upon launching.

Save to Defaults Save all new and modified toolbars to their Target default files. META provides
a warning about the actions that should be performed upon saving, where
Target default files may be updated or even the whole process may be
canceled.
New or modified toolbars that have not saved in the defaults file are marked
orange in the list.

Reload from Reload all toolbars from the available META_post.defaults files. In this case
Defaults only the information related to toolbars is reloaded, not all information existing
in the META_post.defaults. Therefore, it is not the same as applying the
command:
options rereaddefaults

Move selected items up and down in the list within the same tree-structure level

BETA CAE Systems 35 META Automation User’s Guide


3. Toolbar Designer

3.2. Context menu, create new items, save and delete selected items

By pressing the Right Mouse button on an


item in the list, a context menu appears with
all available options. Note that the available
options depend upon the Type of the item that
is selected.
The options are decreased regarding the
depth of the expansion in the tree structure.
However there are extra options that are
available in the context menu of specific items
(see 3.5.1. Create a toolbar, pg.51).

Show Toolbar Show the selected toolbar.

Show at right click Activate this option so that the toolbar is also shown when the right
mouse button is pressed on a 3d plot window.

Export to Session Editor A new tab will be created in the Session Editor window and the session
commands assigned to the selected toolbar / button / box will be
exported to it.

Insert... Insert one of the following in the selected toolbar/group/menu/tab page:

- Group - Checkbox
- Menu - Textbox
- Tab - File textbox
- Button - Directory textbox

Delete Delete the selected items.

Save as... Save a toolbar in a *.defaults file. Only available for toolbars

Set target defaults Set the target defaults where the toolbars will be saved with the Save
to Defaults button.

Cut/Copy Cut / Copy selected items

Paste Paste copied items in under selected item. The option appears only if
there are any items copied.

Expand all/ Collapse all Expand or Collapse all Toolbar trees.

Copy all/selected to Copy the titles of all or of selected items to clipboard


Clipboard.

BETA CAE Systems 36 META Automation User’s Guide


3. Toolbar Designer

3.3. Item Properties

3.3.1. Introduction
In this section different properties of different Items are presented. Fields that appear in more than
one Items’ Properties are explained only the first time met.

3.3.2. Toolbar properties

Name Input the characteristic text that META uses to understand that toolbar.

Label Input the label to appear as name of the toolbar. Due to the use of the Name in
commands, there may be a need to not include gaps in the Name and use short
Names for easier handling. In that case a different Label can be set, which is the
name that actually appears as title in the toolbar window. If the button is
activated Label will have the same input as Name and it will not be editable.

Orientation Set the orientation of the item to:


- Horizontal
- Vertical

BETA CAE Systems 37 META Automation User’s Guide


3. Toolbar Designer

Expand into Activate this option so that the submenus, groups, buttons, etc. of the Toolbar will
User Toolbars appear as further expansions under Toolbars menu of META (Toolbars>
submenu Toolbar>...).

Commands Input META commands, to be executed with the execution of the Item. They can
be edited by pressing the Edit commands list button.

Commands Input META commands, to be executed with the activation / deactivation of the
On / Off Item. They can be edited by pressing Edit commands on / off list buttons
respectively.

3.3.3. Group properties


Only Name, Label and Orientation options are available
for Group Items.

3.3.4. Menu properties


- Name, Label and Orientation options are also
available for Menu Items.

Info tip Activate this checkbox to display the text written in the respective field when
the mouse cursor is left on the Menu.

Image checkbox Use an image from a valid file path to be displayed in the drop-down button
of the Menu.

Color Set color for:


- Text
- Background

BETA CAE Systems 38 META Automation User’s Guide


3. Toolbar Designer

3.3.5. Tab properties


Tab Item has only Name and Label Properties available.

3.3.6. Button properties


- Name, Label, Info tip, Image and Color options are
available.
- In Commands list the commands that the button will
execute can be edited by pressing the Edit commands
list button.

Button Type Select the type of the button among the following options:
- Simple Button
- Font Selection Button: When pressed a Font selection window will be
invoked
- Color button: When pressed a color selection window will be invoked. The
button will colored according to the picked color.

Commands Press Edit commands list button to edit the commands that the button will
execute.

BETA CAE Systems 39 META Automation User’s Guide


3. Toolbar Designer

3.3.7. Toggle button properties


- Name, Label, Info tip, Image and Color options are
available.
- In Commands list the commands that the button will
execute can be edited by pressing the Edit commands
list button.

Initial State Set initial state of the checkbox when invoked (with the toolbar):
- Unckecked
- Checked

Execute Initial Enable execution of the commands that correspond to the above selection of
commands the Initial State, i.e. Checked (Commands On) or Unchecked (Commands
Off).

Commands On / Edit the commands applied when the checkbox is activated / deactivated by
Off the Edit commands on / off list buttons respectively.

BETA CAE Systems 40 META Automation User’s Guide


3. Toolbar Designer

3.3.8. Checkbox properties


- Name, Label, Info tip, Image and Color options are
available.

Initial State Set initial state of the checkbox when invoked (with the toolbar):
- Unckecked
- Checked

Execute Initial commands Enable execution of the commands that correspond to the above
selection of the Initial State, i.e. Checked (Commands On) or
Unchecked (Commands Off).

Commands On / Off Edit the commands applied when the checkbox is activated /
deactivated by the Edit commands on / off list buttons
respectively.

BETA CAE Systems 41 META Automation User’s Guide


3. Toolbar Designer

3.3.9. Radio button properties


- Name, Label, Info tip, Image and Color
options are available.

Commands Edit the commands applied when the radio-button is activated by pressing Edit
commands list button.
Radiobuttons are deactivated when at least 1 more Radiobutton is available and
activated at the same Group and its commands are applied instead.

BETA CAE Systems 42 META Automation User’s Guide


3. Toolbar Designer

3.3.10. Slider properties


- Name, Label, Info tip, Image and Color options are
available.

Enable tracking When active, the commands will be applied when the slider is moved.
Otherwise the commands will be applied when the slider is left at rest, i.e.
after its movement has stopped.

Slider Style Set the type of the slider using the options:
- Slider Only
- Spinbox Only
- Both

Range Control the range of the slider setting the appropriate values in the fields:
- Min
- Max

Commands Edit the commands applied when setting the slider pressing the Edit
commands list button.

BETA CAE Systems 43 META Automation User’s Guide


3. Toolbar Designer

3.3.11. Textbox properties


- Name, Label, Info tip, Image and Color options are
available.

Disable edit Enable this checkbox to disable edit of the textbox. By enabling this
option, the Trigger on text checkbox will be hidden and enabled by
default.

Trigger on text Enabling this checkbox, commands will be applied while typing the
text.

Initial State Write a text to be the default value of the textbox when launching
the toolbar.

Execute initial commands Activating this checkbox, if arguments of META commands exist in
the Initial State field, the corresponding commands will be
executed.

Commands Press the Edit commands list button to execute the commands of
the Textbox.

History Enter string values to form a list of predefined options to select in


the appearing drop-down menu of the Textbox, by pressing the Edit

BETA CAE Systems 44 META Automation User’s Guide


3. Toolbar Designer

history list button.

3.3.12. Filetextbox properties


- Name, Label, Info tip, Image and Color options are
available.
- Initial State Execute initial commands, Commands
and History options are available too.

File Selection - Any file: The file manager invoked by the file textbox will contain a Save
button.
- Only existing file: The file manager invoked by the file textbox will contain an
Open button.

Trigger on text Enabling this checkbox, commands will be applied while typing the text.

Initial State Write a text to be the default value of the textbox when launching the toolbar.

Execute initial Activating this checkbox, if arguments of META commands exist in the Initial
commands State field, the corresponding commands will be executed.

Commands Press the Edit commands list button to execute the commands of the Textbox.

BETA CAE Systems 45 META Automation User’s Guide


3. Toolbar Designer

Wildcards Pressing the Edit wildcards list,to edit the Wildcards of the Filetextbox to appear
as available File Types in the File Manager that will be invoked from it.

History Enter string values to form a list of predefined options to select in the appearing
drop-down menu of the Textbox, by pressing the Edit history list button.

BETA CAE Systems 46 META Automation User’s Guide


3. Toolbar Designer

3.3.13. Directory textbox properties


- Name, Label, Info tip, Image and Color options are
available.
- Initial State Execute initial commands, Commands and
History options are available too.

Initial State Write a text to be the default value of the textbox when
launching the toolbar.

Execute initial commands Activating this checkbox, if arguments of META


commands exist in the Initial State field, the
corresponding commands will be executed.

Commands Press the Edit commands list button to execute the


commands of the Textbox.

History Enter string values to form a list of predefined options to


select in the appearing drop-down menu of the Textbox,
by pressing the Edit history list button.

BETA CAE Systems 47 META Automation User’s Guide


3. Toolbar Designer

3.4. Editing the commands list - Property editor

The image depicts the Property editor tab, specifically that of Radibutton Commands. The available
options in this tab depend upon the Type of item that has been selected to be edited.
The available tabs are
- Commands
- Commands On
- Commands Off
- Wildcards
- History.
The commands that are listed in the Command list (On / Off) are the ones that will be assigned to
the selected item as soon as the Apply button is pressed.

Blank Field Type the commands directly

Record actions as commands in the Commands or Commands On /


Off tabs.
Show Commands Window Invoke the Commands tool (Tools>Commands), to select a
command. Once selecting the proper command apply the option
Send command to toolbar designer from the context menu, and the
command will pass to the Property Editor.

BETA CAE Systems 48 META Automation User’s Guide


3. Toolbar Designer

Import Session File Import a session file with commands to be assigned on the
respective item.
Edit in Session Editor Edit the commands typed in the blank field in Session Editor.
Pressing the button the Session Editor window will be invoked
containing everything typed in the blank field until that moment.
Add Environment variable Select an environment variable from a list containing all environment
variables.
Apply Assign the input commands to the item

Scripts can also be embedded within the commands list, separated from the rest of the commands
using a starting, #!script, line and an ending, #!EOF, line.
For all types of text buttons, apart from the above options, there are extra similar options for multiple
arguments that can be passed to these types of buttons.

Add Button argument Apply a button argument


(Button Items only)

Add Slider Argument Apply a slider argument


(Slider Items only)

Add Textbox argument Invoke an argument list to select


between All and 0-10, to be added
(Textboxes, Filetextboxes, as argument. Nevertheless a value
Directory Textboxes) can be set to 11 or more by typing it
directly in the field. The expression
produced in the Command field will
be of the form: {0} for argument 0,
{1} for 1 and so on. For argument
All it will be {}. All is the only option
available for Buttons and Sliders.
Text should be separated with “;” for
META to separate columns and find
the appropriate text according to the
argument.

BETA CAE Systems 49 META Automation User’s Guide


3. Toolbar Designer

Furthermore, in History
tab the control of the
History options is
available for the
respective Items.

History Type arguments to be added in the History list.

Add the arguments typed in the History field in the list.

Move selected entries in the History list. This way the values will fill back the History
field.

Delete Delete the entry from the list.

Apply Apply the History list.

Similar to History tab is


the functionality of
WildCards tab.

File type Input the file type to be added in the list

Wildcard Input the wildcard connected to the specific filetype.

Automated procedures that execute toolbar commands are supported. The functionality of a button
or checkbox etc. can be applied with the command:
toolbar edit click <toolbar name><button name>
The command can be used within another section of the same toolbar or another toolbar to repeat
some process automatically. To have a set of default settings in a toolbar by opening it, for example,
the previous command can be used. In order to activate checkboxes by the startup of a toolbar (or
similar action), without applying their functionality, the following command can be used:
toolbar edit onlytoggle <toolbar name> <checkbox name> on/off

BETA CAE Systems 50 META Automation User’s Guide


3. Toolbar Designer

3.5. How to (Toolbar Designer)

3.5.1. Create a toolbar


The following examples illustrate the creation of a Toolbar for saving results in a MetaDB file. The
toolbar comprises of one checkbox button, three radio buttons and one text button. The checkbox
controls, whether visible or all, are saved to the file. The three radio buttons are related to the
settings regarding which results should be saved and the text box is for saving the file.

1. Press Create A new toolbar to create it in the list


2. Define its settings (name, orientation and Target Defaults file, if needed).

3. Create a new group for this


toolbar and define the appropriate
settings (name and orientation).
Creating groups is a save way to
organize Buttons, Checkboxes,
3 etc.

BETA CAE Systems 51 META Automation User’s Guide


3. Toolbar Designer

3.5.2. Define a radio button


5. Press the right mouse button on
the previously created group and
Insert>Radiobutton. Define its
settings (Name, Orientation) as
previously (Name: Function &
Displacement).
1 Note that a radio button can be
1 created only inside a group.
1

6. Switch to the Property Editor tab. Type the commands:


write options MetaDB dispsave enable
write options MetaDB funcsave enable
write options MetaDB geomsave enable

7. Press Apply

8. Repeat steps 3 and 4 to create two more radio buttons: one for writing only Geometry and
Displacement results (Displacement) and the other for writing Geometry and Function results
(Function).

BETA CAE Systems 52 META Automation User’s Guide


3. Toolbar Designer

3.5.3. Define a checkbox


1. Turn to the Property
Viewer and create a
new Checkbox from
the context menu of
the Toolbar. Define the
appropriate settings.

2. Switch back to the


Property Editor tab, in
the Commands On tab
an type the command:
write options
MetaDB vissave
enable
2 Press Apply to assign
the command to the
checkbox. Repeat the
procedure in the
Commands Off tab
with the command:
write options
MetaDB vissave
disable).

BETA CAE Systems 53 META Automation User’s Guide


3. Toolbar Designer

3.5.4. Define a textbox and assign its functionality by recording actions


1. Back to the Property Viewer
tab, select the Toolbar and
select Insert>Textbox from its
context menu. Define the
appropriate settings (Name:
Save Data).
1

2. Turn to the Property Editor.


Activate the record button and
then save a MetaDB from
File>Save. Then deactivate the
record button. Only the last
command should be assigned
to the text button (write
2 MetaDB ...), since the rest
of the commands are regulated
by the buttons defined
3 previously.
4
3. Select the text that
corresponds to the label of the
results and replace it with the
first argument of this textbox by
pressing the Add Textbox
argument button. From the
Arguments List that appears
select (0).
4. Press Apply.

BETA CAE Systems 54 META Automation User’s Guide


3. Toolbar Designer

5. In the same way


select the path to be
replaced by an
environment
variable.
6. Press the Add
5 environment variable
button. In the
6 Environments
Variables List that
appears select
7 HOME.
7. Press Apply to
replace the path by
the variable $HOME.

8. Then, select only the


base (not the
extention of the file
name) to replace it
with the second
textbox argument.
The procedure is the
8 same as in steps 2,
3 and 4 and id (1) is
selected.
9. Press Apply.
9

The final command


written is:
write MetaDB {0}
${HOME}/{1}.metadb

BETA CAE Systems 55 META Automation User’s Guide


3. Toolbar Designer

The Toolbar is ready. Select it in the Property


Viewer and select the View toolbar option from its
context menu or double-click on it. The new
created Toolbar is presented aside.
Optionally, press Save to Defaults button to save it
in the Target Defaults File.
By selecting a User Toolbar in the Toolbar
Designer and activating the Expand into User
Toolbars submenu checkbox, it is now possible to
create submenus under this toolbar, which will
include the buttons, checkboxes and radio buttons
of the toolbar.

3.5.5. Add textbox arguments


1. In the toolbar of the previous
example select the final
Textbox “Save Data” and
press Edit commands.
1

2. In the Property Editor>


Commands tab type the
expression:
opt var add n
in the field. Leave a gap
(Space key from keyboard)
and then press the Add
Textbox argument button and
select All in the invoked
2 window. The expression
should be:
opt var add n {}
Press Apply.

3. Double-click on the Toolbar Item (or any


expansion) in the expansion tree to invoke
it. Add the expression:
text1;text2;text3;text4
3 in the Save Data Textbox and press the
Enter key.

BETA CAE Systems 56 META Automation User’s Guide


3. Toolbar Designer

4. Open the Variables window from


Tools menu of META.
(Tools>Variables). The variable is
added in the list ant its value is the
full expression:
text1;text2;text3;text4.

5. Select again the Textbox in the


list and press Edit commands.
Change the expression in the
Property editor to:
opt var add n {0} {2}
and press Apply.

6. Leave the expression in the Save


Data field of the created Toolbar as it
is and press the Enter key again.
Turn in the Variables window again.
The Value has changed conaining
st nd
only the 0 (1 ) and 2 (2 ) value of
the “;” separated string entry:
6 text1text3.

BETA CAE Systems 57 META Automation User’s Guide


3. Toolbar Designer

3.5.6. Add history


1. Select the previous Textbox
again and press Edit History
1 list.

2. Insert the values text1,


text2, text3 separately
by typing them in the History
field.
3. Press Apply.
2

4. The options appear in the Save Data drop-down menu of


the created Toolbar

BETA CAE Systems 58 META Automation User’s Guide


3. Toolbar Designer

3.5.7. Add file textbox with wildcards


1. Select the Toolbar Item in the
Item list and Insert a
Filetextbox from the context
menu. Set the Name “Save
File” in the respective field.

2. Select the Filetextbox and


press Edit wildcards list
button.
2

3. Type Text Files in the File


type field and *.txt in the
Wildcard field and add them
in the list.
4. Press the Apply button.

3
4

BETA CAE Systems 59 META Automation User’s Guide


3. Toolbar Designer

5. Activate the Toolbar and


invoke the File Manager from
the ... button of the Save File
Filetextbox. The only
available option in the File
Type drop-down menu of the
File Manager is Text Files
(*.txt).
4

BETA CAE Systems 60 META Automation User’s Guide


3. Toolbar Designer

3.6. Summary Table of the keywords used within toolbars

Conventions:

Courier New Bold: Keywords used for creation of items of the toolbars

<Quoted>: Referenced field for User input.

Courier New Bold Italics Any META command with the same syntax as in the
command line of the program.

Keywords:

1 toolbar start <name>


Define a vertical toolbar. This must be the first keyword of a toolbar.

2 toolbar hstart <name>


Defines a horizontal toolbar. This must be the first keyword of a toolbar.

3 toolbar onoff : commands on 1 ; commands on 2; … | commands off 1 ;


commands off 2; …
It is placed after a toolbar start directive. The on commands run when the toolbar is
shown and the off commands run when the toolbar is hidden.

4 toolbar group <name>


Defines a group of buttons. All following buttons, toggle buttons or text buttons are assigned
to this group unless another toolbar or group is defined. Although obsolete, it is still
supported for compatibility with older versions.

5 toolbar subgroup <name>


Denotes the start of a vertical group of buttons. All button definitions that are enclosed
between this keyword and the toolbar endgroup are assigned to this group.

6 toolbar hsubgroup <name>


Denotes the start of a horizontal group of buttons. All button definitions that are enclosed
between this keyword and the toolbar endgroup are assigned to this group.

7 toolbar endgroup
Denotes the end of a group definition. This is related to groups defined either with the
toolbar subgroup or the toolbar hsubgroup keywords.

BETA CAE Systems 61 META Automation User’s Guide


3. Toolbar Designer

8 toolbar tab <name>


Denotes the start of a tab section that can include several page tabs. All page tabs enclosed
between the lines toolbar tab and toolbar endtab belong to the same tab
section. All buttons defined within a toolbar tab section should be defined under a toolbar
pagetab …definition. It is not possible to have buttons defined for a toolbar tab section
without having defined at least one toolbar pagetab keyword for that tab section.

9 toolbar endtab
Denotes the end of a tab section.

10 toolbar pagetab <name>


Defines a vertical page tab within a tab section. Page tabs can be defined only within a tab
section (only between the keywords: toolbar tab and toolbar endtab. The end
of a page tab definition is denoted either by another toolbar pagetab or by a
toolbar endtab.

11 toolbar hpagetab <name>


Defines a horizontal page tab within a tab section. The same issues valid for vertical page
tabs are also valid here. See previous keyword.

12 toolbar button <name> : command1 ; command2 ; command3 ; …


One command or a sequence of commands (macro operation) can be assigned to this
button. A colon : must follow the name of the button and the commands in sequence must
be separated with a semicolon ; There is no limit to the number of commands in sequence.

13 toolbar togbutton <name> : command1ON ; command2ON ; ...|


command1OFF ; commnad2OFF ; ...
Defines a toggle button. A toggle button holds two options. The two options must be
separated with a “|”. If the button is ON, the first option is applied. If it is OFF, then the
second option is applied. Each option may hold one or more commands in sequence. A
colon : must follow the name of the button and the commands in sequence must be
separated with a semicolon ;. There is no limit to the number of commands in sequence.

14 toolbar toggle <name> : command1ON ; command2ON ; ...| command1OFF ;


commnad2OFF ; ...
Defines a checkbox. A checkbox holds two options. The two options must be separated with
a “|”. If the button is ON, the first option is applied. If it is OFF, then the second option is
applied. Each option may hold one or more commands in sequence. A colon : must follow
the name of the button and the commands in sequence must be separated with a semicolon
;. There is no limit to the number of commands in sequence.

15 toolbar radio <name> : command1ON ; command2ON ; ...| command1OFF ;


commnad2OFF ; ...
Defines a radio button. Radio buttons form a group of switches and only one of them can be
active at a time. Consequently, radio buttons can be defined only within a toolbar group
(defined with the keywords: group, subgroup or hsubgroup). A colon : must follow the
name of the button and the commands in sequence must be separated with a semicolon ;.
There is no limit to the number of commands in sequence.

BETA CAE Systems 62 META Automation User’s Guide


3. Toolbar Designer

16 toolbar text <name> : command1 ; command2 ; command3 ; …


This is used for commands which demand input (arguments) from the user. One command
or a sequence of commands can be assigned to this button. The command step, where the
argument is requested, it is substituted by the string {N}. N corresponds to the order of the
argument (starting from 0) (eg: {0} corresponds to the first argument that is necessary, {1}
corresponds to the second argument and so on).
When using the created text button for the application of commands, the multiple arguments
typed inside the field must be separated by a semicolon ;.

17 toolbar ctext <name> : command1 ; command2 ; command3 ; …


Defines a combobox. This is the same as a text button but the input cannot be provided by
typing it in the field. The input has to be selected among several predefined options.
Therefore, for this button to be operational, it is necessary to combine it with the definition of
a toolbar historytext.

18 toolbar filetext <name>: command1 ; command2 ; command3 ; …


This creates a text field that provides also a file browser. Hence, this can be used for
commands that require the input of a filename. However, an efficient usage of this button is
related to the command:
opt var add <Variable name> <Variable value>
for the definition of a variable that will be assigned a filename with the complete path as a
value. This variable can then be used wherever necessary (functions/scripts) instead of
writing the full path. The rules for arguments that exist for a text button exist also for a
filetext button.

19 toolbar sfiletext <name>: command1 ; command2 ; command3 ; …


This is the same as a toolbar filetext except that this is for use only with existing
files. That means that this can serve as a file manager for opening files and not for saving.

20 toolbar directorytext <name>: command1 ; command2 ; command3 ; …


This creates a text field that provides also a directory browser. An efficient usage of this
button is related to the command:
opt var add <Variable name> <Variable value>
for the definition of a variable that will be assigned a directory path as a value. The rules
for arguments existing for a text exist also for a directorytext button.

21 toolbar historytext <name of text or ctext or filetext or sfiletext or


directorytext field> : <option1>|<option2>|…
Using this keyword, a list of available options may be created for the already defined, text
or ctext or filetext or sfiletext or directorytext field. By activating the
respective field in META and pressing F1, the list with all available options appears.
Notes
- The definition of the text or ctext or filetext or sfiletext or directorytext
field must precede that of the historytext keyword.

22 toolbar filterfiletext <filter1> ; <filter2> | <filter3> ...


Use this keyword to define default filters that will be available within the File Browser of a
filetext or sfiletext button.
Notes

BETA CAE Systems 63 META Automation User’s Guide


3. Toolbar Designer

- To define multiple filters as one option: Separate filters with semi-colons (;) or
spaces
- To define multiple filters as multiple options: Separate filter options with |. In that
case, the last defined filter will be the current when opening the File Browser.
- The filterfiletext keyword must be the next specified keyword after the respective
filetext or sfiletext button definition.

23 toolbar menu <name of the menu>


This is used to denote the beginning of a pulldown menu definition. The options for the
pulldown menu must be defined as simple buttons (toolbar button) placed under the
toolbar menu keyword.

24 toolbar endmenu .
This keyword is used to denote the end of the definition of a pulldown menu.

25 toolbar relativesize <size>


Specifies the horizontal relative size of the element. If the element is part of a horizontal
group, then the raletive size of each element will define how the horizontal space of the
group is distributed. The size parameter must be an integer.

26 toolbar init: command1 ; command2 ; command3 ; …


This keyword is used right after keywords “toolbar start” or “toolbar hstart”. The specified
commands are executed at the creation of the toolbar.

27 variable <Variable name> <Variable value>


This keyword is used for the definition of a variable that can be used within the toolbar
definitions. For example, the path for the icons (see below par. 21.5.6.4) that are used for
the toolbar buttons can be specified using a variable. The only restriction is that this variable
should be defined inside the META_post.defaults file above (and not below) the lines where
this variable is referenced.

28 MOUSE_TOOLBAR <Name of the toolbar>


Use this parameter to define one toolbar that will appear each time the right mouse button is
pressed inside a META 3d Drawing window.

BETA CAE Systems 64 META Automation User’s Guide


4. Scripting
Table of Contents

4.1. Introduction .............................................................................................................................. 70


4.2. Script Editor ............................................................................................................................. 71
4.2.1. Interface ........................................................................................................................... 71
4.2.2. Main menu ....................................................................................................................... 72
4.2.3. Standard toolbar............................................................................................................... 76
4.2.4. Editor................................................................................................................................ 77
4.2.4.1. Interface .................................................................................................................... 77
4.2.4.2. The Immediate tab .................................................................................................... 79
4.2.5. META Window Designer .................................................................................................. 79
4.2.6. Snippets ........................................................................................................................... 80
4.2.7. Select font ........................................................................................................................ 81
4.2.8. Editor colors ..................................................................................................................... 82
4.2.9. How to (Script Editor) ....................................................................................................... 83
4.2.9.1. Monitor variables ....................................................................................................... 83
4.2.9.2. Debug scripts ............................................................................................................ 84
4.2.9.3 Create and handle projects ........................................................................................ 86
4.3. Python Scripting ....................................................................................................................... 88
4.3.1. Introduction ...................................................................................................................... 88
4.3.1.1. Introduction................................................................................................................ 88
4.3.1.2. The Python Programming Language .................................................................. 88
4.3.1.3. Python Version .......................................................................................................... 88
4.3.1.4. Python Documentation .............................................................................................. 88
4.3.2. Short Introduction to Python ............................................................................................. 88
4.3.2.1. Data types ................................................................................................................. 88
4.3.2.1.1. Numbers ............................................................................................................. 88
4.3.2.1.2. Sequences Data Types ...................................................................................... 89
4.3.2.1.3. The del statement ............................................................................................... 90
4.3.2.1.4. The none Object ................................................................................................. 90
4.3.2.2. Modules and Namespaces ........................................................................................ 90
4.3.2.2.1. Module ................................................................................................................ 90
4.3.2.2.2. Namespaces....................................................................................................... 91
4.3.2.3. Program scope .......................................................................................................... 91
4.3.2.4. If statements and branching ...................................................................................... 91
4.3.2.4.1. The "if-else" blocks and the logical operators ..................................................... 91
4.3.2.5. Loop statements ........................................................................................................ 92
4.3.2.5.1. The for statement ............................................................................................... 92
4.3.2.5.2. The while statement ........................................................................................... 93
4.3.2.5.3. The continue, break and pass statements .......................................................... 93
4.3.2.6. Handling lists ............................................................................................................. 94
4.3.2.6.1. Set data in a list .................................................................................................. 94
4.3.2.6.2. Retrieve values from a list .................................................................................. 95
4.3.2.6.3. Retrieve the length of a list ................................................................................. 95
4.3.2.7. Handling Strings ........................................................................................................ 95
4.3.2.7.1. Adding strings ..................................................................................................... 95
4.3.2.7.2. Handling strings as matrices............................................................................... 96
4.3.2.8. Handling Dictionaries ................................................................................................ 96
4.3.2.8.1. Set keys and data in a Dictionary ....................................................................... 96
4.3.2.8.2. Retrieve a node value ......................................................................................... 96
4.3.2.8.3. Delete a node ..................................................................................................... 97
4.3.2.8.4. Iteration through the data in a map ..................................................................... 97
4.3.2.8.5. Check the existence of a key .............................................................................. 97
4.3.2.8.6. Identify the number of map nodes ...................................................................... 97
4.3.2.8.7. Destroy the dictionary and release memory ....................................................... 97
4.3.2.9. User functions ........................................................................................................... 97
4.3.2.9.1. Definition ............................................................................................................ 97
4.3.2.9.2. Returning data from functions............................................................................. 98
4.3.2.9.3. Argument Matching Modes ................................................................................. 98
4.3.2.9.4. Help text and comments ..................................................................................... 98
4.3.2.9.5. Global variables .................................................................................................. 99
4.3.2.9.6. Program variables .............................................................................................. 99
4.3.2.10. Handling exceptions .............................................................................................. 100
4.3.2.11. Object Oriented Programming Basics ................................................................... 100
4.3.2.12. Organizing scripts .................................................................................................. 101
4.3.2.12.1. Including files .................................................................................................. 101
4.3.2.12.2. Including files using the ImportCode Function ................................................ 102
4.3.3. META session commands within scripts ........................................................................ 102
4.3.4. Interacting with MΕΤΑ .................................................................................................... 103
4.3.4.1. General.................................................................................................................... 103
4.3.4.2. Handling data .......................................................................................................... 104
4.3.4.2.1. Introduction ....................................................................................................... 104
4.3.4.2.2. META classes................................................................................................... 104
4.3.4.2.3. Subclassing META classes .............................................................................. 105
4.3.4.3. Collect entities ......................................................................................................... 105
4.3.4.3.1. Introduction ....................................................................................................... 105
4.3.4.3.2. Collect entities of the database......................................................................... 107
4.3.4.3.3. Collect entities according to their attributes (results, name, id, type, position,
comments, failure, free, outer)........................................................................................... 108
4.3.4.3.4. Collect entities from other entities..................................................................... 110
4.3.4.3.5. Collect visible entities ....................................................................................... 110
4.3.4.3.6. Collect identified entities ................................................................................... 111
4.3.4.3.7. Collect models information ............................................................................... 111
4.3.4.3.8. Collect newly created entities ........................................................................... 111
4.3.4.3.9. Collect files and directories ............................................................................... 112
4.3.4.3.10. Collect view parameters ................................................................................. 112
4.3.4.3.11. Select files or directories through the file manager ......................................... 113
4.3.4.4. Create, Edit, Delete and Handle Entities ................................................................. 114
4.3.4.4.1. Introduction ....................................................................................................... 114
4.3.4.4.2. Create entities .................................................................................................. 114
4.3.4.4.3. Edit entities ....................................................................................................... 115
4.3.4.4.4. Delete entities ................................................................................................... 115
4.3.4.4.5. Show / Hide entities .......................................................................................... 115
4.3.4.4.6. Identify entities.................................................................................................. 115
4.3.4.4.7. Get/handle material properties ......................................................................... 116
4.3.4.4.8. Get results/attributes of entities ........................................................................ 116
4.3.4.4.9. Get measurements from entities....................................................................... 118
4.3.4.4.10. Get connected and neighbour elements/nodes .............................................. 119
4.3.4.4.11. Get spreadsheet entities/data ......................................................................... 120
4.3.4.4.12. Get attributes of user Toolbars ....................................................................... 120
4.3.4.5. Load Geometry and Solver Results, Create User-Defined Results ......................... 121
4.3.4.5.1. Load geometry and field / history results .......................................................... 121
4.3.4.5.2. Create user-defined field results ....................................................................... 123
4.3.4.6. Useful notes about ΜΕΤΑ script functions ............................................................... 123
4.3.4.6.1. Speed up the execution of scripts..................................................................... 123
4.3.5. User defined buttons and custom GUI ........................................................................... 124
4.3.5.1. General.................................................................................................................... 124
4.4. BETA Scripting Language ...................................................................................................... 125
4.4.1. Introduction .................................................................................................................... 125
4.4.2. Syntax ............................................................................................................................ 125
4.4.3. Data types ...................................................................................................................... 126
4.4.3.1. General.................................................................................................................... 126
4.4.3.2. User Defined Data Types (structures) ..................................................................... 127
4.4.4. Variables ........................................................................................................................ 127
4.4.4.1. Introduction.............................................................................................................. 127
4.4.4.2. Naming of variables and restrictions ....................................................................... 127
4.4.4.3. Declaration of variables ........................................................................................... 129
4.4.4.4. The const keyword .................................................................................................. 129
4.4.4.5. Checking the variables‟ spelling .............................................................................. 129
4.4.5. Sets of data: matrices and maps .................................................................................... 130
4.4.5.1. Introduction.............................................................................................................. 130
4.4.5.2. Matrices ................................................................................................................... 130
4.4.5.3. Maps........................................................................................................................ 131
4.4.6. Operators and basic calculations ................................................................................... 131
4.4.6.1. Expressions and assignments for numeric data types ............................................ 131
4.4.6.2. Arithmetic operators ................................................................................................ 131
4.4.6.3. Assignment operators.............................................................................................. 132
4.4.6.4. Combination of assignment with arithmetic operators ............................................. 133
4.4.6.5. Increment and decrement operators ....................................................................... 133
4.4.6.6. Logical operators ..................................................................................................... 133
4.4.6.7. Expressions and assignments for string data types ................................................ 134
4.4.6.8. Expressions and assignments for struct data types ................................................ 135
4.4.7. Conditional statements and branching ........................................................................... 137
4.4.7.1. The "if-else" blocks and the logical operators .......................................................... 137
4.4.7.2. The switch statement .............................................................................................. 138
4.4.7.3. The goto statement ................................................................................................. 139
4.4.8. Loop statements............................................................................................................. 139
4.4.8.1. The foreach statement ............................................................................................ 139
4.4.8.2. The for statement .................................................................................................... 139
4.4.8.3. The while statement ................................................................................................ 140
4.4.8.4. The do while construct............................................................................................. 141
4.4.8.5. The continue and break statements ........................................................................ 141
4.4.9. Handling variables and sets of data ............................................................................... 142
4.4.9.1. Handling matrices .................................................................................................... 142
4.4.9.1.1. Setting data to a matrix ..................................................................................... 142
4.4.9.1.2. Retrieve a matrix member value ....................................................................... 142
4.4.9.1.3. Retrieve the size of a matrix ............................................................................. 142
4.4.9.1.4. Matrix expressions............................................................................................ 143
4.4.9.2. Handling Strings ...................................................................................................... 144
4.4.9.2.1. Correspondence between Strings and Matrices ............................................... 144
4.4.9.2.2. Modify Strings ................................................................................................... 144
4.4.9.3. Handling Maps ........................................................................................................ 145
4.4.9.3.1. Map Declaration and Initialization ..................................................................... 145
4.4.9.3.2. Set and Retrieve Map Node Values ................................................................. 145
4.4.9.3.3. Delete Node Values.......................................................................................... 146
4.4.9.3.4. Iteration through the Data of a Map .................................................................. 146
4.4.9.3.5. Check the existence of a node ......................................................................... 146
4.4.9.3.6. Destroy Map and Release Memory .................................................................. 146
4.4.9.3.7. Identify the Number of Map Nodes ................................................................... 146
4.4.10. User functions .............................................................................................................. 147
4.4.10.1. Introduction............................................................................................................ 147
4.4.10.2. Definition ............................................................................................................... 147
4.4.10.3. Argument list and function call............................................................................... 147
4.4.10.4. Declaring functions as variables ............................................................................ 148
4.4.10.5. Returning data from functions (return, byref call) .................................................. 148
4.4.10.6. Scope and lifetime of variables .............................................................................. 150
4.4.10.7. Public and private functions................................................................................... 151
4.4.10.8. Including files ......................................................................................................... 151
4.4.10.9. Including project files ............................................................................................. 152
4.4.10.10. Compilation control (Preprocessor) ..................................................................... 152
4.4.10.11. Recursive structures ............................................................................................ 155
4.4.10.12. Initialization of matrices and variables ................................................................. 156
4.4.10.13. Help text and comments ...................................................................................... 157
4.4.11. META session commands within scripts ...................................................................... 158
4.4.12. Interacting with MΕΤΑ .................................................................................................. 159
4.4.12.1. General.................................................................................................................. 159
4.4.12.2. Handling data ........................................................................................................ 159
4.4.12.2.1. Introduction ..................................................................................................... 159
4.4.12.2.2. META structs .................................................................................................. 160
4.4.12.3. Collect entities ....................................................................................................... 170
4.4.12.3.1. Introduction ..................................................................................................... 170
4.4.12.3.2. Collect entities of the database....................................................................... 171
4.4.12.3.3. Collect entities according to their attributes (results, name, id, type, position,
comments, failure, free, outer)........................................................................................... 172
4.4.12.3.4. Collect entities from other entities................................................................... 174
4.4.12.3.5. Collect visible entities ..................................................................................... 174
4.4.12.3.6. Collect identified entities ................................................................................. 175
4.4.12.3.7. Collect models information ............................................................................. 175
4.4.12.3.8. Collect newly created entities ......................................................................... 175
4.4.12.3.9. Collect files and directories ............................................................................. 176
4.4.12.3.10. Select files or directories through the file manager ....................................... 176
4.4.12.4. Create, Edit, Delete and Handle Entities ............................................................... 177
4.4.12.4.1. Introduction ..................................................................................................... 177
4.4.12.4.2. Create entities ................................................................................................ 177
4.4.12.4.3. Edit entities ..................................................................................................... 178
4.4.12.4.4. Delete entities ................................................................................................. 178
4.4.12.4.5. Show / Hide entities ........................................................................................ 178
4.4.12.4.6. Identify entities................................................................................................ 179
4.4.12.4.7. Get /handle material properties ...................................................................... 179
4.4.12.4.8. Get results/attributes of entities ...................................................................... 179
4.4.12.4.9. Get measurements from entities..................................................................... 182
4.4.12.4.10. Get connected and neighbour elements/nodes ............................................ 183
4.4.12.4.11. Get spreadsheet entities/data ....................................................................... 184
4.4.12.4.12. Get attributes of user Toolbars ..................................................................... 184
4.4.12.5. Load Geometry and Solver Results, Create User-Defined Results ....................... 185
4.4.12.5.1. Load geometry and field / history results ........................................................ 185
4.4.12.5.2. Create user-defined field results ..................................................................... 187
4.4.12.6. Useful notes about META script functions ............................................................. 187
4.4.12.6.1. Speed up the execution of scripts................................................................... 187
4.4.13. User defined buttons and custom GUI ......................................................................... 188
4.4.13.1. General.................................................................................................................. 188
4.4.13.2. Creation of custom graphical user interface (GUI) ................................................ 188
4.4.13.2.1. Introduction ..................................................................................................... 188
4.4.13.2.2. Setting Cancel and Ok buttons ....................................................................... 189
4.4.13.2.3. Opening and destroying windows ................................................................... 189
4.4.13.2.4. Callback functions for custom GUI ................................................................. 189
4.4.13.3. Callback functions ................................................................................................. 191
4.4.13.3.1. Introduction ..................................................................................................... 191
4.4.13.3.2. Setting edit fields and check buttons .............................................................. 191
4.4.13.3.3. Creating and setting up menus and radio buttons .......................................... 191
4.4.13.3.4. Creating and setting up List Boxes ................................................................. 194
4.4.13.3.5. Hiding and showing controls ........................................................................... 197
4.4.14. Exchanging data .......................................................................................................... 198
4.4.14.1. General.................................................................................................................. 198
4.4.14.2. TEXT files .............................................................................................................. 198
4.4.14.2.1. Introduction ..................................................................................................... 198
4.4.14.2.2. Opening and closing files ............................................................................... 198
4.4.14.2.3. Reading files ................................................................................................... 199
4.4.14.2.4. Writing files ..................................................................................................... 201
4.4.14.3. XML files................................................................................................................ 202
4.4.14.3.1. Introduction ..................................................................................................... 202
4.4.14.3.2. Opening XML files .......................................................................................... 202
4.4.14.3.3. Getting nodes and sub-nodes......................................................................... 203
4.4.14.3.4. Getting the name of the node ......................................................................... 203
4.4.14.3.5. Getting attributes and node data .................................................................... 204
4.4.14.3.6. Writing XML files and setting the base node .................................................. 204
4.4.14.3.7. Creating nodes ............................................................................................... 205
4.4.14.3.8. Setting attributes and node data ..................................................................... 205
4.4.14.4. Binary files ............................................................................................................. 206
4.4.14.4.1. Introduction ..................................................................................................... 206
4.4.14.4.2. Setting attributes and node data ..................................................................... 206
4.4.14.4.3. Reading and Writing binary files ..................................................................... 207
4.5. BCGUI Functions ................................................................................................................... 208
4.5.1. What is the BCGUI ......................................................................................................... 208
4.5.2. BCGUI structure and philosophy .................................................................................... 208
4.5.2.1. Classes of BCGUI entities ....................................................................................... 208
4.5.2.2. Widget classes or widgets ....................................................................................... 208
4.5.2.3. Layout classes or layouts ........................................................................................ 212
4.5.2.4. Items........................................................................................................................ 213
4.5.2.5. General Remarks .................................................................................................... 214
4.5.3. How to (BCGUI) ............................................................................................................. 215
4.5.3.1. Create a simple BCWindow..................................................................................... 215
4.5.3.2. Creating and using callback functions ..................................................................... 215
4.5.3.3. Moving more data around Creating and using callback functions ........................... 217
4.5.3.4. Advanced BCGUI functionality ................................................................................ 219
4.6. BCGUIDesigner ..................................................................................................................... 225
4.6.1. Introduction .................................................................................................................... 225
4.6.2. The Designer's interface ................................................................................................ 225
4.6.3. Toolbox .......................................................................................................................... 226
4.6.4. Constructed items list ..................................................................................................... 228
4.6.5. Common parameters (BC) ............................................................................................. 229
4.6.6. Parameters .................................................................................................................... 230
4.6.7. CallBack functions.......................................................................................................... 231
4.6.8. Help area ....................................................................................................................... 232
4.6.9. Source code area ........................................................................................................... 232
4.6.10. Editing the source code ................................................................................................ 232
4.7. Running scripts ...................................................................................................................... 233
4.7.1. Introduction .................................................................................................................... 233
4.7.2. Running scripts from GUI ............................................................................................... 233
4.7.2.1. Running script from the Script Editor ....................................................................... 233
4.7.2.2. Running script from the META command line ......................................................... 234
4.7.2.3. Running a script as a session .................................................................................. 235
4.7.2.4. Running a script as part of a session ...................................................................... 236
4.7.2.5. Running a script from inside a script ....................................................................... 236
4.7.2.6. Running a script as a Built-in function ..................................................................... 237
4.7.2.7. Running a script inside the Statistics tool ................................................................ 237
4.7.3. Running a script without GUI ......................................................................................... 238
4.7.3.1. General.................................................................................................................... 238
4.7.3.2. Running a script with the –s running option ............................................................. 239
4.7.3.3. Running a script with the -exec running option ........................................................ 240
4.7.4. Stopping the execution of a script .................................................................................. 240
4.8. META KEYWORDS ............................................................................................................... 241
4. Scripting

4.1. Introduction

The METAScripting Interface is an Application Programming Interface (API) that allows developers
to access the META core functionality and data. In scripts, all META commands can be combined
with programming capabilities. The Scripting Interface allows for:
- creation and modification of the META data/entities
- creation of custom GUI
- reading and writing custom file formats
- Access and manipulate data from nodes, elements, boundary elements, materials, annotations,
models, groups, cut planes and isofunctions.
- Manipulate 2D plots: create and select curves, access data from curves and their points and
modify them.
- Create coordinate systems and access information of defined coordinate systems.
- Create new results with user-defined data (deformation-scalar-vector) on nodes and elements.
- Create and manipulate META 3D and 2D windows.
- Create and manipulate windows during the execution of scripts.
- Manipulate files and directories.
- Create and handle data in XML form.
- Use system commands.

Scripts are created, edited and handled with Script Editor. However a script can also be written in
any text editor.

A script can be executed through:


- The Script Editor
- From META Command
- As a Session
- As part of a Session
- As a Built-in function
- Inside the Statistics tool

BETA CAE Systems 70 META Automation User’s Guide


4. Scripting

4.2. Script Editor

4.2.1. Interface
Script Editor is a complete code-developing tool to create, edit and debug scripts of META scripting
language.
The Script Editor can be accessed through:
Tools > Script Editor

Main menu Standard Editor Function list / Project


toolbar Watch window window

Status bar Help/Output window

Main menu Contains the Script Editor functions distributed under the File, Edit,
Project, Debug, Tools, View, Window and Help drop down menus.

Standard toolbar Contains buttons for calling the most important edit and debug functions.

Editor This is the text area where the code is written or tested. Every open
script file is located on its own tab. The Immediate tab allows the
debugging of script code lines missing the main function.

Help / Output window Consist of the Help and Output tabs.


Help: Displays information (synopsis, description, returns of the function,
examples) on a script function. Double clicking on a function in the
Library tab or the Search tab, information about its syntax is shown.

BETA CAE Systems 71 META Automation User’s Guide


4. Scripting

Output: Displays warnings/comments, when parsing the script, and the


output of scripts. Comments and warnings of are printed in red fonts
while outputs (if present) of the script are printed in black fonts.

Status Displays useful information, tooltips while working on scripts.

Functions list Offers a list of META script functions distributed in three tabs: Library,
Dynamic help and Search.
Library: Lists all available functions grouped by type (Annotations
functions, Elements functions, etc.)
Dynamic help: Displays the types of the parameters needed by the typed
function as arguments. It appears as a function is typed, in order to
assure that the function is typed right.
Search: Displays a list of all functions sorted in alphabetical order. It also
features an input field that can be used for filtering.

Watch window Displays information about the variables and the functions contained in a
script while debugging.

Project Window Displays the structure of a Project in a tree mode view. Also files and
includes can be created, added or removed in the Project.

4.2.2. Main menu


File

New... Creates a named Untitled, script file. A new tab in the editor window is added.
The name of the script in the tab is followed by an asterisk (*) until the script is
saved.

In the Select file type window that popup appear the options to creae a Beta or
a Python script and to create an empty script or a script, where the main
function is already defined.

Open... Invokes the file manager to browse for a script file (i.e. *.bs, *.c, *.ses) to open.
Script opens in a new tab in Editor window. There is no restriction regarding
how many scripts can be remained opened simultaneously.

Open recent Select to open, from a list of the recently opened script files.

Save Saves the current edited script. By default scripts are saved in the working
directory.

BETA CAE Systems 72 META Automation User’s Guide


4. Scripting

Save as... Invokes the file manager to save the currently edited script. The name of the
script tab also changes accordingly.

Save all Saves all open scripts.

Close Closes the current edited script file.

Print Invokes the Print window to print and define the printing options of the current
script.

Close window Closes the Script Editor.

Edit

Undo, Redo Undo and redo editing actions in the current edited script.

Cut, Copy, Paste Cut, Copy and Paste script text within and between windows.

Clear Deletes everything written in the current edited script.

Select all Selects all in the current edited script.

Find... Invokes the Find window to search for a word in the script.

Find next Functional only when the Find window is open. Finds the next match (F3).

Replace text Invokes the Find and Replace window to replace certain words in the script.

Goto line Point the cursor to the entered number line.

Project

New... Creates a new Project. In the New Project window specify the project‟s name
and the directory.

Append extension to main script checkbox, append the default extension .bs
(beta script) to the final main script.

Open... Invokes the file manager to browse for a project (i.e. *.bpr) to open

Open recent Select to open, from a list of the recently opened projects.

Close Closes the Project.

Save... Saves the Project.

Export main script Creates a script file named as the project, into the project‟s directory which
includes the Search script files of the project.

BETA CAE Systems 73 META Automation User’s Guide


4. Scripting

Parse file Examines the scripts, analyzing for possible syntax errors that will be printed
in the Output tab.

Compile Invokes the file manager to save the file (i.e. *.bs) in binary format.
Note that a compiled script although can be executed cannot be edited. A
compiled script can be loaded and run throughout all the normal ways
(command line, script menu) except the Script Editor. Furthermore, all the
contained functions can be called from any other script even from decompiled
ones. A compiled script can be used as include file or project file.
Scripts can be compiled normally even if they contain #include or
#projectfile statements.

Remark
Note that an opened project has compilation priority. This means that if a project is opened, then
the Parse file, Compile, Run, Run function, Debug and Debug function commands, will generate
and run the project code and not the code of the current opened file.

Debug

Run Runs the script without stopping at breakpoints. While in debugging mode, it
starts the automatic execution of the script until next breakpoint.

Debug Run the script in debugging mode. The execution stops if a breakpoint is met.

Breakpoint Add / Remove a breakpoint in the selected line(s). Line should not be emty.

Clear breakpoints Clears all set breakpoints.

Step Execute one line of script stopping on the next line of script in the same source
file. This will run any functions encountered until the above condition is met.

Step into Execute exactly one line of script. This means that will "Step into" the current
function, if necessary.

Step out Run to the end of the current function.

Run function Invokes the Select script function window. Select one function from the
available to run individually. Arguments that may need are entered manually.

Debug function Invokes the Select script function window. Select one function from the available
to debug individually. Arguments that may need are entered manually.

Tools

Designer Invokes the BETA windows designer which uses the BCGUI (BETA C
interface Graphical User Interface) library to create windows.

Code snippets Invokes the Select snippet window, to manage and import a snippet.

Make snippet Invokes the Make new snippet window, to create a snippet. If lines of script
code are selected they are automatically passed as the contents of the new
snippet.

Fix obsolete Automatically fixes commands that are written in an obsolete format or syntax.
There are commands in META scripting language that are currently obsolete
but they are still supported in order to keep compatibility with previous
versions. For example command print is obsolete but is still supported.

BETA CAE Systems 74 META Automation User’s Guide


4. Scripting

Running the Fix obsolete, print will be converted to Print.

View

Watch window Controls the visibility of Watch window.

Add variable Adds in the Watch window > variables list, the variable on which the cursor
points to. Cursor should point on to variable‟s name.

Clear watch Clears the Watch window > variables list.

Tabbed GUI Turns off/on the tabbed GUI interface (each script opens on its own tab).
Needs restart to take effect. If applied each script opens on its own window.

Select font Invokes the Select Font window to manage the font‟s type in Editor.

Editor colors Invokes the Script editor colors window to manage the coloring code of META
scripting language layout.

Window

Output window Controls the visibility of Output window.

Function list Controls the visibility of Function list window.

Project window Controls the visibility of Project window.

Help

Help Display the corresponding information (synopsis, description, returns of the


function, examples) of the pointed script function in the Help window.

User Guide... Open the Automation Users Guide *.pdf4.

Edit help Invokes the Script Help Editor window where the help text of commands can
be edited.

Complete help Invokes the Script Help Editor window where the help text of commands can
be edited.

Diff help Invokes the Script Help Diff/Editor window where two *.xml help files can be
compared.

BETA CAE Systems 75 META Automation User’s Guide


4. Scripting

4.2.3. Standard toolbar


New (Ctrl+N), File > New...:
Creates a named Untitled, script file. A new tab in the editor window is added. The
name of the script in the tab is followed by an asterisk (*) until the script is saved.

Open (Ctrl+O), File > Open...:


Invokes the file manager to browse for a script file (i.e. *.bs, *.c, *.ses) to open.
Script opens in a new tab in Editor window. There is no restriction regarding how
many scripts can be remained opened simultaneously.

Save (Ctrl+S), File > Save:


Saves the current edited script. By default scripts are saved in the working
directory.

Save As (Ctrl+Shift+S), File > Save As...:


Invokes the file manager to save the currently edited script.

Save All, File > Save All:


Saves all open scripts.

Print (Ctrl+P), File > Print:


Invokes the Print window to define the printing options and print the current script.

Undo, Redo (Ctrl+Z, Ctrl+Y), Edit > Undo, Edit > Redo:
Undo and redo editing actions in the current edited script.

Cut, Copy, Paste (Ctrl+X, Ctrl+C, Ctrl+V), Edit > Cut, Edit > Copy, Edit > Paste:
Cut, Copy and Paste script text within and between windows.

Find (Ctrl+F), Edit > Find:


Invokes the Find window to search for a word in the script. If a text is selected in
the script editor then it is automatically added in the field.

Parse file (F7), Project > Parse file:


Examines the script, analyzing for possible syntax errors that will be printed in the
Output tab.

Run (F5), Debug > Run:


Runs the script without stopping at breakpoints. While in debugging mode, it starts
the automatic execution of the script until next breakpoint.

Debug (Shift+F5), Debug > Debug:


Run the script in debugging mode. The execution stops if a breakpoint is met.

Step (F10), Debug > Step:


Execute one line of script stopping on the next line of script in the same source
file. This will run any functions encountered until the above condition is met.

Step into (F11), Debug > Step into:


Execute exactly one line of script. This means that will "Step into" the current
BETA CAE Systems 76 META Automation User’s Guide
4. Scripting

function, if necessary.

Step out (F12), Debug > Step out:


Run to the end of the current function.

Breakpoint (F9), Debug > Breakpoint:


Add / Remove a breakpoint in the selected line(s). Line should not be emty.

Clear Breakpoints, Debug > Clear breakpoints:


Clears all set breakpoints.

Watch window, View > Watch window:


Controls the visibility of Watch window.

4.2.4. Editor
4.2.4.1. Interface

In Editor all opened scripts are tabbed. The Immediate tab is always accessible.

Tabs Each script is placed under a different tab. All functions are applied to the
active tab.
If a script is not saved and asterisk is present next to its name.
Single click on a tab to activate it.
Use the arrows on the right to scroll between tabs.

BETA CAE Systems 77 META Automation User’s Guide


4. Scripting

Lines All lines are numbered.


Lines where a breakpoint is set are highlighted pink.
Lines that are going to be executed (while in debugging mode) are colored
light blue.

Text The script code text is colored according to the type of the word.
While the cursor is in line with a command, guide about the syntax is displayed
in the Status bar. Also information about the types of the parameters of the
typed function are displayed in the Function list > Dynamic help tab.

Controls

left mouse button Clicking sequentially selects the whole word and next the whole line of code.

F1 While the cursor points on a function the corresponding function‟s help text is
displayed in the Help window.

Context menu functions

Add function The following code lines are added to the script body to write a function:
def <func_name>(<args>)
{
// add function code here
return 0;
}

Add watch Available only when the cursor points to a variable‟s name. Adds the variable
in the Watch window > variables list, in order to monitor it during debugging.

Make snippet Available only when a script part is selected. Invokes the Make new snippet
window. The selected script is added in the contents of a new snippet.

Comment out Available only when a script part is selected. The selected code is comment
out the script body between /* */. The enclosed script code is colored
gray and is not executed when running the script.

Uncomment code Available only when a script part is selected. Uncomment the selected code if
it is commented out.

BETA CAE Systems 78 META Automation User’s Guide


4. Scripting

4.2.4.2. The Immediate tab

The immediate tab is used for testing functions or a few lines of code.
For simplicity, the code inside is not allowed to have any def statement. Consequently, any variable
that is written in the global section of the script has no sense.
Scripts made in the immediate environment can be executed normally.
Next follows a code that tests how many models exist. written for both Immediate and script tab:

Code in Immediate tab Identical code in a script tab

#include "meta_structs" #include "meta_structs"


all_models = Models(); def main()
Print(MatLen(all_models)); {
all_models = Models();
Print(MatLen(all_models));
}

4.2.5. META Window Designer

The META Window Designer uses BCGUI (BETA C interface Graphical User Interface) library and
supports creation of a graphical interface trough which scripts can be called and controlled. This
way a graphical interactive environment can be built to run a complete project automatically and
interactively (see 4.6. BCGUIDesigner, pg.225).

BETA CAE Systems 79 META Automation User’s Guide


4. Scripting

4.2.6. Snippets
Snippets are sections of code or complete functions that can be created or loaded anytime through
the Script Editor. The first time a snippet is created, it is saved without any warning in an xml file
called snippets.xml, located in HOME directory and can hold separately any number of snippets. In
this way a library of mostly used functions or codes can created.
The Select snippet depicted following is accesses through Tools > Code snippets
and is invoked generally to import snippets in the current edited script.
The Make new snippet window accessed through Tools > Make snippet
follows the same functionality except of importing a snipped into the script. Thus only edit and
creation of snippets is possible.

Snippet name Displays the name of the selected snipped in the list. Also the name of a new
snipped can typed.

Snippets list The available snippets are listed. They are divided into two groups: ANSA and
META snippets depending the on the source of the snippet that is created.

Code area The script code lines of the selected snipped are displayed. Editing of the snippet
is allowed and follows the general rules that apply in Script Editor.

Delete Deletes the selected snippet.

Save Saves the listed snippets in the default snippets.xml file, located in HOME
directory.
In case a snippet name is set in the Snippet name field then it is also created and
added into the snippets list.

Import Passes the selected snippet in the list to the current script.

Exit Closes the snippet window

BETA CAE Systems 80 META Automation User’s Guide


4. Scripting

4.2.7. Select font

Font Set the font.

Font style Set the style of font (i.e. Normal, Italic, Bold, Bold Italic)

Size Set the size of the font.

Effect Apply an effect in the font (i.e. Strikeout, Underline)

Sample Display a font preview.

Script Filter the fonts to match ethnic script criteria.

BETA CAE Systems 81 META Automation User’s Guide


4. Scripting

4.2.8. Editor colors

Color definition Pressing the buttons the Select color window opens to define the color of the
buttons mentioned Script Editor layout.
There are thirteen coloring codes in the Script Editor. The button‟s color
represents the currently selected color for the corresponding layout.

Sample code Display a preview of the current display color mode of Script Editor.

The default coloring code of the script text is:


1. Black: Normal Text. Everything that is not a language, a keyword function, a comment, a
number or a string.
2. Red: Keywords. The language keyword functions (e.g. def, for, if, else, goto etc).
3. Light Blue: Strings.
4. Purple: Numbers.
5. Gray: Commented code.

BETA CAE Systems 82 META Automation User’s Guide


4. Scripting

4.2.9. How to (Script Editor)


4.2.9.1. Monitor variables

In the following script monitor the declared variables


// BETA script
#include "meta_structs"
def main()
{
number_to_multiply=4;
mult(number_to_multiply);
}

def mult(int number)


{
for(multiplier=1; multiplier<11; multiplier++){
result=multiplier*number;
print(multiplier+" * "+number+" = "+result);
}
}

2 3
4

1. Click on the Watch window button to make visible the Watch window and switch to variables
tab or select View > Watch window.
2. Move the cursor to, or select a variable‟s text (e.g. multiplier).
3. In the context menu select Add watch: multi::multiplier.
The multiplier variable is added in the variables list in Watch window.
Pointing on a variable the Add watch prompt option, follows the syntax:
Add watch:<function name>:: <variable name>
4. Repeat the same for the other variables.
While in debugging mode the variables value will be monitored in the Watch window.

BETA CAE Systems 83 META Automation User’s Guide


4. Scripting

4.2.9.2. Debug scripts

Debugging is the line by line manually execution of a code. In order to debug a script at least one
breakpoint should be set.
Consider that the aforementioned script have to debugged.

3 4 1

th
1. Point on the 5 line and press the Breakpoint button or (F9).
The line is highlighted pink.
th
2. Repeat the same, pointing on the 12 line.
3. Press the Run button or (F5).
The script output results will displayed in the Output window.
No debugging took place. Run function ignores all set breakpoints.
4. Press the Debug button or (Shift + F5).
Script will be executed till the first breakpoint is met (line 5).
The current line (the line where the breakpoint is set), which is to be executed next, is
highlighted light blue.
At this state, script is running in debugging mode. The script can be run line by line. While in
debugging mode, all messages are displayed in the Output tab of the Output window.
5. Press the Run button or (F5).
The script will executed till the next breakpoint is reached
6. Press the Run button or (F5) multiple times till the execution of script is finished and watch the
values of monitored variables.

BETA CAE Systems 84 META Automation User’s Guide


4. Scripting

7 8 9

Make sure the execution of script is finished and point into the script.
7. Press the Debug button or (Shift + F5).
8. Press the Step into button or (F11) to go into a sub function. Press the F11 key multiple times
and watch the values of monitored variables as well the Output window.
9. Press the Step out button or (F12) to step out the sub function. Continue pressing the F12 key
till the end of execution of the script.

The script can be run line by line by pressing the Step button (F10) . This way debugging
proceeds only through the lines of the main function, without stepping into the sub functions.
While in debugging mode, at any time the Script Editor window can be minimized to review the
results of the commands applied up to the current line reflected in the corresponding META
windows.

BETA CAE Systems 85 META Automation User’s Guide


4. Scripting

4.2.9.3 Create and handle projects

A project is a collection of user scripts, organized in a way that they can be accessed anytime
through the Script Editor. In the project environment, embedded in Script Editor, two distinctive
capabilities are offered:
- The creation of an xml project file, holding references to scripts‟ file paths.
- The creation of a main script with #projectfile statements. The files that are referenced in this
script are those that are included in the xml file.
The project environment can be activated through Window > Project window.

1. Press the Project > New...


Alternatively select the New Project
option of context menu of Project
window.
2. In the New Project window enter the
2 project‟s name and browse a path for it.
3. Press OK
3
A file, named MyProject.bpr is created in the selected folder. This is the project file and initially
has the following form:
<?xml version="1.0" encoding="UTF-8"?>
<BetaCAE_script_project>
<appendExtension>true</appendExtension>
<projectName>MyProject</projectName>
</BetaCAE_script_project>

4. Also, in Project window, the created


project is listed. Expanding the project,
two categories can be seen. The Include
files that can host auxiliary files that are
added normally in the project file but are
not incorporated in the main script. And
the Source files that are the basic files
4 that will be referenced either in the
project file or in the main script.
5 5. In the Project window, select the context
menu option Add existing file and
browse for one or more source script
files to add.
Alternatively select the corresponding
option in context menu of Source files
bracket.

BETA CAE Systems 86 META Automation User’s Guide


4. Scripting

6. Double click on the added source file. Its


contents are displayed in the Editor
window.
7. Select Project > Save project, to update
the xml project file.
In case where some of the added files use
include files that are also liked to be added in
6 the project, this can be done selecting the
respective option Add existing include in the
context menu of Include files branch. The
selected file will be added under the Include
files category.

8. In the Project window, select the context


menu option Add new file and in the
Select file type window make a
selection.
Alternatively select the corresponding
option in context menu of Source files
bracket.
Anew untitled script tab to edit opens
8 and also the new file is added under the
Source files branch.

9. In the Project window, select the context


menu option Export main script and in
the Select file type window make a
selection.
Alternatively select
Project > Export main script.
Automatically, a *.bs file will be created in the
same directory where the project was saved.
All the source files will be added in the main
script using the #projectfile statement.
No include file will be added in the main
script.

BETA CAE Systems 87 META Automation User’s Guide


4. Scripting

4.3. Python Scripting

4.3.1. Introduction
4.3.1.1. Introduction

The META Scripting Interface is an extension of the Python Programming Language.

4.3.1.2. The Python Programming Language

Python is a general purpose, object-oriented, interpreted high-level programming language. It is


known as a clear and highly readable language with a large and comprehensive standard library.
Python can be utilized for object-oriented programming and for functional programming. It
implements dynamic typing system and automatic memory management.

4.3.1.3. Python Version

The Python version that is used by META is Python v3.3.0

4.3.1.4. Python Documentation

This guide is intended to provide a quick introduction of Python 3 and to describe the META python
module. For more information about the capabilities of the Python programming language please
refer to the online language documentation provided by the Python Software Foundation
(www.python.org). In addition there are numerous of books and resources that are available from
third party vendors and contributors.

4.3.2. Short Introduction to Python


4.3.2.1. Data types

The data type determines the kind of data that a variable or a function can hold. Data types include
integer or floating point numbers, strings, matrices etc, as well as user defined types. The following
paragraphs describe the Python built-in data types

4.3.2.1.1. Numbers

Integer
The integer data type is used by variables that can only have whole numbers as values.
my_var = 10

Floating Point
Values that are not integral are stored as floating point numbers. A floating point variable can be
expressed as a decimal number such as 112.5, or with an exponent such as 1.125E2. In the latter
case the decimal part is multiplied by the power of 10 after the E symbol.
A floating point must contain a decimal point, or an exponent or both.
my_var = 112.5

BETA CAE Systems 88 META Automation User’s Guide


4. Scripting

Complex
c = 4+3j

Bool
b = True

4.3.2.1.2. Sequences Data Types

A sequence is an object containing a series of objects. There are three types of built in sequences
in Python. These are the list, tuple and string.

String
A string, is declared as a series of printable text characters representing human readable stuff. A
string value is enclosed in quotes (e.g. "this is a string") and can be assigned to any variable for
storage and easy access. String variables are represented as lists of characters.

s = 'a string'
s = "a string"

List
Lists is an ordered collection object type. A list can contain any type of an object such as integer,
float string, other lists, custom objects etc. Lists are mutable objects. Objects can be added,
removed and their order can be changed. The List object is similar to the matrix of the BETA
Scripting language.

my_list = [1, 2.3, 'world', [2, 3.7, 8.5]]


my_list.append('python')
print('result: '+my_list[2])

Tuple
Tuple objects simple groups of objects. They are like lists but are immutable. They are constructed
once and no further change can be done to the object. No new objects can be added, nor can they
be removed or reordered.

my_tuple = (2.5, 7.9, 'python', (4.8, 'earth'))


print('result: '+my_tuple[3][1])

BETA CAE Systems 89 META Automation User’s Guide


4. Scripting

Dictionary
Dictionaries are unordered collections. In dictionaries items are stored and fetched by key instead
of by positional offset. Indexing a dictionary is a very fast and powerful operation. Dictionaries are
the equivalent to Maps of the BETA Scripting Language.

my_dict = {'planet':'earth', 'world':3, 'test':10}


print('result: '+my_dict['world'])

my_dict = {'planet':'earth', 'world':3, 'nest':{'test':10, 'entity':10}}


print('result: '+my_dict['nest']['entity'])

4.3.2.1.3. The del statement

The del statement is used to delete references

del data[k]
del data[i:j]
del obj.attr
del variable

4.3.2.1.4. The none Object


Python provides a special object called None, which is always considered to be false. It is a special
data type and it serves as an empty placeholder.

4.3.2.2. Modules and Namespaces


4.3.2.2.1. Module

The module-based model in python is the core idea behind program architecture. Every file of
Python source code is a module. Other python files can access the items defined in a module by
importing that module. Import operations load another python file and allow access to that file's
contents.

import math
import os

def main():
x = math.sqrt(9)
print('The square root is: '+str(x))
os.system('ECHO the square root of 9 is: '+str(x))

BETA CAE Systems 90 META Automation User’s Guide


4. Scripting

4.3.2.2.2. Namespaces

Each module file is a self-contained package of variables (Namespaces). One module file cannot
see the names of another module unless it is imported to that file, thus minimizing name collisions,
even if variables are spelled the same way

4.3.2.3. Program scope

In computer programming, a scope is the context within a computer program in which a variable
name or other identifier is valid and can be used, or within which a declaration has effect. Outside
of the scope of a variable name, the variable's value may still be stored, and may even be
accessible in some way, but the name does not refer to it; that is, the name is not bound to the
variable's storage.

4.3.2.4. If statements and branching


4.3.2.4.1. The "if-else" blocks and the logical operators

The if statement is the basic decision statement of a script. Its operation is based on the evaluation
of a condition that will yield a result that is either true or false. If the condition is true (i.e. not equal
to 0), then the if-block of statements is executed. If the condition is false, then the else-block of
statements is executed. The if statement general form is:

if condition:
statement

The alternative line of execution is created with elif and else:

if condition:
statement
elif condition:
statement
else:
statement

BETA CAE Systems 91 META Automation User’s Guide


4. Scripting

Since the condition is interpreted as a logical operator, the operators used for its expression are the
logical relational operators. Such operators are summarized in the table below:

Operator Meaning
< less than
<= less than or equal to
> greater than
>= greater than or equal to
== equal to
!= not equal to
or Logical OR
and Logical AND
not Logical NOT

4.3.2.5. Loop statements

A loop comprises of a block of statements that are executed repetitively. When the end of the loop
is reached, the block is repeated from the start of the loop.

4.3.2.5.1. The for statement

The for statement allows the iteration over the elements of a sequence. for loops do not maintain
any explicit counter. The general form of the statement is:

for <item> in <sequence>:


do something to <item>

An example of the statement use is given below:

all_properties = ["PSHELL","PCOMP","PBAR","PBEAM","PELAS"]
for property in all_properties:
print(property)

the result is
PSHELL
PCOMP
PBAR
PBEAM
PELAS

BETA CAE Systems 92 META Automation User’s Guide


4. Scripting

4.3.2.5.2. The while statement

The while statement introduces a conditional exit loop. The program executes the specified
statements repetitively for as long as the given condition remains true (i.e. not equal to 0). Its
general form is:

while (condition):
body-statement

If operators are to be used for the expression of the condition, these must be of logical relational
type.

a = 0
while a<3:
print(a)
a += 1

the above result will be something like


0
1
2

4.3.2.5.3. The continue, break and pass statements

The continue and break statements can be used to redirect the execution order of a loop. The
break statement allows the termination of a loop regardless of the loop control condition. In other
words it can lead to an unconditional branching. A typical example is given below:

a = 0
while a<5:
print(a)
a += 1
if a == 3:
break;

In this case the result would be:


0
1
2

The continue statement jumps back to the beginning of the loop‟s block to begin the next iteration.
BETA CAE Systems 93 META Automation User’s Guide
4. Scripting

Thus, it omits a certain block of statements. A typical example is given below:

a = 0
while a<5:
a += 1
if a == 3:
continue
print(a)

In this case the result would be:


1
2
4

4.3.2.6. Handling lists


4.3.2.6.1. Set data in a list

To set some data to a specific position in a matrix:

my_list = list()
my_list.append('hello')
my_list.append('world')

To specify all list members at once

m = [10, 7, 9]

List members can be even other lists. Thus, a definition like the following would form a 3x3 list:

my_list = [[10,7,9],
[5,2,17],
[6,12,55]]

my_list.remove(0) #Remove item from a list


my_list.insert(1, [2,5,7]) #Insert item in index

BETA CAE Systems 94 META Automation User’s Guide


4. Scripting

4.3.2.6.2. Retrieve values from a list

To retrieve a value of a specific member of a list, the user must provide the corresponding index
operator:

val = my_list[0]

For the 3x3 list given above:

val = my_list[1][0]

will assign to val the value of 5.

4.3.2.6.3. Retrieve the length of a list

The function len returns the length of a matrix:

length = len(m)

In case of a 2 dimension list the function will return the number of rows. In order to get the number
of columns of a row, ask the length of a specific row, e.g

C = [[20,7,9], [5,4,17]]
length = len(C[1])

In the above example, the number of columns for the second row will be 3.

4.3.2.7. Handling Strings


4.3.2.7.1. Adding strings

Characters may be assigned to string variables, using statements similar to those of numeric types:

property = 'PSHELL'
mat_name = 'steel_105'

The operators that can be used to form expressions between string data types are:
+%
Both of them generate a string as the result of the concatenation of two or more strings, e.g.

property = 'PSHELL'
id = 'with id 1'

BETA CAE Systems 95 META Automation User’s Guide


4. Scripting

property_id = property + id

4.3.2.7.2. Handling strings as matrices

Strings can be treated as matrices, so any part of them can be isolated without the use of any built
in function. A string corresponds to a matrix, which has a length equal to the number of characters
that comprise it. Each character corresponds to a matrix member.
Example
str = 'Bumber_Front'
The above string has 12 characters.
We can get any part of the string by using the indices of the characters. Here are some examples:
val = str[0:6] #This will get the "Bumber"
val = str[7:12] #This will get the "Front"
val = str[7:8] #This will get the character "F"
val = str[6:7] #This will get the character "_"
val = str[2:8] #This will get the "mber_F"
val = str[4:] #This will ge the "er_Front"
val = str[:7] #This will get the "Bumber_"

The length of a string (an integer) can be obtained calling the function len:
length = len(str)

4.3.2.8. Handling Dictionaries


4.3.2.8.1. Set keys and data in a Dictionary

When a Dictionary is created and initialized, it is originally empty.

myDictionary = dict()
#or
myDictionary = {}

To set some data to the dictionary:

myDictionary = {'Name':'aluminum', 'pid':19987}

Alternatively:

myDictionary['Name'] = 'aluminum'
myDictionary['pid'] = 19987

since the former node uses a string-type key and the latter node uses a numeric key. Note that
when maps are used as keys, they are sorted according to the number of nodes they have, with
larger maps taking precedence over smaller maps.

4.3.2.8.2. Retrieve a node value

BETA CAE Systems 96 META Automation User’s Guide


4. Scripting

To retrieve a value of a specific key, the user must provide the corresponding key:

i = myDictionary['Name']
print(i)

4.3.2.8.3. Delete a node

Dictionary elements can be deleted using the del statement:

del myDictionary['Name']

4.3.2.8.4. Iteration through the data in a map

In order to iterate through a Dictionary:

for key, value in myDictionary.items():


print(key)
print(values)

4.3.2.8.5. Check the existence of a key

To check the existence of a key inside a dictionary, use:


if 'pid' in myDictionary:
print('OK')

4.3.2.8.6. Identify the number of map nodes

To identify how many nodes a dictionary contains:

length = len(myDictionary)

4.3.2.8.7. Destroy the dictionary and release memory

In order to delete a dictionary:

del myDictionary

4.3.2.9. User functions

User functions allow to group a set of operations into a compact unit that can be easily and
repeatedly accessed. The repetitive use of functions saves much time while reduces the chances of
error. Each user function is given a name, optionally uses some input parameters (arguments) and
returns the results as output parameters.

4.3.2.9.1. Definition

BETA CAE Systems 97 META Automation User’s Guide


4. Scripting

User functions are defined using the def statement. This statement is followed by the function
name. The rest of the code must be indented. A typical function has the form:
def main(list of arguments if exist):
.......
Statement
.......

4.3.2.9.2. Returning data from functions

Since the target of each sub-function is to perform a certain task, there must be a way to notify the
main function that called it for the result of the procedure it performed.
The communication between the functions can be achieved through the return command. This
command can be used anywhere in the code and is followed by any data. A function that calls
another function can store the returned value in an output argument or even can ignore it.
Functions that don‟t return anything are executed normally and may not use the return command.
Equivalent, they can return a dummy value.

Return value No return Return dummy value


def main(): def main(): def main():
a = 100 a = 100 a = 100
b = 50 b = 50 b = 50
result= substr(a,b) result = substr(a,b) result = substr(a,b)
print(result) print(result) print(result)

def substr(a, b): def substr(a, b): def substr(a, b):


res = a-b res = a-b res = a-b
return res return 1

4.3.2.9.3. Argument Matching Modes


Python provides additional techniques that alter the way arguments are passed to the called
functions. These are optional but allow the writing of code that supports very flexible calling
patterns. The table bellow describes these patterns.

Syntax Location Interpretation


func(value) Caller Normal arguments matched by position
func(name=valve) Caller Keyword (named) arguments, matched by name
func(*name) Caller Pass all objects in name as individual positional
arguments
func(**name) Caller Pass all key/values in name as individual keywords
arguments
def func(value) Function Normal arguments matched by position
def func(name=valve) Function Default argument value, if not passed in the call
def func(*name) Function Matches and collects positional arguments in a tuple
def func(**name) Function Matches and collects keyword arguments in a
dictionary

Note: The named arguments pattern is widely supported in the META module.

4.3.2.9.4. Help text and comments

The common practice has proven that even the most experienced programmer needs to keep some
BETA CAE Systems 98 META Automation User’s Guide
4. Scripting

comments in order for the code to be readable and understandable. InPython comments can be
added after the # sign. Comments between three pairs of quotes (“””Comment”””), under the
function declaration, define a python docstring (see python documentation for more information)

# PYTHON script
import meta
from meta import parts

def fun1():
"""Docstring for function help"""
# Collect Parts
model_id = 0
pids = parts.Parts(model_id)
# Print the id of each Part
for pid in pids:
print(pid.id) #Print the id

4.3.2.9.5. Global variables

In contrast to local variables, global variables are valid throughout the program, so they can be
accessed and changed by any individual function of the program. Global variables must be
declared prior to the definition of any function (global section).

myInteger = 12
myFloat = 5.78 #myFloat and myInteger are now global for all
functions

def main():
global myInteger
print('initial value: '+str(myInteger))
myInteger = 7
print('Final value: '+str(myInteger))

def fun():
global myInteger
sum = myInteger + 7
global myFloat
myFloat += 1.0

4.3.2.9.6. Program variables

For storing and retrieving strings as long as the META session is opened, the functions
BetaSetVariable, BetaGetVariable, MetaSetVariable and MetaGetVariable must be used. Any
variables defined this way are considered as part of the program and thus they are accessible by
any script. In META vairables only strings can be stored, as META variables are also accessible
from other META tools as well. In Beta variables bytes objects are stored, so respective python
library funtions must be used to generate the objects and then retrieve the values from them.

To set up program variables, follow the example below:

import meta
from meta import *

BETA CAE Systems 99 META Automation User’s Guide


4. Scripting

def main():
utils.MetaSetVariable('program_var1', '10')
val1 = utils.MetaGetVariable('program_var1')
print('val1: '+val1)

META variables' values can be cleared using the META command opt var delete.

import pickle
import meta
from meta import session

def main():
p = 1
v = pickle.dumps(p)
session.BetaSetVariable('a', v)
v = session.BetaGetVariable('a')
p = pickle.loads(v)
print(p)

4.3.2.10. Handling exceptions

Exception handling is the process of responding to the occurrence, during computation, of


exceptions – anomalous or exceptional situations requiring special processing – often changing the
normal flow of program execution. It is provided by specialized programming language constructs
or computer hardware mechanisms.

In python exceptions are handled with try and except statements. Any code that runs inside the try
block and raises an exception, the exception can be handled in the catch block.

try:
res = x / y
except DivisionByZero:
print('division by zero')
else:
print('result: '+str(res))

try:
val = myDict['Name']
except error:
print('Key Name does not exist')

4.3.2.11. Object Oriented Programming Basics

In object oriented programming, object is an instance of Class. A class is construct that


encapsulates state and behaviour. By state we mean the class's data (attributes/variables). By
behaviour we mean the class's methods (functions). An example of a class is show below:

import math
BETA CAE Systems 100 META Automation User’s Guide
4. Scripting

class Point:
"""A class that stores the x,y,z coordinates of a a point,
with a method that calculates the distance from the origin
and a method that prints the description of the class"""
def __init__(self, x_coord, y_coord, z_coord):
"""This is the constructor of the class"""
self.x = x_coord
self.y = y_coord
self.z = z_coord

def distFromOrigin(self):
"""Method that calculates the distancefrom the origin
dist = math.sqrt(self.x**2 + self.y**2 + self.z**2)
return dist

def __repr__(self):
print('A point with X: '+str(self.x)+' Y: '+str(self.y)+' Z:
'str(self.x))

def main():
myPoint = Point(100.57, 786.46, 436,89) #creation of class
instance myPoint

print(myPoint.x) #access the value of attribute x

myPoint.x = 120.74 #assign new value

distance = myPoint.distFromOrigin()
print('The distance from the origin is: '+str(distance))

4.3.2.12. Organizing scripts


4.3.2.12.1. Including files

In python modules are imported with the import statement. At the top of your python file import the
desired modules like in the example shown below

import math
import sys
import meta

The import statement cannot take a full path. It looks directly into the python home directory. If a
module that needs to be imported resides outside the python home the following method needs to
be called.

import sys
sys.path.append()

An example of this:

BETA CAE Systems 101 META Automation User’s Guide


4. Scripting

import sys
sys.path.append(/home/myHome/myLibrary.py)
import myLibrary

Note: Please refer to the official Python 3 documentation for more information on modules
management

4.3.2.12.2. Including files using the ImportCode Function

Since the target of each sub-function is to perform a certain task, there must be a way to notify the
main function that called it for the result of the procedure it performed.
The communication between the functions can be achieved through the return command. This
command can be used anywhere in the code and is followed by any data. A function that calls
another function can store the returned value in an output argument or even can ignore it.
Functions that don‟t return anything are executed normally and may not use the return command.
Equivalent, they can return a dummy value.

4.3.3. META session commands within scripts


Inside a script, any META command can be applied. This can be achieved through the following
command:
MetaCommand (string command)
The command has to be input as a string, so it has to be placed between single or double quotation
marks or between three double quotation marks, e.g.
MetaCommand ('color background red')
If the command already contains quotation marks the single quote or the three double quotes
should be used to declare the start and the end of the string.
# PYTHON script
import meta
from meta import utils

def main():
utils.MetaCommand('write tif "C:/ses/ses2/test.tif" 0.9')
Any string operation is acceptable for the string given as argument for the MetaCommand.
So, the values of variables can also be used:
file = "/home/demo/one folder/image1.tif"
MetaCommand ('write tif "'+file+'" 0.9')
command = 'write tif "'+file+'" 0.9'
MetaCommand (command)

BETA CAE Systems 102 META Automation User’s Guide


4. Scripting

4.3.4. Interacting with MΕΤΑ


4.3.4.1. General

The basic idea behind the scripting language is to automate many repetitive and tedious
procedures with the minimum user interaction and to perform specific tasks that are not covered by
the standard META commands and META session capabilities. Some of the tasks that can be
performed within scripting language are the following:
- Extracting any type of information from an already loaded model (data from nodes, elements,
boundary elements, materials, models, coordinate systems and groups).
- Access and manipulate data from META entities like annotations, groups, cut planes and
isofunctions.
- Manipulating 2D plots: create and select curves, access data from curves and their points and
modify them.
- Creating new results (deformation-scalar-vector) on nodes and elements with custom calculated
data.
- Creating and manipulate META 3D and 2D windows.
- Creating user-defined windows.
- Manipulating files and directories.
- Reading and writing ASCII and binary files.
- Creating and handling data in XML form.
- Use of session commands.
- Use of system commands.
- Running automatically (after launching META) a series of functions.
- Communication with the interface (File Manager functions, Pick functions).
All these tasks that can interact with the model and META entities data are controlled through a
series of META specific functions.
In order to use a META specific function in Python, the relevant module has to be imported from
META. The names of the modules are the available categories in the drop-down menu in tab
Library in Functions List window. The functions are then called as methods of the imported module.
In Python the meta structs are objects and their attributes can be used directly without having to
define the variable type first.

For example to print the ids and names of the visible parts
# PYTHON script
import meta
from meta import parts

def main():
pids = parts.VisibleParts()
for pid in pids:
print('Id: '+str(pid.id)+' Name: '+pid.name)

BETA CAE Systems 103 META Automation User’s Guide


4. Scripting

4.3.4.2. Handling data


4.3.4.2.1. Introduction

Using the available META modules it is possible to access and manipulate the data of the various
METAentities. Contrary to BETA Scripting, the attributes of the META objects can be accessed
directly without the need to define the object type first (as it is needed to define the META struct
first).

4.3.4.2.2. META classes

The available META classes are the following.


The description of each class ant the attributes of the class objects can be found in Function List of
Script Editor under the respective category relevant to each class
Class Category
Annotation annotations
AnnotationGroup annotations
Boundary boundaries
CentroidScalar results
CentroidVector results
Color windows
Connection connections
CoordSystem coordsystems
CornerScalar results
Curve plot2d
CurveGroup plot2d
Deformation results
Elem elements
ElemCoordSystem coordsystems
Group groups
Image visuals
Isofunction isofunctions
Material materials
Model models
NodalScalar results
NodalVector results
Node nodes
OverlayRun overlay
Page pages
Part parts
PartLayer parts
Plane planes
Plot plot2d
PlotAxis plot2d
Point plot2d
Resultset results
SpreadsheetCell spreadsheet
Video visuals
Window windows

BETA CAE Systems 104 META Automation User’s Guide


4. Scripting

4.3.4.2.3. Subclassing META classes

META classes can be subclassed as shown in the example in the description of each class in
Function List of Script Editor. An example is given below:
# PYTHON script
import meta
from meta import *

class MyModel(models.Model):
def __init__(self, r):
super(MyModel,self).__init__(
r.id,
r.name,
r.label,
r.deck,
r.active)
self.function_labels = models.FunctionLabelsOfModel(r.id)

def main():
model_id = 0
r = models.ModelById(model_id)
if r:
print(r.id, r.name, r.label, r.deck, r.active)
my_r = MyModel(r)
print(my_r.id, my_r.name, my_r.label, my_r.deck,
my_r.active, my_r.function_labels)

if __name__ == '__main__':
main()

4.3.4.3. Collect entities


4.3.4.3.1. Introduction

In META there is a separate group of script functions for META entities. For example, there are
Element functions to collect the elements, Node functions to collect the nodes, etc.
Additionally, there are the following generic functions CollectEntities to collect all the specified
entities that are loaded in META:

Function Description
CollectEntities Collect all existing entities of the specified type in the current
META session
CollectModelEntities Collect all existing entities of the specified type in a model
CollectWindowEntities Collect all existing entities of the specified type in a window

The types of entities that can be collected using these functions are:
ANNOTATIONs
BOUNDARIEs
COORDINATE SYSTEMs
CUT PLANEs
ELEMENTs (SHELLs, SOLIDs, BEAMs, etc)
GROUPs
BETA CAE Systems 105 META Automation User’s Guide
4. Scripting

ISOFUNCTIONs
MATERIALs
META WINDOW entities (WINDOWs, FRINGEs, COLORs)
MODELs
NODEs
PAGEs
PARTs
PLOT2d entites (PLOTs, CURVEs and POINTs)
RESULTSETs
FRINGEs
VISUAL entities (FRAMEs, IMAGEs, VIDEOs)

BETA CAE Systems 106 META Automation User’s Guide


4. Scripting

4.3.4.3.2. Collect entities of the database

For collecting all entities, the appropriate functions are the functions with just the type of the entities
to be collected, e.g. Annotations(), Boundaries(), LoadsOfBoundary(), Elements(), Nodes(), Parts(),
Models(), Groups(),Resultsets(), Connections(), CyclesList() etc. Please note that Groups refer to
the entities Parts/Groups of Part Manager, Includes, Boundaries, Connections, Sets
In the case of model entities, the model id is given as argument.
To access the entities directly according to their id, the list with the model objects can be converted
to a dictionary with the XxxListToDict() functions where the key is the entities' id, e.g.
AnnotationsListToDict(), ElementsListToDict(), etc.
# PYTHON script
import meta
from meta import parts

def main():
model_id = 0
all_parts = parts.Parts(model_id)
for p in all_parts:
print(p.id)
print(p.name)

dict_parts = parts.PartsListToDict(all_parts)
for key, p in dict_parts.items():
print(key)
print(p)

p = dict_parts[ 10 ] #Get directly part with id 10


print(p.name)

if(__name__ == '__main__'):
main()

To get the entities types of a model, the functions XxxTypeXxx() are available, e.g.
ElementsTypes(), CurvesTypesNastran(), DeformationTypes(), ScalarTypes(), VectorTypes() etc.

# PYTHON script
import meta
from meta import elements

def main():
model_id = 0
all_types = elements.ElementsTypes(model_id)
for element_type in all_types:
print(element_type)

if(__name__ == '__main__'):
main()

To get the available results in a database the functions XxxTypes(), XxxTypesAll(), XxxTypesList()
are available, e.g. DeformationTypes(), DeformationTypesAll(), DeformationTypesList(),
ScalarTypesList(), VectorTypesList(), etc. To retrieve deformation results types of a database the
following can be used.

BETA CAE Systems 107 META Automation User’s Guide


4. Scripting

# PYTHON script
import meta
from meta import results

def main():
filename = 'X:/project.metadb'
deck = 'METADB'
all_types = results.DeformationTypes(filename, deck)
for one_type in all_types:
total = len(one_type)
deform_type = one_type[0] # Deformation type
print(deform_type)
for i in range(1,total):
state = one_type[i]
print(state)
print(i) # Id of the state

if(__name__ == '__main__'):
main()

For curves types of Dyna, Pamcrash and Radios files the functions
CurvesTypesDynaWithNames(), CurvesTypesPamcrashWithNames() and
CurvesTypesRadiosWithNames() are available to get also their name.

4.3.4.3.3. Collect entities according to their attributes (results, name, id, type, position,
comments, failure, free, outer)

There are specific functions in order to collect entities according to one of their attributes, e.g.
NodesByName(), NodesByField10(), ElementById(), CurvesByName(), ElementsByType(),
FailedElements, FreeNodes(), OuterElements(), FollowNodes() etc.
# PYTHON script
import meta
from meta import parts
from meta import constants

def main():
model_id = 0
part_type =constants.PSHELL
collected_parts = parts.PartsByType(model_id, part_type)
for p in collected_parts:
print(p.id,p.type,p.subtype,p.visible,p.name,p.mat_id,
p.shell_thick,p.model_id)

if(__name__ == '__main__'):
main()
When the function returns only one entity (e.g. ElementById()), then it returns the meta object of
this entity. When it may return more than one entities (e.g. ElementsByType()), then it always
returns a matrix with meta objects(even when only one entity is returned).
For entities that need to be collected and which are neighbors of other entities, the functions
NeighbourElements(),NeighbourMaterials(),NeighbourParts() etc can be used. Neighboring entities
are those which are directly attached to the specified entity or calculated by the solver.
For entities that need to be collected according to their nearest relative position to one given point,
the functions NearestNodeOfPart, NearestNodeOfGroup, NearestElementOfPart,

BETA CAE Systems 108 META Automation User’s Guide


4. Scripting

NearestElementOfGroup, NearestNodeOfMaterial, NearestElementOfMaterial etc can be used.


When entities need to be collected according to results (deformation, scalar, vector) or according to
more advanced filters, then the functions AdvFiltersOnXxx() and XxxFromAdvFilters() can be used,
e.g. AdvFiltersOnNodes(), AdvFiltersOnPoints, ElementsFromAdvFilters(), etc.. The difference
between AdvFiltersXxx() and XxxFromAdvFilters() functions is that in AdvFiltersXxx() the filters are
given as a string argument to the functions, whereas in XxxFromAdvFilters() the execution of the
script will stop and a window will open in order for the user to specify the advanced filters.
An easy way to build the string argument with the advanced filters for AdvFiltersXxx() is to apply an
iFilter from GUI inside a META session. The string, that corresponds to the filters selected, will be
shown as argument of the applied META command in the command line or in the current
META_post.ses.
# PYTHON script
import meta
from meta import results
from meta import elements

def main():
model_id = 0
adv_filters = list()
adv_filters.append('add:Parts:id:==1:Keep All')
adv_filters.append('intersect:Elements:centroidfuncmax::Max 3')
all_resultsets = results.Resultsets(model_id)
result = all_resultsets[1]
collected_elements = elements.AdvFiltersOnElements(model_id,
adv_filters, result)
for e in collected_elements:
print(e.id)

if(__name__ == '__main__'):
main()
# PYTHON script
import meta
from meta import plot2d

def main():
window_name = 'Window1'
collected_curves = plot2d.CurvesFromAdvFilters(window_name)
for c in collected_curves:
Print(c.id,c.name)

if(__name__ == '__main__'):
main()

BETA CAE Systems 109 META Automation User’s Guide


4. Scripting

4.3.4.3.4. Collect entities from other entities

There are many functions to collect entities from other entities, e.g. ElementsOfPart(),
NodesOfElement(), ElementsOfNode(), PartsOfGroup(), etc. There is a separate function for each
combination of the entities to collect and the entity that these belong to.
There are also functions that collect only the entities with specific attributes from other entities, e.g.
ElementsOfNodeByType(), VisiblePartsOfGroupByType(), SelectedCurvesOfWindow(), etc.
# PYTHON script
import meta
from meta import parts

def main():
model_id = 0
group_name = 'My_Group'
group_parts = parts.PartsOfGroup(model_id, group_name)
for p in group_parts:

print(p.id,p.type,p.subtype,p.visible,p.name,p.mat_id,p.shell_thic
k,p.model_id)

if(__name__ == '__main__'):
main()

4.3.4.3.5. Collect visible entities

For collecting the visible entities, the appropriate functions are the functions which include the word
visible, e.g. VisibleAnnotations(), VisibleElements(), VisibleCurves(), etc.
There are also functions that collect only the visible entities with specific attributes, or only the
visible entities from another entity, or only the visible entities with specific attributes from another
entity, e.g. VisibleElementsByType(), VisiblePartsOfGroup(), VisiblePartsOfGroupByType(),
VisibleCurvesOfPlot(), etc.
# PYTHON script
import meta
from meta import parts

def main():
model_id = 0
group_name = 'My_Group'
window_name = 'MetaPost'
visible_parts = parts.VisiblePartsOfGroup(model_id, group_name,
window_name)
for p in visible_parts:
print(p.id,p.type,p.subtype,p.visible,p.name,p.mat_id,
p.shell_thick,p.model_id)

if(__name__ == '__main__'):
main()

BETA CAE Systems 110 META Automation User’s Guide


4. Scripting

4.3.4.3.6. Collect identified entities

For getting only the identified entities of a model the respective functions are IdentifiedXxx(), e.g.
IdentifiedElements(), IdentifiedNodes(), IdentifiedParts(), etc.

4.3.4.3.7. Collect models information

There is a series of functions to get information from the loaded models, like NumOfNodes(),
NumOfModels(), NumOfPartsByType(), etc.
Also information only for the active Models, Pages, Plots, Plot axes and Windows can be retrieved
through the functions ActiveModels(), ActivePages(), ActivePlots(),ActivePlotAxes() and
ActiveWindows().
# PYTHON script
import meta
from meta import models

def main():
act_models = models.ActiveModels()
for r in act_models:
print(r.id,r.name,r.label,r.deck,r.active)

if(__name__ == '__main__'):
main()

Information about the currently loaded plot models (the plot files listed in the Read Results >
Curves > Files List) that may exist can be retrieved through the function PlotModels().
# PYTHON script
import meta
from meta import plot2d

def main():
plot_models = plot2d.PlotModels()
for pmod in plot_models:
print(pmod.id,pmod.deck,pmod.filename)

if(__name__ == '__main__'):
main()

4.3.4.3.8. Collect newly created entities

For collecting all newly created entities of a specific type, the respective functions to use are
CreateNewXxxStart(), ReportNewXxx() and CreateNewXxxEnd()
The syntax is, for example: CreateNewAnnotationsStart(), ReportNewAnnotations(),
CreateNewAnnotationsEnd(), etc.
This can be very useful in order to get the number and ids of entities created through filters or
session Commands.
For example, for curves created through the Curve Function User Defined the function
ReportNewXxx() will return the entity‟s structs without ending the recording of the created entities.

To collect newly created entities within a period, the functions to use are CollectNewXxxStart() and

BETA CAE Systems 111 META Automation User’s Guide


4. Scripting

CollectNewXxxEnd()
# PYTHON script
import meta
from meta import utils
from meta import plot2d

def main():
utils.MetaCommand('xyplot read lsdyna "Window1" "Z:/demo/nodout"
Node 1 Magnitude_of_acceleration_(ma)')
plot2d.CollectNewCurvesStart()
utils.MetaCommand('xyplot curve function userdef "Displacement
Difference" "c1.x" "c1.y-c2.y" "Window1"')
new_curves =plot2d.CollectNewCurvesEnd()
for c in new_curves:
print(c.id,c.name)

if(__name__ == '__main__'):
main()

4.3.4.3.9. Collect files and directories

For collecting files (of specific formats) or directories, the commands of the python os module
can be used. A simple example to get the files in a directory is the following:
# PYTHON script
import meta
import os

def main():
path = 'Z:/demo'
files = os.listdir(path)
for f in files:
print(f)

if(__name__ == '__main__'):
main()
An example to get the installation directory is:
# PYTHON script
import meta
import os
from meta import constants

def main():
print(os.path.realpath(constants.app_root_dir))

if __name__ == '__main__':
main()#

4.3.4.3.10. Collect view parameters

For collecting view parameters, the functions XxxOfView() can be used. An example is the
following:
# PYTHON script
import meta
from meta import windows
BETA CAE Systems 112 META Automation User’s Guide
4. Scripting

from meta import utils

def main():
window_name = 'MetaPost'
view_name = 'view0'

#Save view
utils.MetaCommand('view save "'+view_name+'"')

#Get view parameters


camera_position = windows.CameraPositionOfView(window_name,
view_name)
reference_position = windows.ReferencePositionOfView(window_name,
view_name)
up_vector = windows.UpVectorOfView(window_name, view_name)
front_clipping_distance =
windows.FrontClippingDistanceOfView(window_name, view_name)
back_clipping_distance =
windows.BackClippingDistanceOfView(window_name, view_name)
viewing_angle = windows.ViewingAngleOfView(window_name, view_name)
perspective_mode = windows.PerspectiveModeOfView(window_name,
view_name)

#Change view parameters


camera_position[ 0 ] = camera_position[ 0 ] + 100.0

#Apply view
if camera_position and reference_position and up_vector and
front_clipping_distance and back_clipping_distance and viewing_angle:
utils.MetaCommand('view set '+str(camera_position[ 0
])+','+str(camera_position[ 1 ])+','+str(camera_position[ 2
])+','+str(reference_position[ 0 ])+','+str(reference_position[ 1
])+','+str(reference_position[ 2 ])+','+str(up_vector[ 0
])+','+str(up_vector[ 1 ])+','+str(up_vector[ 2
])+','+str(reference_position[ 0 ])+','+str(reference_position[ 1
])+','+str(reference_position[ 2
])+','+str(front_clipping_distance)+','+str(back_clipping_distance)+','+s
tr(viewing_angle)+','+str(perspective_mode))

if __name__ == '__main__':
main()
4.3.4.3.11. Select files or directories through the file manager

Scripting language interacts directly with the File Manager through the commands SelectOpenDir,
SelectSaveDir, SelectOpenFile, SelectSaveFile, SelectOpenFileIn, SelectSaveFileIn. These
functions open the File Manager and allow the selection or creation of files and directories. This is
an elegant way to use file and directory paths in user scripts, since it enables the interactive
definition of script parameters. The functions that deal with files return a matrix containing strings
that represent the full path to the selected files, while those for directories return a string indicating
the full path to the folder.

BETA CAE Systems 113 META Automation User’s Guide


4. Scripting

# PYTHON script
import meta
from meta import utils

def main():
print('Select the file for reading')
read_file = utils.SelectOpenFile(0, 'csv files (*.csv)')
if not read_file:
print('No file was selected')
else:
print('The file that was selected is: '+read_file[0])
print('Select the log file for writing the error messages')
save_file = utils.SelectSaveFile()
if not save_file:
print('No file was selected')
else:
print('The file that was selected for writing errors is:
'+save_file[0])
print('Select the directory where the META files are located');
dir = utils.SelectOpenDir('');
if not dir:
print('No dir was selected')
else:
print('The selected directory is: '+dir)

if(__name__ == '__main__'):
main()
If nothing is selected, it can be identified using the if not statement.

4.3.4.4. Create, Edit, Delete and Handle Entities


4.3.4.4.1. Introduction

The entities Annotations, Cut planes, Groups, Isofunctions, Windows, Models, Pages, Plots,
Curves, Images and Videos can be created edited and deleted through script functions. The entities
nodes, elements, parts, materials and boundaries CANNOT be created, edited or deleted in META
in general, so this is also not possible through scripitng. Coordinate systems can be created but
cannot be deleted. Moreover, specific functions exist for other operations related to the entities, e.g.
to show, hide, get results from them, etc.

4.3.4.4.2. Create entities

For creating entities the respective functions are CreateXxx(), e.g. CreateEmptyAnnotation(),
CreatePlane(), CreateGroupFromElements(), etc..
The entities can also be created by applying the respective session commands (see also chapter
“META session commands for use in Scripting Language”). However, one advantage of creating
the entities through script functions is that the function returns the structs of the created entities. For
example, when creating a curve through scripting, the id of the curve is available.
# PYTHON script
import meta
from meta import annotations

def main():
window_name = 'MetaPost'

BETA CAE Systems 114 META Automation User’s Guide


4. Scripting

text = '10th Annotation'


a = annotations.CreateEmptyAnnotation(window_name, text)
if (annotations.IsValidAnnotation(a)):
print(a.id);

if(__name__ == '__main__'):
main()

4.3.4.4.3. Edit entities

There is a series of script functions for editing directly entities and their settings, for example
SetSettingsOfAllCurves(),SetSettingsOfAllAnnotations(), SetAnnotationPointerOnlement(),
ChangeOriginOfPlane(), AddPartsOnGroup(), RotateView(), etc. However, the full possibilities of
editing entities in META are covered through the META session commands and can be achieved
by using the MetaCommand syntax (see also chapter “META session commands for use in
Scripting Language”).
# PYTHON script
import meta
from meta import planes
from meta import utils

def main():
plane_name = 'plane_axis2'
#Change origin through script function
xorig = 1.26
yorig = 7.52
zorig = 3.59
planes.ChangeOriginOfPlane(plane_name, xorig, yorig, zorig)
#Change section width through session command
utils.MetaCommand('plane options width 3 "'+plane_name+'"')

if(__name__ == '__main__'):
main()

4.3.4.4.4. Delete entities

For deleting entities the respective functions are DeleteXxx(), e.g. DeleteAnnotation(),
DeleteCurve(), DeleteModel(), etc.
The entities can also be deleted by applying the respective session commands.

4.3.4.4.5. Show / Hide entities

For showing / hiding entities the respective functions are ShowXxx() and HideXxx(), e.g.
ShowAnnotation(), HideCurve(), ShowModel(), etc.
When more than one 3d model entities or curves need to be shown / hidden, it is much faster to
use the functions ShowSomeXxx() and HideSomeXxx(), e.g. ShowSomeElements(),
HideSomeParts(), ShowSomeCurves(), etc. In this case the entities must be given as matrix.
The entities can also be shown / hidden by applying the respective session commands.

4.3.4.4.6. Identify entities

BETA CAE Systems 115 META Automation User’s Guide


4. Scripting

For identifying 3d model entities the respective functions are IdentifyXxx(), e.g. IdentifyNode(),
IdentifyElement(), IdentifyMaterial(), etc.
When more than one 3d model entities need to be identified, it is much faster to use the functions
IdentifySomeXxx(), e.g. IdentifySomeElements(), IdentifySomeParts(), etc. In this case the entities
must be given as matrix.
The entities can also be identified by applying the respective session commands.

4.3.4.4.7. Get/handle material properties

To get the properties of a material the script function PropertyOfMaterial() can be used. To set
these attributes the script function SetPropertyOfMaterial() can be used. If “all” is used as
argument for property type in the PropertyOfMaterial() function then all material information lines
will be returned, as in the input deck.
# PYTHON script
import meta
from meta import materials

def main():
model_id = 0
material_id = 1
property_type = 'all'
property_value = materials.PropertyOfMaterial(model_id,
material_id, property_type)
print(property_value)

if(__name__ == '__main__'):
main()
4.3.4.4.8. Get results/attributes of entities

First of all, to get the states for which the resultsets are needed, the functions that can be used are
CurrentResultset(), ResultsetsXxx(), FilterResultsetsXxx(), GeneratedResultsetsXxx().
If more than one labels exist for the resultset, the functions DeformationLabelsOfResultsets(),
FunctionLabelsOfResultsets() can be used to get directly all the label results of the state.
Alternatively, the functions StringDeformationLabelsOfResultsets(),
StringFunctionLabelsOfResultsets() can be used to get the available labels and then the functions
GetResultsetFromDeformationLabel() and GetResultsetFromFunctionLabel() can be used to get
the specific label result of the state.
After the needed resultset is found, the functions to get the loaded results depend on the entity from
which the result which is needed. So, in the Nodes functions group there are functions to get results
on the nodes, in the Elements functions group there are functions to get results on elements, in the
Parts functions group functions to get all results from a part, in the Materials functions group
functions to get all results from a material, in the Groups functions group functions to get all results
from a group and in the Models functions group there are functions to get all results from a model.
Moreover, there is a different function for each specific result needed. For nodes, to get the
deformation results, there is the function DeformationOfNode(), to get the coordinates
CoordinatesOfNode(), to get scalar results NodalScalarOfNode() and to get vector results
NodalVectorOfNode().
Similarly for results on elements, there are functions DeformationsOfElement(),
MaxDeformationOfElement(), CentroidScalarOfElement(), CornerScalarOfElement(),
NodalScalarsOfElement() and more.
For parts / materials / models there are functions that return the results on all the nodes or
BETA CAE Systems 116 META Automation User’s Guide
4. Scripting

elements, e.g. CentroidVectorOfPart(), and functions that return directly the maximum and
minimum result, e.g. MinMaxNodalScalarOfModel().
For CELAS spring connection elements the functions StiffnessOfElasElement,
DampingOfDampElement and MassOfMassElement can be used to get information about the
stiffness, damping and mass respectively.
To get and set the number of steps of an axis the functions StepsOfPlotAxis() and
SetStepsOfPlotAxis() respectively can be used.
To get, calculate, and set the material tension, compression, shear, x_tension, y_tension,
x_compression, y_compression, shear and f12 limits of composites materials, the functions
MaterialLimitOfMaterial() and MaterialLimitOfPart() or AddMaterialLimitOfMaterial() and
AddMaterialLimitOfPart() can be used respectively.
Remarks
When the function returns only one entity (e.g. NodalScalarOfNode()), then it returns the
meta_struct of this entity, when it may return more than one entities
(e.g. DeformationsOfElement()), then it always returns a matrix with meta_structs (even when only
one entity is returned).
# PYTHON script
import meta
from meta import results
from meta import nodes

def main():
model_id = 0
result = results.CurrentResultset(model_id)
node_id = 10
deform = nodes.DeformationOfNode(result, node_id)
if(results.IsValidDeformation(deform)):
print(deform.x,deform.y,deform.z,deform.total,
deform.node_id)

if(__name__ == '__main__'):
main()

# PYTHON script
import meta
from meta import results
from meta import models

def main():
model_id = 0
all_resultsets = results.Resultsets(model_id)
result = all_resultsets[2]
print(result)
nodal = models.MinMaxNodalVectorOfModel(result)
print(len(nodal))
if(len(nodal)):
min_nodal = nodal[0] #Struct with the minimum nodal vector
value
print(min_nodal.value) #Minimum nodal vector value
print(min_nodal.x,min_nodal.y,min_nodal.z) #Normalized
coordinates (X, Y, Z) of the minimun nodal vector value
print(min_nodal.node_id) #Id of the node with the minimum
nodal vector value
print(min_nodal.part_id); #Id of the part or -1 if no part

BETA CAE Systems 117 META Automation User’s Guide


4. Scripting

exists

max_nodal = nodal[1] #Struct with the maximum nodal vector


value
print(max_nodal.value) #Maximum nodal vector value
print(max_nodal.x,max_nodal.y,max_nodal.z) #Normalized
coordinates (X, Y, Z) of the maximum nodal vector value
print(max_nodal.node_id) #Id of the node with the maximum
nodal vector value
print(max_nodal.part_id) #Id of the part or -1 if no part
exists

if(__name__ == '__main__'):
main()
4.3.4.4.9. Get measurements from entities

The functions to get measurements depend on the entity from which the measurement is needed.
So, in the Nodes functions group there are functions to get measurements from the nodes, in the
Elements functions group there are functions to get measurements from the elements, in the Parts
functions group functions to get measurements from a part and in the Groups functions group
functions to get measurements from a group.
Moreover, there is a different function for each specific measurement needed. To get the distance
between a node and another node there is the function DistanceNodeToNode(), to get the distance
between a node and a part the function is DistanceNodeToPart(), etc. To get the angle formed by
nodes the function is AngleOfNodes(). To get the distance between a part and a group the function
is DistancePartToGroup().
# PYTHON script
import meta
from meta import results
from meta import parts

def main():
part_model = 0
all_resultsets =results.Resultsets(part_model)
part_result = all_resultsets[1]
part_type = 13
part_id = 1
group_model = 0
group_result = all_resultsets[2]
group_name = "My_Group"

distance = parts.DistancePartToGroup(part_model, part_result,


part_type, part_id, group_model, group_result, group_name)
if(len(distance)):
dist_x = distance[0] # Distance in direction X
dist_y = distance[1] # Distance in direction Y
dist_z = distance[2] # Distance in direction Z
dist_total = distance[3] # Total distance
print(dist_x,dist_y,dist_z,dist_total)

if(__name__ == '__main__'):
main()

BETA CAE Systems 118 META Automation User’s Guide


4. Scripting

4.3.4.4.10. Get connected and neighbour elements/nodes

In cases that the connected elements or nodes are needed, the functions NeighbourElementsXxx(),
NodesOfElements() and ElementsOfNodes() should be used. In case of mesh independent
spotweld connections, where there is no node connectivity, the functions NeighbourElementsXxx()
can still be used as long as the connectivity is supported in META.
The above script functions should be preferred from the visibility session commands, e.g. “add
connected”, as the first are much faster.
# PYTHON script
import meta
from meta import elements

def main():
model_id = 0
element_type = 3
element_id = 1
second_id = -1
neighbour_type =3
neighbour_elements = elements.NeighbourElementsByType(model_id,
element_type, element_id, second_id, neighbour_type)
for e in neighbour_elements:
print(e.id)

if(__name__ == '__main__'):
main()
In cases that the connected elements, nodes, parts etc to connections are needed, the functions
ConnectedXxxOfConnection() should be used.
# PYTHON script
import meta
from meta import connections

def main():
model_id = 0
connection_id = 100001
connected_elements =
connections.ConnectedElementsOfConnection(model_id, connection_id)
for e in connected_elements:
print(e.id)

if(__name__ == '__main__'):
main()

BETA CAE Systems 119 META Automation User’s Guide


4. Scripting

4.3.4.4.11. Get spreadsheet entities/data

There are functions to get data stored in a spreadsheet. To get a cells data the function
SpreadsheetCellByRowColumn(sheet_name, row, col) can be used.
Also the entire row‟s or column‟s data can be stored in a matrix through the functions
SpreadsheetCellsByRow(sheet_name, row). and SpreadsheetCellsByColumn(sheet_name, col).
Returned matrix stops at the last non-empty cell. If all cells are empty, an empty matrix is returned)
To get cells data of an entire cells area the functions SpreadsheetCellsByArea(sheet_name,
top_row, left_col, bottom_row, right_col) and SpreadsheetCellsByLabel(sheet_name, cell_label)
can be used. Cells data are stored in a matrix of same size as the defined spreadsheet area.
Also in order to identify the spreadsheet cells area that involves data the function
SpreadsheetBoundingArea(sheet_name) can be used. A matrix that determines the bounding box
of non-empty cells (matrix[0][0]: top-row, matrix[0][1]: left-column, matrix[1][0]: bottom-row,
matrix[1][1]: right-column) will be returned.

4.3.4.4.12. Get attributes of user Toolbars

To get the attributes of specific entities of user Toolbars the functions CheckboxStateOfToolbar(),
SliderValueOfToolbar() and TextboxValueOfToolbar() are available.
# PYTHON script
import meta
from meta import utils

def main():
toolbar_name = 'Toolbar 1'
checkbox_name = 'Checkbox 1'
state = utils.CheckboxStateOfToolbar(toolbar_name, checkbox_name)
if state == 1:
print('Checked')
elif state == 0:
print('Not checked')
elif state == -1:
print('Failure!')

if(__name__ == '__main__'):
main()

BETA CAE Systems 120 META Automation User’s Guide


4. Scripting

4.3.4.5. Load Geometry and Solver Results, Create User-Defined Results


4.3.4.5.1. Load geometry and field / history results

For loading geometry the respective functions are LoadModel() for solver geometry data files and
LoadProjectModel() for geometries from META databases and META projects.
For loading field results the functions are LoadDeformations(), LoadModalDeformations(),
LoadScalar() and LoadVector() for solver results data files and LoadProjectDeformations(),
LoadProjectScalar() and LoadProjectVector() for results from META databases and META
projects.
The argument “data” which is needed for the functions is the same as the argument used in the
equivalent META session commands. The best way to retrieve the correct syntax is to load the
result manually from the META interface and view the session command passed to the current
META_post.ses file.
In order to append the loaded geometry/results the functions LoadAppendDeformations(),
LoadAppendProjectDeformations(), LoadAppendScalar(), LoadAppendScalarGetCoordSystems(),
LoadAppendProjectScalar(), LoadAppendVector(), LoadAppendVectorGetCoordSystems(),
LoadAppendProjectVector() are available.
For loading curves from history results files the respective functions are LoadCurvesXxx(), e.g.
LoadCurvesNastran(), LoadCurvesDyna().
The arguments which are needed for the functions, e.g. entities, variables, etc, are the same as the
arguments used in the META session commands. The best way to retrieve the correct syntax is to
load the result manually from the META interface and view the session command passed to the
current META_post.ses file. The only difference is that the results are passed as matrices to the
script functions. The string expressions can be easily changed to matrices and vice versa through
the functions RangeToMatrix() and MatrixToRange().
Especially for loading curves from RADIOSS history results files, the function LoadCurvesRadioss()
needs the time history id as argument. In case the time history id is not known, strings „all‟ or „*‟ can
be used referring to all available time history ids or the function GetRadiossTimeHistoryId() can be
used to find the time history id for a specific history result.
The entities can also be loaded by applying the respective session commands (see also chapter
“META session commands for use in Scripting Language”). However, one advantage of loading the
entities through script functions is that the function returns the structs of the created entities. For
example, when loading a model through the script function, the id of the model is available.

BETA CAE Systems 121 META Automation User’s Guide


4. Scripting

# PYTHON script
import meta
from meta import models
from meta import results

def main():
window_name = 'MetaPost'
filename = '/home/demo/example.op2'
deck = 'NASTRAN'
r = models.LoadModel(window_name, filename, deck)
if models.IsValidModel(r):
model_id = r.id
states = '1-3'
data = 'Displacements,Translational'
new_resultsets =results. LoadDeformations(model_id,
filename, deck, states, data)
data = 'Stresses,VonMises,MaxofTopBottom'
new_resultsets = results.LoadScalar(model_id, filename,
deck, states, data)
for res in new_resultsets:

print(res.name,res.nodal_data_name,res.function_data_name,res.stat
e)

if(__name__ == '__main__'):
main()
# PYTHON script
import meta
from meta import plot2d

def main():
window_name = 'Window1'
plot_id = 0
filename = '/home/demo/exmampleT01'
entity_id = '12954'
entity_type = 'node'
variable = ""
time_history = [ plot2d.GetRadiossTimeHistoryId(filename,
entity_id, entity_type, variable) ]
#time_history = ['all' ]
entities = [ entity_id ]
variables = [ 'dx' ]
new_curves = plot2d.LoadCurvesRadioss(window_name, plot_id,
filename, entity_type, time_history, entities, variables)
for c in new_curves:
print(c.id)

if(__name__ == '__main__'):
main()
Remarks
The deck of the results is given as argument in the functions to load geometry and field results,
whereas different functions exist for each deck for loading history results.

BETA CAE Systems 122 META Automation User’s Guide


4. Scripting

4.3.4.5.2. Create user-defined field results

Apart from loading solver results, it is possible to create user defined field results using the results
from calculations realized inside the script.
First of all a new empty state for field results can be created with the function CreateResultSet().
To add a new label to the resultset and set the results to the nodes or the elements, the functions to
be used are AddDeformationOnAllNodes(), AddNodalScalarOnAllNodes() and
AddNodalVectorOnAllNodes().
For more complicated procedures:
To reset all the values of a resultset and add values to the nodes or the elements, the functions to
be used are StartAddingXxx() and EndAddingXxx(), e.g. StartAddingDeformations(),
EndAddindDeformations().
To change the values of a resultset the functions to be used are StartChangingXxx() and
EndAddingXxx(), e.g. StartChangingCentroidVector(), EndAddingCentroidVector().
To append a new label to a resultset and set values to the nodes or the elements for this label, the
functions to be used are StartAppendingXxx() and EndAddingXxx(), e.g.
StartAppendingCentroidScalar(), EndAddingCentroidScalar().
Between the StartXxx() and EndXxx() functions the values can be assigned to the nodes with the
functions AddCentroidScalarOnElement(), AddCentroidScalarOnSomeElements(),
AddCentroidVectorOnElement(), AddCentroidVectorOnSomeElements(),
AddCornerScalarOnElement(), AddCornerScalarOnSomeElements(), AddDeformationOnNode()
and AddDeformationOnSomeNodes(). When values are to be to more than one elements / nodes,
functions XxxOnSomeElements() and XxxOnSomeNodes() should be preferred, as they are much
faster.
Improtant Note: The EndAddingXxx() function must be called at the end, or else the values will not
be assigned to the resultset.

4.3.4.6. Useful notes about ΜΕΤΑ script functions


4.3.4.6.1. Speed up the execution of scripts

When executing scripts in META some points should be taken into consideration in order to achieve
minimum execution times.
- When the script includes functions that change the display of the META windows, each redraw will
result to time consumption. To speed up the execution of the script, the redraws can be disabled,
and enabled only at the end of the script, in order to display directly the final state.
This can be achieved through the lines
MetaCommand('options session controldraw disable')
MetaCommand('options session controldraw enable')
- When a function needs to be applied on more than one entities, it is always faster to use the
function that applies directly on all the needed entities XxxOnSomeXxx, e.g. IdentifySomeNodes(),
AddElementScalarOnSomeElements(), etc, instead of applying the single function for each entitty.
- When all the results from entitiy are needed, it is faster to use the function that gets all the results
directly, e.g. DeformationsOfModel, CentroidScalarOfPart(), etc, instead of getting the result for
each element / node separately.
- In cases the connected elements or nodes are needed the functions NeighbourElementsXxx(),
NodesOfElements() and ElementsOfNodes() should be preferred from the visibility session

BETA CAE Systems 123 META Automation User’s Guide


4. Scripting

commands, e.g. “add connected”, as the first are much faster.

4.3.5. User defined buttons and custom GUI


4.3.5.1. General

META scripting language enables the creation of user defined buttons and fully customized
graphical interfaces. The buttons that can be created are similar to the buttons of the GUI and are
used to invoke user functions. For the management of specific tasks that must be controlled
through a number of definitions and actions, it is very useful to create a custom GUI. There are two
libraries of functions to create custom user interface. The first supports only the basic widgets that a
GUI can hold, like checkbuttons, radio buttons, menu buttons, lists, tables, while the second library,
BCGUI functions, is more extensive and except from the main widgets mentioned before it also
supports hundreds of more sophisticated tools. These tools allow the creation of any complex
interface that may also contain tab widgets, popup menus, spin boxes, group of buttons, tooltips
and so on. The first library is similar for Python and BETA Scripting language and is described in
the relevant paragraph of the chapter BETA Scripting Language. The second library is described in
a separate chapter for both Python and BETA Scripting Lanuage.

BETA CAE Systems 124 META Automation User’s Guide


4. Scripting

4.4. BETA Scripting Language

4.4.1. Introduction
Script is a code (series of commands) written in the, C-like, BETA scripting language and is saved
as text file. An example of script code follows:

def Main()
{
//Comment
count = 0;
pshells = CollectEntities(NASTRAN,0,"PSHELL",0);
foreach pshell in pshells
{
GetEntityCardValues(NASTRAN,pshell,"Name",name);
pos = MatchString(name,"Default");
if(pos)
{
to_del[count++]= pshell;
}
}
DeleteEntity(to_del,1);
}

4.4.2. Syntax
Commands Each command consists from a series of valid words and characters
that ends to a semicolon (;). Execution of a command is not
depended on the lines on which this is written. Thus all the following
three examples pass the value 1 to the variable a, and print its value
in the Output and META terminal window.

a a=1; a=1;Print (a);


= Print (a);
1;
Print (a
)
;

Spaces Spaces count only to separate string words, otherwise they are
ignored. Also multiple spaces in a row count as one space. Thus:
Print(“aa”); is the same as
Print ( “aa”) ; but different from
Print(“a a”); as this prints: a a and not: aa
Also:
PrintMonitor(“text”); prints the word “text” in a monitor
window and
Print Monitor(“text”); leads to a syntax error while
Print Monitor is not a valid syntax for the Print command.

Capital and lower case META scripting language is case sensitive. Thus:
if (a==1)Print(a); prints the a variable value if is equal to 1 and

BETA CAE Systems 125 META Automation User’s Guide


4. Scripting

If (a==1)Print(a); leads to a syntax error while If is not the


right syntax for the if command.

Comments Comments are script code lines that are not taken into consideration
when the script is parsed and executed. These lines are generally
used to inform the developer.
Rows starting with // are considered as comments. Also anything
that follows the // in a row is commented out.

4.4.3. Data types


4.4.3.1. General

The data type determines the kind of data that a variable or a function can hold. Data types include
integer or floating point numbers, strings, matrices etc, as well as user defined types. The following
paragraphs describe the available data types for writing an META script. Note however that
variables used in META scripts, are considered typeless.

Integers
The integer data type is used by variables that can only have whole numbers as values.
my_var = 10;

Floating Point
Values that are not integral are stored as floating point numbers. A floating point variable can be
expressed as a decimal number such as 112.5, or with an exponent such as 1.125E2. In the latter
case the decimal part is multiplied by the power of 10 after the E symbol.
A floating point must contain a decimal point, or an exponent or both.
my_var = 112.5;

Strings
A string, is declared as a series of printable text characters representing human readable stuff. A
string value is enclosed in quotes (e.g. "this is a string") and can be assigned to any variable for
storage and easy access. String variables are internally represented as arrays of characters.
s = "a string";

Elements
This is a specific data type used in functionality to create windows and in specific functions in
ANSA.
Typically, the element data type is used in the declaration of function arguments.

BETA CAE Systems 126 META Automation User’s Guide


4. Scripting

4.4.3.2. User Defined Data Types (structures)

In many cases, user scripts can be more elegantly and concisely expressed if they can be written in
terms of aggregate structures. Such structures can be considered as user defined data types that
represent a collection of one or more variables, possibly of different types, grouped together under
a single name for convenient handling. The keyword used to declare such collections is struct and
the individual variables within the collection are called its members.
A very important feature of META scripting is the use of meta_structs variables. meta structs is a
special group of structs, which are used to carry information about entities in META and through
them it is possible to access and modify their data.
In order for meta structs to be used, they need to be defined first. Their definition exists in the file
meta_structs, which is provided with the META software inside the folder config. This file must be
included in each script that uses meta structs through the keyword
#include "meta_structs"
The above line is inserted automatically each time the user selects to create a new script. With the
above line, META searches to find the file in the config directory.
An example of a meta struct is the meta_struct for the elements:
Elem:
meta struct elem is used to carry information about the elements loaded in META. It has the
following structure:

struct {
int id; // Id of the element
int second_id; // Second id of the element (GAP, TUBE, JOINT) , -1 if
there is not a second id
int model_id; // Model number of the element
int type; // Type of the element
int subtype; // Subtype of the element
int visible; // 1 if element is visible, 0 if model is not visible
int part_id; // Id of the part it belongs to, -1 if element belongs to
no part
} elem;

4.4.4. Variables
4.4.4.1. Introduction

A variable is a named memory location that contains data and can be modified during script
execution. Every variable is distinguished according to its data type and its value:
The data type describes what particular kind of data is stored in a variable, such as an integer
number, a string etc. As seen earlier, variables are typeless, i.e. their type is defined by the way the
variables are used.
The value of the data that a variable contains at any point is determined by the instructions of the
code and, of course, this value will usually change many times during program execution.

4.4.4.2. Naming of variables and restrictions

The variable's name is called an identifier, or more conveniently, a variable name. Variable names
can include the letters A-Z (in upper or lower case), the numbers 0-9 and the underscore character.
All other characters including the blank space are illegal. A variable name is case sensitive and
must begin with a letter or an underscore. Names usually indicate the kind of information that is

BETA CAE Systems 127 META Automation User’s Guide


4. Scripting

stored in the variable and must be chosen in a manner that will not confuse the user. The following
table lists some valid and invalid variable names:

# Variable Name Validity Reason


1. surface_area Valid --
2. surface-area Invalid Is considered an operation
3. surface area Invalid Contains blank space
4. SurfaceArea Valid --
5. _surface_area Valid --
6. surface@area Invalid Contains reserved characters
7. _1-Surface Valid --
8. Surface"1" Invalid Contains reserved characters
9. Surface_1 Valid --
10. Surface/1/ Invalid Contains reserved characters
11. 1Surface Invalid Begins with a number

Although the number of characters in a variable name can be unlimited, it is usually a good
programming practice to keep it short. Furthermore, the language reserves some "names" as
"keywords". These names are used to represent internal functions and are not allowed to be used
as variable or function names.
The reserved characters and for writing a META script are listed below:

reserved characters =^*/+-%&'"\!(){}[]:;<>,.

reserved words include, void, int, def, float, char, string,


matrix, map pointer, element, struct, byref, if,
else, for, do, while, foreach, in, const, switch,
break, continue, goto, case, default, return,
static, global, projectfile, defbutton, script,
stricton, strictoff, public, private, model, elem,
node, part, boundary, material, page, window, group,
resultset, deformation, nodal_scalar,
centroid_scalar, corner_scalar, nodal_vector,
centroid_vector, plot, curve, point, coord_system,
annotation, color, image, video, plane, isofunction,
elem_coord_system, part_layer, curve_group,
plot_axis

reserved variables FILENAME, FILEPATH, TRANSLATIONS

reserved constants PROD, PBEAM, PTUBE, PELAS, PDAMP, PVISC, PMASS,


PBAR, PGAP, PBEND, PBUSH, PSOLID, PSHELL, SHELL,
TRIA3, TRIA6, QUAD4, QUAD8, SOLID, TETRA, PENTA,
HEXA, TETRA10, PENTA15, HEXA20, ROD, BEAM, BUSH,
TUBE, ELAS1, DAMP1, MASS1, VISC, BAR, GAP, BEND,
ONROD, ELAS2, DAMP2, MASS2, ONM1, ONM2, RBAR, RBE2,
RBE3, JOINT, RROD, PLOTEL, SPC, SPC1, MPC, TEMP,
FORCE, FORCE1, FORCE2, MOMENT, MOMENT1, MOMENT2,
PLOAD, PLOAD1, PLOAD2, PLOAD4, MAT1, MAT2, MAT3,
MAT4, MAT5, MAT8, MAT9, CORD1R, CORD1C, CORD1S,
BETA CAE Systems 128 META Automation User’s Guide
4. Scripting

CORD2R, CORD2C, CORD2S

4.4.4.3. Declaration of variables

When writing META scripts, it is not necessary to explicitly define the data type of variables. This is
because all variables used in META scripts are considered by default typeless and automatically
acquire the proper data type depending on their use at the time. For example, in a statement like:
my_var = 13;
the variable my_var is treated as being of integer type. But, if later on, the same variable is found
in another statement like:
my_var = "my string";
it will switch from integer to string type.
The use of typeless variables reduces the total number of variables used in a script, since the same
variable can be used in different ways. However, typeless variables can be proven dangerous when
they must be passed as arguments to a function, since the function should be aware as to how to
treat these variables. Thus, in such cases, the data type of all variables that are communicated to a
function must be explicitly declared in the functions' arguments. For example, if 'var1', 'var2' and
'var3' represent integer, float and string variables respectively, they should be declared as:
def my_function (int var1, float var2, string var3)

4.4.4.4. The const keyword

A variable can get a unique and unchangeable value if defined as constant. Once it is defined, it
keeps its original value even if later on is given a different value. This kind of variables can be
declared in global or function code using the keyword const followed by the type of variable. The
type is auxiliary and is used only for the definition.
const float pi = 3.14;
def main()
{ pi = 3;
Print(pi);//The 3.14 will be printed
}

4.4.4.5. Checking the variables’ spelling

A very frequent problem for all programmers is the spelling of variables. Especially in lengthy codes
where there is a significant number of variables, an error like that can cause erroneous results and
a serious waste of time for debugging. This can be totally avoided if using the statement #stricton
written in the global section of the script. The parser issues a warning when it comes across an
undeclared variable. The variable type is given explicitly either in the global section or within a
function and it is not binding. The script stops this check by invoking the statement #strictoff. Thus,
any code located between the two statements is examined for variables‟ spelling errors.

#stricton In this example the parser will recognize the two


undeclared variables („value‟ and „params‟) and
int a; will return the following message:

BETA CAE Systems 129 META Automation User’s Guide


4. Scripting

float b;
float param;

def main()
{
a = 1;
b= 1.2;
value = a*b;
params = a/b;
}
#strictoff
Remarks:
- Although the variables get a type, they are still typeless.
- There is no restriction to the number of times the #stricton and #strictoff can be invoked inside a
script.
- #strictoff is the default state.

4.4.5. Sets of data: matrices and maps


4.4.5.1. Introduction

Most problems that occur in practice require more than simple variables for their definition and
solution. Thus, it is often necessary to handle data as sets of similar or different kind objects.
Towards this direction comes the definition of matrices and maps.

4.4.5.2. Matrices

A matrix data type provides a way to collect entities under the same storage. As a good
programming practice, matrices should be declared so that the program will reserve enough space
to store the data. The corresponding keyword for this declaration is matrix.
Since matrix members are actually variables, they can hold any type of variable, so a matrix like:
m = {1, 1.23, "some string", "a", 2, 99.23};
is perfectly valid.

Example
matrix m={1,2,3,4};
m={1, 1.23, "some string", "a", {2, 3.15, "string2"}, 99.23};
m[532]=56.7;
The memory reserved for the matrix depends on the position of the last member in the matrix, so
the user has to be very careful in order not to reserve unused memory. In the third example above,
if this is the first definition regarding the matrix m, 533 places of memory (from 0 to 532) will be
reserved although the other positions of the matrix have not been assigned any value from the
user.
The functions dealing with the creation and manipulation of matrices are presented in paragraph
“Handling Matrices”.

BETA CAE Systems 130 META Automation User’s Guide


4. Scripting

4.4.5.3. Maps

A map data type can be seen as an expansion of the matrix, since the indexing is done with
arbitrary values. The keyword that specifies this data type is map.
A map is characterized by a name and is like a user defined tree-structure, where each node holds
a specific value and is referenced by a specific key. The key can be of any data type.
A map is initialized using the command CreateMap:
m = CreateMap();

Example
m = CreateMap();
m[1140]=1;
m["some string"]=10.5;
In maps, memory is reserved only for the specific node in the map, for example when typing
m = CreateMap();
m[1140]=1;
only one position will be reserved in memory contrary to the case m was a matrix, where 1141
positions would be reserved.
The functions dealing with the creation and manipulation of maps are presented in paragraph
“Handling Maps”.
Note that a map is the only data that needs to be destroyed, as the memory used by it is not
automatically released at the end of the execution of the script.

4.4.6. Operators and basic calculations


4.4.6.1. Expressions and assignments for numeric data types

Various data types can be combined, by the appropriate operators, to form expressions. These
expressions are evaluated when the script is executed. The results of a calculation can be stored
for future use by assigning a value to a variable. This is done by an assignment statement whose
general form is:
<variable name> = <expression>;
where <variable name> is the name of the variable, while <expression> is an expression
formed by the combination of variable names using operators.
The sets of operators and the rules of how expressions may be written and evaluated are
determined by the types of the operands involved. Therefore, the data type is a very critical attribute
of any data value.
An expression is formed by the combination of variables, constants and operators. Operators are
used in order to compute new values out of old ones, and can be arithmetic, assignment,
increment / decrement and logical operators. Operators can also be used in expressions and
assignments for string data types.

4.4.6.2. Arithmetic operators

There are five different arithmetic operators that can occur in numeric expressions. These are:

# Operator Operation
BETA CAE Systems 131 META Automation User’s Guide
4. Scripting

1. + Addition
2. - Subtraction
3. * Multiplication
4. / Division
5. ** Exponentiation

Some examples of arithmetic expressions are:


surface_area = width_x * width_y
interior_vol = exterior_vol - width_x * width_y * width_z;
hypot2 = a**2 + b**2;
However, the meaning of the 2nd and 3rd examples might not be clear. For instance, the 2nd
example might be interpreted as
interior_vol = (exterior_vol - width_x) * width_y * width_z;
or
interior_vol = exterior_vol - (width_x * width_y * width_z);
The meaning of such expressions is resolved by defining an order of precedence for operators.
This precedence will determine the order in which the expression is to be evaluated.
Operator precedence:
The order of precedence is very much alike what is known from algebra. Thus, exponentiations are
carried out first, then multiplications and divisions and finally additions and subtractions.
Multiplication and division have equal precedence. When a number of multiplications and divisions
are found in sequence, the expression is evaluated from left to right. The same applies for addition
and subtraction. Thus, the expression
x / y * z ;
is understood to be
(x / y) * z
and not
x /(y * z)
The use of parentheses can force the order of evaluation of certain expressions.
Thus, the expression:
x /(y * z);
will be evaluated exactly as it is written.

4.4.6.3. Assignment operators

The assignment operators are the ones that actually assign a value to a variable. The well-known:
“=“ sign, is an assignment operator. For example
x = 1;
sets 1 to variable x, and
a = b;
sets to whatever b's value is. The expression:

BETA CAE Systems 132 META Automation User’s Guide


4. Scripting

i = i + 1;
is a standard programming idiom for increasing a variable's value by 1, while
i = i - 1;
i = i * 2;
i = i / 2;
will decrease a variable‟s value by 1, multiply and divide it by 2 respectively.

4.4.6.4. Combination of assignment with arithmetic operators

The pattern v = v op value;


where “v” is a variable, “op” is any of the addition, subtraction, multiplication and division operators
+, -, *, / and “value” is a constant arithmetic value, can be shortly expressed as:
v op = value;
where variable “v”, does not have to be mentioned twice.

The following syntax expressions are equivalent:

Expression Equivalent Expression


i = i + 1; i += 1;
i = i - 1; i -= 1;
i = i * 2; i *= 2;
i = i / 2; i /= 2;

4.4.6.5. Increment and decrement operators

For the most common cases where we add or subtract the constant value 1 from a variable, META
scripting language allows the use of auto-increment or auto-decrement operators. In their simpler
form, they look like this:
i++;
i--;
These expressions correspond to the slightly longer:
i += 1;
i -= 1;
and to the fully expanded:
i = i + 1;
i = i - 1;

4.4.6.6. Logical operators


Logical operators are the operators used for logical procedures like comparisons. Such
operators are summarized in the table below:

# Operator Meaning
BETA CAE Systems 133 META Automation User’s Guide
4. Scripting

1. < less than


2. <= less than or equal to
3. > greater than
4. >= greater than or equal to
5. == equal to
6. != not equal to
7. || Logical OR
8. && Logical AND
9. ^ Logical XOR

4.4.6.7. Expressions and assignments for string data types

Characters may be assigned to string variables, using statements similar to those of numeric types:
property = "PSHELL";
mat_name = "steel_105";
The operators that can be used to form expressions between string data types are:

# Operator Meaning
1. + string catenation
2. % string catenation

For example, the string variable


property = "PSHELL";
can be merged with the string variable
id = "with id 1";
as
property_id = property + id;
or with the equivalent
property_id = property % id;
and assign to the 'property_id' variable the value
"PSHELL with id 1"

BETA CAE Systems 134 META Automation User’s Guide


4. Scripting

4.4.6.8. Expressions and assignments for struct data types

A typical example of a user defined data type is the meta struct node. Its structure is the following:
struct {
int id; // id of the node
int model_id; // Model number of the node
float x; // X coordinate of node
float y; // Y coordinate of node
float z; // Z coordinate of node
int visible; // 1 if node is visible, 0 if node is not visible
} node;

The above line defines a structure called node whose members are the integers called id and
model_id three floats for the coordinates x, y, z and an integer which defines if the node is visible.
Each node occupies a position in space as dictated by its coordinates and may also have a unique
ID and a unique model ID to distinguish it from other nodes.
Once the structure is defined, it can be used as a regular data type for the declaration of other
variables. For example, to declare a node n in space, just type: node n;
Now, the n variable can automatically reference the members of the node structure. In other words
structure “n” can reference its id and its x, y, z coordinates.

The syntax for this reference is struct.member and in this case takes the form:

Reference Meaning
n.id …the id of node n
n.model_id …the id of the model of node n
n.x …x-coordinate of n
n.y …y-coordinate of n
n.z …z-coordinate of n
n.visible …the integer defining if the node is visible

Examples:

Reference Meaning
n.id = 13; assign number 13 as the id of node PA
n.x = 123.45; assign the x coordinate of node PA
n.y = 321.00; assign the y coordinate of node PA
n.z = 456.78; assign the z coordinate of node PA

As an extension to declaring a single node n that belongs to the structure node, an array (matrix) of
nodes can be declared. For example, to declare an array called nds of 10 nodes in space using the
structure node type:
node nds[10];
The reference to the individual variables of the nds array follows the same rules as before. For
example, to assign 13 as the id of the 5th node of the nds array, the following should be typed:
nds[5].id = 13;
and to assign the coordinates of nds[5] type:

BETA CAE Systems 135 META Automation User’s Guide


4. Scripting

nds[5].x = 123.45;
nds[5].y = 321.00;
nds[5].z = 456.78;

When a script function is used that returns a matrix of meta structs, for example
el_nodes = NodesOfElement(model_id,element_type,element_id,second_id);
the variable element_nodes has to be defined as a matrix, although it contains meta structs.
Structure members cannot be accessed through expressions like:
el_nodes[3].id
To access the data of a member directly the following steps should be followed.
- first define a meta struct variable
- assign to it the desired matrix member and
- access the data of the meta struct variable.
The examples below show how the data of returned meta structs can be accessed, either using the
foreach statement or directly.

Example

Use of foreach statement Direct access to the members’ data

node n; node n;
matrix el_nodes; matrix el_nodes;
el_nodes=NodesOfElement(0,7,66,5); el_nodes=NodesOfElement(0,7,66,5);
foreach n in el_nodes n=el_nodes[0];
{ Print(n.id); Print(n.x);
Print(n.id); Print(n.x); Print(n.y);
Print(n.y); Print(n.z); n=el_nodes[3];
} Print(n.id); Print(n.x);
Print(n.y);

BETA CAE Systems 136 META Automation User’s Guide


4. Scripting

4.4.7. Conditional statements and branching


4.4.7.1. The "if-else" blocks and the logical operators

The if statement, is the basic decision statement of a script. Its operation is based on the evaluation
of a condition that will yield a result that is either true or false. If the condition is true (i.e. not equal
to 0), then the if-block of statements is executed. If the condition is false, then the else-block of
statements is executed. The if statement general form, is:
if (condition)
statement;

The alternative line of execution is created with else:


if (condition)
statement;
else
statement;

Some examples of the use of the if-else blocks follow:


if (a>5) In this case the logical expression a>5 will be evaluated. If it is proved true,
{ then b and c will be assigned zero values. Otherwise, this block of
b = 0; statements will be ignored.
c = 0;
}
if (a>5) In this case the logical expression a>5 will be evaluated. If it is proved true,
{ then b and c will be assigned zero values. Otherwise, they will be assigned
b = 0; unit values as dictated by the else group of statements.
c = 0;
}
else
{
b = 1;
c = 1;
}
if (a>5 ^ c==1) In this case b will be assigned zero value, only if one of the two
b = 0; expressions is true. It is similar to :
if((a>5 && c!=1) || (c==1 && a<=5))
if (a>5) In this case the logical expression a>5 will be evaluated. If it is proved true,
{ then b and c will be assigned zero values. Otherwise, the logical
b = 0; expression a<3 will be evaluated. If it is proved true, then b and c will be
c = 0; assigned unit values. If none of the conditions is fulfilled, the whole block of
} statements will be ignored.
else if (a<3)
{
b = 1;
c = 1;
}
if(a>5 || b==1) In this case a unit value will be assigned to c only if one of the two
c = 1; expressions is true.
if(a>5) && b==1) In this case a unit value will be assigned to c only if both expressions are
c = 1; true.

BETA CAE Systems 137 META Automation User’s Guide


4. Scripting

4.4.7.2. The switch statement

The switch statement is an alternative form of a conditional statement, which allows the definition
of multiple possible execution paths. The general form of the statement is:
switch (expression)
{
case constant1:
statement;
....
break;
case constant2:
statement;
/* fall through */
case constant3:
statement;
....
break;
....
default:
statement;
break;
}
The switch statement evaluates the value of an expression and branches to one of the case labels.
Duplicate labels are not allowed, so only one case will be selected. The expression can evaluate an
integer or a string. The case labels can be in any order and must be constants or strings. The
default label can be placed anywhere in the switch. Note that two case labels cannot have the
same value. When META reach a switch statement, it evaluates the expression and then looks for
a matching case label. If none is found, the default label is used. If no default is found, the
statement does nothing, e.g.:
a = 2;
switch (a)
{
case 0:
Print("a is zero");
break;
case 1:
Print("a is one");
break;
case 2:
Print("a is two");
break;
/* will fall through default as well */
default:
Print("a is not zero");
break;
}
The result is: 'a is two'.

BETA CAE Systems 138 META Automation User’s Guide


4. Scripting

4.4.7.3. The goto statement

The goto statement is a powerful branching statement. It can be used to create jumps and redirect
the execution order of a program. Its general form is:
goto < label >

where '<label>' is the label of an executable statement. e.g:


some_label:
...
if (a>5)
goto some_label;

4.4.8. Loop statements


A loop comprises of a block of statements that are executed repetitively. When the end of the loop
is reached, the block is repeated from the start of the loop.

4.4.8.1. The foreach statement

The foreach statement allows the iteration over the elements of an array. foreach loops do not
maintain any explicit counter. The general form of the statement is:
foreach <item> in <array>
{
do something to <item>
}

An example of the statement use is given below:


matrix m={1,2,3,4,5,"foo"};
foreach a in m
Print(a);

the result is
1
2
3
4
5
foo

4.4.8.2. The for statement

The for statement introduces an indexed loop, where the number of repetitions is known before the
loop is started. The general form of the for statement is:
for (initial-statement; condition; iteration-statement)
body-statement;

BETA CAE Systems 139 META Automation User’s Guide


4. Scripting

The 'initial-statement' initializes the explicit counter, the 'condition' specifies the number
of repetitions and the 'iteration-statement' dictates the increment or decrement value of the
explicit counter during the loop.
for (a=0; a<5; a++)
Print (a);

the result is
0
1
2
3
4

Remarks
- When a foreach or for loop statement affects only one line then it is not necessary to enclose this
line in brackets:

One line is affected More lines are affected

for (a=0; a<5; a++) for (a=0; a<5; a++)


Print (a); {
Print(a);
Print(a+1);
}

4.4.8.3. The while statement

The while statement introduces a conditional exit loop. The program executes the specified
statements repetitively for as long as the given condition remains true (i.e. not equal to 0). Its
general form is:
while (condition)
body-statement;

If operators are to be used for the expression of the condition, these must be of logical relational
type.
a = 0;
while (a<3)
{
Print(a);
a++;
}

the above result will be something like


0
1
2

BETA CAE Systems 140 META Automation User’s Guide


4. Scripting

4.4.8.4. The do while construct

While the for and while statements check the condition before entering the loop, the do while
construct makes the check after every pass of the loop and thus guarantees that at least one pass
will take place. Its general form is:
do
body-statement;
while (condition);

In the example below:


a = 1;
do
{
Print (a);
a++;
} while (a>5);

the result is 1.

4.4.8.5. The continue and break statements

The continue and break statements can be used to redirect the execution order of a loop. The
break statement allows the termination of a loop regardless of the loop control condition. In other
words it can lead to an unconditional branching. A typical example is given below:
a = 0;
while (a<5)
{
Print(a);
a++;
if ( a == 3)
break;
}
In this case the result would be:
0
1
2
The continue statement jumps back to the beginning of the loop‟s block to begin the next iteration.
Thus, it omits a certain block of statements. A typical example is given below:
a = 0;
while (a<5)
{
a++;
if ( a == 3)
continue;
Print(a);
}
In this case the result would be:
1
2
4
BETA CAE Systems 141 META Automation User’s Guide
4. Scripting

4.4.9. Handling variables and sets of data


4.4.9.1. Handling matrices
4.4.9.1.1. Setting data to a matrix

Most problems that occur in practice require more than simple variables for their definition and
solution. Thus, it is often necessary to use matrices as sets of data.
To set some data to a specific position in a matrix type:
m[3] = 10;
To specify all the matrix members at once:
m={10,7,9};
Matrix members can be other matrices, e.g.the expression forms a 3x3 2-dimension matrix:
m = {{10,7,9},
{5,2,17}
{6,12,25}};

4.4.9.1.2. Retrieve a matrix member value

To retrieve a value of a specific member of a matrix, the user must provide the corresponding index
operator:
i = m[0];
For the 3x3 2 dimension matrix given above, the following expression will assign to i the value of 5:
i = m [1][0];

4.4.9.1.3. Retrieve the size of a matrix

The function MatLen returns the length of matrix m.


len = MatLen(m);
Note that, as the index of a matrix‟s member starts from 0, the size of a matrix is always one more
than the index of the last member of the matrix. This means, if m[8] is the last member of the
matrix m, the size of m is 9.

Remarks
- There is also available the MatSize function that retrieves the same result as MatLen.
- Note that matrices are always stored in memory as one dimensional entity.
- An entity in a matrix may be also a matrix.
- Writing a matrix in a row, column format is not necessary for each row to consist of the same
number of columns. A matrix like the following is absolutely valid:
M = {{10,{1,2},9,8,90},
{4,6},
{5,3,17}};

Variable: m=M[0][1][1]; will return the value 2.

BETA CAE Systems 142 META Automation User’s Guide


4. Scripting

4.4.9.1.4. Matrix expressions

All algebraic operations between matrices and constant values are interpreted as operations
between each member of the matrix and the constant value. For example the expression:
B = 10*A;
will result to a matrix B, whose members are 10 times the corresponding members of A.
Addition, subtraction, division and exponentiation operations between matrices should take place
only between conformable matrices (i.e. matrices having the same shape).
On the other hand, the multiplication operation can take place between matrices only when the
second dimension of the first matrix equals the first dimension of the second matrix. This means
that, if the first matrix is A (a x b) and the second matrix is B (c x d), then b must equal with c in
order to multiply the matrices.
Having two non-conformable matrices (i.e. A 2x3 and B 3x1):
A = {{10,7,9},
{5,2,17}};
B = {{1},
{2},
{1}};
a multiplication operation:
C = A * B;
will lead to a matrix C 2x1:
C = {{10*1+7*2+9*1},
{5*1+2*2+17*1}};
while a multiplication operation:
C = B * A;
leads to error.

BETA CAE Systems 143 META Automation User’s Guide


4. Scripting

4.4.9.2. Handling Strings


4.4.9.2.1. Correspondence between Strings and Matrices

Strings can be treated as matrices, so any part of them can be isolated without the use of any built
in function. A string corresponds to a matrix, which has a length equal to the number of characters
that comprise it. Each character corresponds to a matrix member. The first character has index 1
and the last has index equal to the string length.

Example
str = "Bumber_Front";
The above string has 12 characters where “B” has index 1, “u” has index 2……and “t” has index 12.
We can get any part of the string by using the indices of the characters. Here are some examples:
str = str(1:6); //This will get the "Bumber"
str = str(8:12);//This will get the "Front"
str = str(8:8); //This will get the character "F"
str = str(7:7); //This will get the character "_"
str = str(3:8); //This will get the "mber_F"
str = str(5:); //This will ge the "er_Front"
str = str(:7); //This will get the "Bumber_"

The size of a string (an integer) can be obtained calling the built-in function „Strlen‟:
length = Strlen(s)

4.4.9.2.2. Modify Strings

The function „TokenizeString‟ splits a string according to a specified character and returns a matrix
containing each split part of the string as matrix members.
TokenizeString (string s, string t, integer flag);

Example
str = "one/two";
m = TokenizeString (str, "/", 0 );

The above command will return a matrix with two members


m[0] = "one" and m[1]= "two"

Two strings can be combined to create a new one, containing the text of both. This is achieved by
the string catenation operators or using the built-in function „Strcat‟.

Examples:
new_string = old_string1 % old_string2;
new_string = old_string1 + old_string2;
Strcat(string1, string2);

BETA CAE Systems 144 META Automation User’s Guide


4. Scripting

The difference between the use of catenation operators and the command Strcat is that 'Strcat'
actually uses the first string as destination of the operation, thus modifying its value.
The function „Strcmp‟ performs a lexicographical comparison between the two strings:
val = Strcmp(s1,s2);
if val < 0 then s1<s2
if val > 0 then s1>s2
if val = 0 then s1=s2
Finally, the function 'Strcpy' copies the contents of a string into another:
Strcpy(a,b);
copies b to a (copies the second string to the first and it returns the destination string).
Alternatively it can be written as:
a = b;

4.4.9.3. Handling Maps


4.4.9.3.1. Map Declaration and Initialization

A map is characterized by a name and is like a user defined tree-structure, where each node
holds a specific value and is referenced by a specific key:
(map_name, key, value)
To use a map, it does not need to be defined first, but it needs to be initialized using the command
CreateMap:
m = CreateMap();

4.4.9.3.2. Set and Retrieve Map Node Values

To manipulate the map node values, array like indexing or the following script functions
SetMapNode(m, key, value) and GetMapNode(m, key)
can be used.
The value of a map can be either a string or a number. However, the key can be a string, a number
or even another map. Nodes within the same map are sorted according to their key. The
corresponding precedence order is
String < map < number
For example, node (m,"1140",1) comes before node (m,1140,2), since the former node uses a
string-type key and the latter node uses a numeric key. Note that when maps are used as keys,
they are sorted according to the number of nodes they have, with larger maps taking precedence
over smaller maps.

Example

Array like Indexing Equivalent Command


m["1140"]=1 SetMapNode(m,"1140",1)
i = m["1140"] i = GetMapNode(m,"1140")

BETA CAE Systems 145 META Automation User’s Guide


4. Scripting

4.4.9.3.3. Delete Node Values

Deletion of a node within a map is achieved using the EraseMapNode command:


EraseMapNode(m, key);

4.4.9.3.4. Iteration through the Data of a Map

In order to search through the data of a map, the user must first identify the first or the last node of
the map using the GetFirstNode or the GetLastNode commands respectively:
i = GetFirstNode(m, key, value);
i = GetLastNode(m, key, value);
Both functions return 1 on success and 0 upon failure (e.g. when the map is empty or not defined).
Looping through the map is achieved using the GetNextNode and GetPreviousNode commands:
i = GetNextNode(m, key, value);
i = GetPreviousNode(m, key, value);

Example
for(ret=GetFirstNode(m,key,value); ret; ret=GetNextNode(m,key,value))
{
Print(key);
Print(value);
}
Remark
- The foreach command can also be used to loop through the data of map.

4.4.9.3.5. Check the existence of a node

To check the existence of a node inside a map, use the ExistMapNode:


existnode = ExistMapNode(m,key);

4.4.9.3.6. Destroy Map and Release Memory

To delete a map, use the DestroyMap:


DestroyMap(m);

4.4.9.3.7. Identify the Number of Map Nodes

To identify how many nodes a map contains, use the GetMapEntries:


i = GetMapEntries(m);
C = {{20,7,9},
{5,4,17}};

BETA CAE Systems 146 META Automation User’s Guide


4. Scripting

4.4.10. User functions


4.4.10.1. Introduction

User functions allow to group a set of operations into a compact unit that can be easily and
repeatedly accessed. The repetitive use of functions saves much time while reduces the chances of
error. Each user function is given a name, optionally uses some input parameters (arguments) and
returns the results as output parameters.

4.4.10.2. Definition

User functions are defined using the def statement. This statement is followed by the function
name. The rest of the code must be enclosed in brackets. A typical function has the form:
def main(list of arguments if exist)
{
.......
Statement
.......
}

4.4.10.3. Argument list and function call

Each user-defined function accepts a number of input arguments (<=40). These arguments are
passed as parameters and are used as initial values inside the function that is called. During the
declaration of a sub-function it is necessary to define explicitly the type of the input arguments: (int,
float, string, element etc)

Remarks
- A sub-function can be called from a main function or from another sub-function.
- Variable number of input arguments is not valid.

Examples:
def main()
{
Print("This is an example of a function");
}

def RectArea(int w, int h)


{
a = w * h;
return a;
}

BETA CAE Systems 147 META Automation User’s Guide


4. Scripting

4.4.10.4. Declaring functions as variables

A new functionality introduced after v6.3.0 enables the definition of functions‟ names as variables.
The benefits from this are multiple since all actions inside a code can be controlled parametrically.
A useful implementation could be the following: Imagine that it is needed to call different functions
with same data sequentially. Instead of using an if structure which makes the code difficult to
maintain, a parametric call would be more handy.
def main()
{
s = {1,3,"title"};
functs = {"test1","test2"};
for(i=0;i<2;i++)
{
functs[i](s);
}
}

def test1(matrix data)


{
...
}

def test2(matrix data)


{
...
}

4.4.10.5. Returning data from functions (return, byref call)

Since the target of each sub-function is to perform a certain task, there must be a way to notify the
main function that called it for the result of the procedure it performed.
The communication between the functions can be achieved through the return command. This
command can be used anywhere in the code and is followed by any data. A function that calls
another function can store the returned value in an output argument or even can ignore it.
Functions that don‟t return anything are executed normally and may not use the return command.
Equivalent, they can return a dummy value.

Return value No return Return dummy value


def main() def main() def main()
{ { {
a = 100; a = 100; a = 100;
b = 50; b = 50; b = 50;
result= substr(a,b); result = substr(a,b); result = substr(a,b);
Print(result); Print(result); Print(result);
} } }

def substr(int a,int b) def substr(int a,int b) def substr(int a,int b)


{ { {
res = a-b; res = a-b; res = a-b;
return res; } return 1;
} }

Only the data that are passing through the return command are valid for the main function.

Remarks
BETA CAE Systems 148 META Automation User’s Guide
4. Scripting

- If the return command is used in the main function, then the execution of the script is terminated.
Another way of exchanging data is through the byref statement. This is very useful in cases where
it is important for the user to know the new modified values of any variables that had been passed
to a sub-function.
def main()
{
width=10;
height=3;
area = RectArea(width, height);
}
def RectArea(byref int w, int h)
{
a = w * h;
w = 20;
return a;
}

In the above example, the values of the variables right before the end of the execution of the scripts
will be:

Variable Value
width 20
height 3
area 30
a not defined
w not defined
h not defined

Remarks
- The matrices, the maps, the structures and the pointers are considered byref by default.

BETA CAE Systems 149 META Automation User’s Guide


4. Scripting

4.4.10.6. Scope and lifetime of variables

A variable's scope is determined by its location. When a variable is declared within a function, then
only the function's code can access or change its value. It is then said that this variable is local to
the function. As a result, there is no conflict to have two or more variables of local character sharing
the same name in different functions.
In contrast to local variables, global variables are valid throughout the program, so they can be
accessed and changed by any individual function of the program. global variables must be
declared prior to the definition of any function (global section), and are defined either using the
global keyword or by declaring their type followed by their name. The type is auxiliary and helps
the language to distinguish a local from a global variable. As said before, the variables still remain
typeless. In the following script code the variables k, name, value, inline and i are considered
as global variables and j as local.
int k;
string name;
float value;

global inline = "test string";


global i = func();

def main()
{
j = 10;
Print(inline);
Print(i+j);
}

However, a variable can be declared as local and global simultaneously in the same script. In this
case it can be treated as being two different variables if using the scope operator „::‟
int a;
def main()
{
int a;
a = 3;//This value is assigned in local 'a'
::a = 5;// This value is assigned in global 'a'
i = a+1;
Print(i);
k = ::a+1;
Print(k);}
}

There is also a third type of variable called static. Static variables are the variables, which can keep
their value even if the execution of the script has come to an end. However, static variables retain
data only when the script file is loaded as a module.
In META, it is better to hold data between executions of functions using META variables.
def main()
{
i = Atoi(MetaGetVariable("meta_i"));
i = i++;
Print(i);
MetaSetVariable("meta_i", i);
}

BETA CAE Systems 150 META Automation User’s Guide


4. Scripting

The result after each execution will be:

Execution No i variable value


Execution 1 1
Execution 2 2
Execution 3 3

4.4.10.7. Public and private functions

A function can be hided even it is not a static one. This is very useful especially in cases where a
function must not be seen, accessed or invoked from other users. This function although is loaded
normally is not visible and thus it considered private. However, in META scripting language all
functions are by default public. The private: statement is used to create such functions while the
public: turns the code in the default status.
def main()
{
test1();
test2();
test3();
}

static def test1()


{
Print("test1");
}
//The function „test2‟ will be hidden
private:
def test2()
{
Print("test2");
}
public:

def test3()
{
Print("test3");
}

4.4.10.8. Including files

Scripting language enables the collection of several existing functions into a file. This declaration is
made with the #include statement. Each line like the one below:
#include "fullpath to the name of file"
is substituted from the contents of the included file (the quotes are necessary). The include
statement, must be declared in the global section of the script and its usage has two major
advantages:
1) The files remain short.
2) Assures that no mistake will be made since no cutting or pasting actions are performed.

#include "/home/work/CreatePoint_struct.bs"

BETA CAE Systems 151 META Automation User’s Guide


4. Scripting

def CreatePoint()
{
set_P point;//The set_p structure is placed in "CreatePoint_struct.bs"
//x,y,z members were defined in "CreatePoint_struct.bs"
point.x = 11;
point.y = 10;
point.z = 3;
}

Remarks
- It is recommended to avoid using include files for loading functions. On the contrary, they should
be used only for type definitions (structs, global variables, etc).

4.4.10.9. Including project files

External files can be treated also as project files. This declaration is made in the global section with
the #projectfile statement. Each line like the one below:
#projectfile "fullpath to the name of file"

it is NOT substituted from the contents of the project file (the quotes are necessary) but only
enables the usage of file contents. Static variables sharing the same name but located in different
project files are loaded normally.

4.4.10.10. Compilation control (Preprocessor)

META scripts can be compiled only through Script Editor (see also respective Chapter). The
compiled script is treated as any other script - regarding loading and executing - but it cannot be
edited since it is not human readable anymore.
Sometimes, a code must be partially compiled either for security reasons or for keeping as small as
possible the size of a file. This job is controlled through the internal script preprocessor which
searches for specific statements/keywords. A part of a code is defined in the preprocessor via the
#define keyword followed by an identifier which can be anything:
#define status
The existence of an identifier is checked through the #ifdef, #if defined and #ifndef keywords. All
definitions can be optionally combined with an #else statement but definitely must end with an
#endif. The code between the above statements is ignored.
Suppose that a script must be compiled and specific users need to have different level of access to
included functions. In this case, it would be very annoying and time consuming to maintain two or
more versions of the script. Thus, the best solution would be to assign the relevant functions in the
pre-processor.
The compiled version of next script is appealed to „user1‟ and will not contain the function
„fun_for_user2‟.
If the user that is going to use the script is „user2‟ then just comment out (//) the first line:
„#define user1‟ and uncomment the second one:
„#define user2‟.
In this case the „fun_for_user1‟ will be ignored. In the same way different compilations schemes

BETA CAE Systems 152 META Automation User’s Guide


4. Scripting

can be done according to user needs.

Remarks
- The logical operators: !, ||, && are allowed.
#define FOO
#define GOO
#define ZOO
#if defined FOO && (!defined GOO || defined ZOO)

def main()
{

#endif

Another use of preprocessor is to protect the user from loading a part of a code more than once. A
concrete example is when a file includes some scripts and additionally one of them includes again
at least one of the previous included scripts. If the double defined script contain only user functions
this wouldn‟t be a problem because the last read will be kept. But, if the script contains global code
like a struct definition this can cause problems. To avoid this, it is recommended to add within all
included scripts a series of preprocessor statements that will ensure no multiple definitions.
Consider that Script1 is used as include and contains only a structure defined in the global section.
Script2 includes Script1 and Script3 which in turn includes Script1.

BETA CAE Systems 153 META Automation User’s Guide


4. Scripting

Script1 Script2 Script3


struct{ #include Script1 #include Script1
float x; #include Script3
float y; def fun3()
float z; def fun1() {
}sruct_name; { ...
}
}

Such an improper definition leads to a syntax error and no loading takes place. If instead, the
structure had been defined as part of the preprocessor, the corresponding code would be loaded
only once and any other time the Script1 was invoked, it would be ignored.
Thus the correct approach could be the following:

Script1 Script2 Script3


#ifndef structure #include Script1 #include Script1
#define structure #include Script3
def fun3()
struct{ def fun1() {
float x; { ...
float y; }
float z; }
}sruct_name;
end if
The pre-processor is also able to distinguish the current operating system using the reserved
keywords LINUX, WINDOWS, MAC, AIX, HPUX, SUN. A very useful application is to load the same
scripts using different file paths depending on the OS. Most likely, such a case occurs between
windows and any UNIX system:
#if defined WINDOWS
#include "C:\users\work\common\test.bs"
#endif
#if defined LINUX
#include "/home/common/test.bs"
#endif

Finally, the identifiers MACHINE_NAME and USR_NAME can be used in the same manner for
acquiring the name of the machine and the user's name.

BETA CAE Systems 154 META Automation User’s Guide


4. Scripting

4.4.10.11. Recursive structures

Recursive structures are supported in scripting language. This means that a function can call itself
as many times as needed. Recursive structures in META have been proved very helpful when
trying to search into entities that have a hierarchical structure. A common example is the extraction
of all META files that exist under a directory tree.
def main()
{
filenames = 0;
path = "/home/demo/model";
type = "META";
parse_tree(filenames,path,type);
}

def parse_tree(matrix filenames,string path,string type)


{
f = FileList(path+"/*"+type);
no_of_files = MatLen(f);
if(f!=0){
foreach file in f{
filenames[i++] = file;
Print(file);
}
}
m = DirList(path);
if(m!=0)
{
foreach d in m{
new_path = path+"/"+d;
parse_tree(filenames,new_path,type);
}
}
}

BETA CAE Systems 155 META Automation User’s Guide


4. Scripting

4.4.10.12. Initialization of matrices and variables

A well-structured algorithm implies that any variables or matrices that change their values during
the execution of a script must be first initialized. The initialization is very crucial especially when a
variable is used as counter for filling the indices of a matrix. Variables or matrices are initialized by
assigning to them an initial value (zero value is preferred in most of the cases).
To release the memory occupied by matrices, the ReleaseVar function can be used to reset them
to uninitialized state. This function comes handy in cases an existing matrix must be refilled with
new data.
def main()
{
//Initialize counter i
i = 0;
//Initialize matrix m
m = 0;
//Define matrix data1
data1 ={10,20,30,40};
len = MatLen(data1);
for(k=0;k<len;k++)
{
m[i++] = data[k];
}
.....
statements
.....
data2 ={1,2,3,4};
ReleaseVar(m);
len = MatLen(data2);
for(k=0;k<len;k++)
{
m[i++] = data[k];
}
.....
statements
.....
}

Initialization of variables can also be done in global section but only if they are preceded by their
type. For example all the following declarations made in global section are valid.
int a = 10;
float b = 2.5;
string s = "alpha";

def main()
{
c = a+b+100;
Print(c);
}

Keep in mind that the type is not binding since it is only used for syntax checking. Thus, it can be
changed anytime.
Finally, a variable can get an initial value from a function call not only within the function code but in
global section too. This is the way of invoking a function before the 'main' or other user defined

BETA CAE Systems 156 META Automation User’s Guide


4. Scripting

function. Again, it is essential to assign a certain type to the variable.


//Global code
int a = InitVal();

def main()
{
...
...
}

def InitVal()
{
no_of_props = MatLen(CollectEntities(NASTRAN,0,"PSHELL"));
return no_of_props;
}

4.4.10.13. Help text and comments

Past experience has proven that even experienced programmers need to write some comments
within the code to make it more readable and understandable. In META scripting language there
are two ways to add comments. Using the symbol // ideal for single-line comments and including
multiple-line comments within the bounds of a /* comment */.
def my_fun()
{
part p;
matrix group_parts;
model_id = 0; //Define the id of the model
group_name = "My_Group"; //Define the name of the group
//Collect the parts
group_parts = PartsOfGroup(model_id, group_name);
/*Print the id and the name
of the collected parts*/
foreach p in group_parts {
Print(p.id+”: ”+p.name);
}
}

A comment line denoted by // symbol can be incorporated in a comment block (/* comment */).
A script function can also have its own help description. This description is a text that must be
enclosed between the symbols ## and must be written always prior to the function which describes.
##
Name: NcogToSet
Description: Function that adds the Ncog nodes of PAMCRASH rbodies to a
set
##

def NcogToSet()
{
statement
}

The user script help can be accessed through the File>Script>Run function.

BETA CAE Systems 157 META Automation User’s Guide


4. Scripting

4.4.11. META session commands within scripts


Inside a script, any META command can be applied. This can be achieved through the following
command:
MetaCommand (string command);
The command has to be input as a string, so it has to be placed between quotation marks “…”, e.g.
MetaCommand ("color background red");
If the command already contains quotation marks the backslash \ must proceed each quotation
mark to notify that the following “ is used as symbol and not to declare the ending of the string.
MetaCommand ("write tif \"/home/demo/one folder/image1.tif\" 0.9");
Any string operation is acceptable for the string given as argument for the MetaCommand.
So, the values of variables can also be used:
file = "/home/demo/one folder/image1.tif";
MetaCommand ("write tif \""+file+"\" 0.9");
command = "write tif \""+file+"\" 0.9";
MetaCommand (command);

BETA CAE Systems 158 META Automation User’s Guide


4. Scripting

4.4.12. Interacting with MΕΤΑ


4.4.12.1. General

The basic idea behind the scripting language is to automate many repetitive and tedious
procedures with the minimum user interaction and to perform specific tasks that are not covered by
the standard META commands and META session capabilities. Some of the tasks that can be
performed within scripting language are the following:
- Extracting any type of information from an already loaded model (data from nodes, elements,
boundary elements, materials, models, coordinate systems and groups).
- Access and manipulate data from META entities like annotations, groups, cut planes and
isofunctions.
- Manipulating 2D plots: create and select curves, access data from curves and their points and
modify them.
- Creating new results (deformation-scalar-vector) on nodes and elements with custom calculated
data.
- Creating and manipulate META 3D and 2D windows.
- Creating user-defined windows.
- Manipulating files and directories.
- Reading and writing ASCII and binary files.
- Creating and handling data in XML form.
- Use of session commands.
- Use of system commands.
- Running automatically (after launching META) a series of functions.
- Communication with the interface (File Manager functions, Pick functions).
All these tasks that can interact with the model and META entities data are controlled through a
series of META specific functions. Before proceeding to the explanation of individual functions, it is
important to emphasize the meaning of meta structs.

4.4.12.2. Handling data


4.4.12.2.1. Introduction

As mentioned in Chapter 1, one of the data types that are used within scripting language is the user
structure data type. In META the data all entities, either model entities (nodes, elements, etc) or
META entities (cut planes, annotations, etc) can be accessed through the use of META structs.
META structs is a special group of variables with struct data type, introduced in version v6.2.0.
These structs are used to carry information about entities in META and through them it is possible
to access and modify their data. In order for meta structs to be used, they need to be defined first.
Their definition exists in the file meta_structs, which is provided with the META software inside the
folder config. This file must be included in each script that uses meta structs through the keyword
#include "meta_structs"
The above line is inserted automatically each time the user selects to create a new script. With the
above line, META searches to find the file in the config directory.

BETA CAE Systems 159 META Automation User’s Guide


4. Scripting

4.4.12.2.2. META structs

The available META structs are the following:

Model:
META Struct model is used to carry information about the models loaded in META. It has the
following structure:
struct {
int id; // Model number - Id
string name; // Filename of the model
string label; // Label of the model
string deck; // Deck name of the model
int active; // 1 if model is active, 0 if model is not active
} model;

Elem:
META Struct elem is used to carry information about the elements of models loaded in META. It
has the following structure:
struct {
int id; // Id of the element
int second_id; // Second id of the element (GAP, TUBE, JOINT) , -1 if
there is not a second id
int model_id; // Model number of the element
int type; // Type of the element (META KEYWORD)
int subtype; // Subtype of the element
int visible; // 1 if element is visible, 0 if model is not visible
int part_id; // Id of the part it belongs to, -1 if element belongs to
no part
} elem;

The type of the element is described through an integer index number corresponding to specific
META KEYWORD. However, the user can use the expression
variable = <META KEYWORD>
to assign the value of the integer corresponding to this META KEYWORD to the variable.

Example
el_type= QUAD4
will assign the value 3, to variable el_type.
The expression SHELL can be used to denote all the respective shell element META KEYWORDS
- TRIA3, TRIA6, QUAD4, QUAD8.
The expression SOLID can be used to denote all the respective solid element META KEYWORDS -
TETRA, PENTA, HEXA, TETRA10, PENTA14, HEXA20.
There is a correspondence between the integer, the META KEYWORDS and the KEYWORDS of
each deck.

BETA CAE Systems 160 META Automation User’s Guide


4. Scripting

Node:
META Struct node is used to carry information about the nodes loaded in META. It has the
following structure:
struct {
int id; // id of the node
int model_id; // Model number of the node
float x; // X coordinate of node
float y; // Y coordinate of node
float z; // Z coordinate of node
visible; // 1 if node is visible, 0 if node is not visible
} node;

Part:
META Struct part is used to carry information about the parts loaded in META. It has the following
structure:
struct {
int id; // Id of the part
int model_id; // Model number of the part
int type; // Type of the part (META KEYWORD)
int subtype; // Subtype of the part
int visible; // 1 if part is visible, 0 if part is not visible
string name; // Name of the part
int mat_id; // The id of the corresponding to the part material
float shell_thick; // Shell thickness for PSHELL, or -1 for rest types
of parts
} part;

The type of the part is described through an integer index number corresponding to specific META
KEYWORD. However, the user can use the expression
variable = <META KEYWORD>
to assign the value of the integer corresponding to this META KEYWORD to the variable.

Example
part_type= PROD
will assign the value 1 to variable part_type.

Boundary:
META Struct boundary is used to carry information about the boundary elements loaded in META.
It has the following structure:
struct {
int id; // Id of the boundary element
int second_id; // Second id of the boundary element
int model_id; // Model number of the boundary element
int type; // Type of the boundary element (META KEYWORD)
int subtype; // Subtype of the boundary element
int visible; // 1 if boundary element is visible, 0 if boundary
element is not visible
} boundary;

BETA CAE Systems 161 META Automation User’s Guide


4. Scripting

The type of the boundary element is described through an integer index number corresponding to
specific META KEYWORD. However, the user can use the expression
variable = <META KEYWORD>
to assign the value of the integer corresponding to this META KEYWORD to the variable.
Example
bound_type = SPC
will assign the value 1 to variable bound_type.

Material:
META Struct material is used to carry information about the materials loaded in META. It has the
following structure:
struct {
int id; // Id of the material
int model_id; // Model number of the material
int type; // Type of the material (META KEYWORD)
string name; // Name of the material
} material;
The type of the material is described through an integer index number corresponding to specific
META KEYWORD. However, the user can use the expression
variable = <META KEYWORD>
to assign the value of the integer corresponding to this META KEYWORD to the variable.
Example
mat_type = MAT1
will assign the value 1 to variable mat_type.

Page:
META Struct page is used to carry information about the existing pages in a META session. It has
the following structure:
struct {
int id; // id of the page
string name; // name of the page
int active; // 1 if page is active, 0 if page is not active
} page;

Window:
META Struct window is used to carry information about the existing windows in a META session. It
has the following structure:
struct {
string name; // Name of the window
int active; // 1 if window is active, 0 if window is not active
int width; // The width of the window
int height; // The height of the window
int plot2d; // 1 if it is a plot2D window, 0 if window is not a plot2d
(3D window)
int enabled; // 1 if window is enabled, 0 if window is not enabled
int page_id; // id of the page of the window
} window;

BETA CAE Systems 162 META Automation User’s Guide


4. Scripting

Group:
META Struct group is used to carry information about the current groups in a META session. It has
the following structure:
struct {
string name; // Name of the group
int model_id; // Model number of the group;
string module_id; // Module id
string version; // Version
string representation; // Representation
string study_version; // Study version
string vsc_number; // VSC number
float target_mass; // Target mass
string user_group; // User group
int pid_offset; // Pid offset
int freeze; // Freeze
string type; // Type of the group ("part", "set", "boundary",
"connection", "include")
int instance; // Instance of the group
} group;

Resultset:
META Struct resultset is used to carry information about results which can be loaded in META. It
has the following structure:
struct {
int cycle; // Cycle number of the resultset
int model_id; // Model number of the resultset
string name; // Name of the resultset
string nodal_data_name; // Nodal data name of the resultset, NONE if
it does not exist
string function_data_name; // Function data name of the resultset,
NONE if it does not exist
string filename; // Filename of the resultset
int subcase; // Subcase of the resultset
float state; // State of the resultset
float step; // Step of the resultset
float frequency; // Frequency of the resultset
float time; // Time of the resultset
int mode; // Mode of the resultset
float eigenvalue; // Eigenvalue of the resultset
float imaginary_eigenvalue; // Imaginary eigenvalue of the resultset
float loadstep; // Loadstep of the resultset
int generate_sequence; // Generate number of the resultset
int internal1; // System use only
int internal2; // System use only element
int internal3; // System use only
string nodal_data_label; // Nodal data label of the resultset, NONE if
it does not exist
string function_data_label; // Function data label of the resultset,
NONE if it does not exist
string vector_data_label; // Vector data label of the resultset, NONE
if it does not exist
string vector_data_name; // Vector data name of the resulsett, NONE if
it does not exist
} resultset;

BETA CAE Systems 163 META Automation User’s Guide


4. Scripting

Deformation:
META Struct deformation is used to carry information about the deformation data on a node. It has
the following structure:
struct {
float x; // X deformation
float y; // Y deformation
float z; // Z deformation
float total; // Total deformation
int node_id; // Node id
} deformation;

Modal Deformation:
META Struct modal deformation is used to carry information about the modal deformation data on a
node. It has the following structure:
struct {
float x; // X deformation
float y; // Y deformation
float z; // Z deformation
float rx; // Rotational X deformation
float ry; // Rotational Y deformation
float rz; // Rotational Z deformation
int node_id; // Node id
} modal_deformation;

Nodal_scalar:
META Struct nodal_scalar is used to carry information about scalar function data on a node. It has
the following structure:
struct {
float value; // Value
int node_id; // Node id
int part_id; // Id of the part of the nodal scalar value, or -1 for
nodes not belonging to a part
} nodal_scalar;

Centroid_scalar:
META Struct centroid_scalar is used to carry information about scalar function data on the centroid
of an element. It has the following structure:
struct {
float value; // Value
int element_id; // Element id
int second_id; // Element second id
int type; // Element type (META KEYWORD)
} centroid_scalar;

Corner_scalar:
META Struct corner_scalar is used to carry information about scalar function data on the corners of
an element. It has the following structure:
struct {
float value; // Value
int element_id; // Element id

BETA CAE Systems 164 META Automation User’s Guide


4. Scripting

int second_id; // Element second id


int type; // Element type (META KEYWORD)
float corner; // Node id for shell and solid elements, or the fraction
of the distance from the start to the total distance
for line elements
} corner_scalar;
Nodal_vector:
META Struct nodal_vector is used to carry information about vector function data on a node. It has
the following structure:
struct {
float value; // Value
float x; // Normalized coordinate X of vector
float y; // Normalized coordinate Y of vector
float z; // Normalized coordinate Z of vector
int node_id; //Node id
int part_id; // Id of the part of the nodal vector value, or -1 for
nodes not belonging to a part
} nodal_vector;

Centroid_vector:
META Struct centroid_vector is used to carry information about vector function data on the centroid
of an element. It has the following structure:
struct {
float value; // Value
float x; // Normalized coordinate X of vector
float y; // Normalized coordinate Y of vector
float z; // Normalized coordinate Z of vector
int element_id; // Element id
int second_id; // Element second id
int type; // Element type (META KEYWORD)
} centroid_vector;

Plot:
META Struct plot is used to carry information about 2D plots in a META session. It has the following
structure:
struct {
int id; // Plot number - Id
string window_name; // Name of the window
int active; // 1 if plot is active, 0 if plot is not active
string type; // Type of the plot (plain, realimag, magphase, polar)
int page_id; // id of the page of the window
} plot;

Curve:
META Struct curve is used to carry information about curves in a META session. It has the
following structure:
struct {
int id; // Curve id
int plot_id; // Plot number of the curve
string window_name; // Name of the plot2d window of the curve
string name; // Name of the curve
int visible; // 1 if curve is visible, 0 if it is not visible
BETA CAE Systems 165 META Automation User’s Guide
4. Scripting

int selected; // 1 if curve is selected, 0 if it is not selected


int page_id; // id of the page of the window
string command; // Command of META from which curve has been created
int entity_id; // Id of the corresponding entity of the curve
} curve;
Point:
META Struct point is used to carry information about points of curves in a META session. It has the
following structure:
struct {
int id; // Id of the point
float x; // X coordinate of the point
float y; // Y coordinate of the point
int selected; // 1 if point is selected, 0 if it is not selected
} point;

Coord_system:
META Struct coord_system is used to carry information about coordinate systems in META. It has
the following structure:
struct {
int id; // Id of the coordinate system
int model_id; // Model number of the coordinate system
int type; // Type of the coordinate system (META KEYWORD)
matrix origin; // Origin
matrix xaxis; // X-axis
matrix yaxis; // Y-axis
matrix zaxis; // Z-axis
int visible; // 1 if coordinate system is visible, 0 if coordinate
system is not visible
int ref_id; // Id of the reference coordsystem, -1 if no reference
coordsystem exists
} coord_system;
The type of the coordinate system is described through an integer index number corresponding to
specific META KEYWORD. However, the user can use the expression
variable = <META KEYWORD>
to assign the value of the integer corresponding to this META KEYWORD to the variable.

Example
coord_type= COORD1R
will assign the value 1 to variable coord_type.

Annotation:
META Struct annotation is used to carry information about annotations in a META session. It has
the following structure:
struct {
int id; // Id of the annotation
string window_name; // Name of the window of the annotation
string text; // Displayed text of the annotation
string origin_text; // String with variables of the annotation
int visible; // 1 if annotation is visible, 0 if it is not visible

BETA CAE Systems 166 META Automation User’s Guide


4. Scripting

int selected; // 1 if annotation is selected, 0 if it is not selected


int page_id; // id of the page of the window
} annotation;

Color:
META Struct color is used to carry information about colors in a META session. It has the following
structure:
struct {
string name; // Name of the color
int r; // Red value [0..255]
int g; // Green value [0..255]
int b; // Blue value [0..255]
int a; // Alpha value [0..255]
} color;

Image:
META Struct image is used to carry information about the existing images in a META session. It
has the following structure:
struct {
string name; // Name of the image
string window_name; // Name of the window
int width; // Width of the image
int height; // Height of the image
string filename; // Filename of the image
int zorder; // Z-order of the image
int visible; // 1 if image is visible, 0 if it is not visible
int page_id; // Id of the page of the image
}image;

Video:
META Struct video is used to carry information about the existing videos in a META session. It has
the following structure:
struct {
string name; // Name of the video
string window_name; // Name of the window
int width; // Width of the video
int height; // Height of the video
string filename; // Filename of the video
int zorder; // Z-order of the video
int visible; // 1 if video is visible, 0 if it is not visible
int page_id; // Id of the page of the video
int frames; // Number of video frames
} video;
Plane:
META Struct plane is used to carry information about the existing planes in a META session. It has
the following structure:
struct {
string name; // Name of the plane
string clip_type; // Clip type ("plane", "section", "none")

BETA CAE Systems 167 META Automation User’s Guide


4. Scripting

matrix origin; // Origin of plane


matrix normal_vector; // Normal vector of plane
matrix edge_vector; // Edge vector of plane
} plane;

Isofunction:
META Struct isofunction is used to carry information about the existing isofunctions in a META
session. It has the following structure:
struct {
string name; // Name of the isofunction
string window_name; // Name of the window
string type; // Type of the isofunction ("function", "xdeform",
"ydeform", "zdeform", "tdeform")
float value; // Value of the isofunction
int visible; // 1 if isofunction is visible, or 0 if it is not visible
int page_id; // Id of the page of the isofunction
} isofunction;

Element Coordinate System:


META Struct element coordinate system is used to carry information about the coordinate systems
of elements. It has the following structure:
struct {
int id; // Id of the element
int second_id; // Second id of the element (GAP, TUBE, JOINT) , -1 if
there is not a second id
int model_id; // Model number of the element
int type; // Type of the element (META KEYWORD)
matrix origin; // Origin of the coordinate system
matrix xaxis; // X-axis of the coordinate system
matrix yaxis; // Y-axis of the coordinate system
matrix zaxis; // Z-axis of the coordinate system
} elem_coord_system;
Part Layer:
META Struct part layer is used to carry information about the layers of a composite part. It has the
following structure:
struct {
int serial; // Serial number of the layer
int id; // Id of the layer
int part_id; // Id of the part of the layer
int part_type; // Type of the part of the layer
int model_id; // Model number of the layer
int material_id; // Id of the material of the layer
string name; // Name of the layer
float thickness; // Thickness
float theta; // Theta
int ips; // Number of layer integration points
} part_layer;
Curve Group:
META Struct curve group is used to carry information about the existing curve groups in a META
session. It has the following structure:

BETA CAE Systems 168 META Automation User’s Guide


4. Scripting

struct {
string name; // Name of the curve group
int plot_id; // Plot number of the curve group
string window_name; // Name of the window
int page_id; // Id of the page of the curve group
} curve_group;
Annotation group:
META Struct annotation group is used to carry information about the existing annotation groups in a
META session. It has the following structure:
struct {
string name; // Name of the annotation group
string window_name; // Name of the window
int page_id; // Id of the page of the annotation group
} annotation_group;
Plot Axis:
META Struct plot axis is used to carry information about the x and y axes of a META 2d window. It
has the following structure:
struct {
int id; // Plot axis id
string type; // Plot axis type ("xaxis", "yaxis", "caxis")
int plot_id; // Plot number
string window_name; // Name of the plot2d window of the plot axis
int active; // 1 if plot axis is active, or 0 if it is not active
int visible; // 1 if plot axis is visible, or 0 if it is not visible
float min_value; // Minimum value of plot axis
float max_value; // Maximum value of plot axis
int page_id; // Id of the page of the plot axis

} plot_axis;
Connection:
META Struct connection is used to carry information about connections in META. It has the
following structure:
struct {
int id; // Id of the connection
int model_id; // Model number of the connection
int type; // Type of the connection (META KEYWORD)
int subtype; // Subtype of the connection (META KEYWORD)
} connection;
Plot_model:

META Struct plot_model is used to carry information about loaded plot models like time history
files (2d models) in a META session. It has the following structure:
struct {
int id; // Id of the plot_model
string deck; // Deck name of the model
string filename; // Filename of the resultset
} plot_model;

BETA CAE Systems 169 META Automation User’s Guide


4. Scripting

Spreadsheet cell:
META Struct connection is used to carry information about cells in Spreadsheet Editor in META.
struct {
int row; // Row number of the spreadsheet cell
int col; // Column number of the spreadsheet cell
string cell_label; // Label of the spreadsheet cell (e.g. A1)
string spreadsheet; // Name of the parent spreadsheet
string text; // Displayed text of the spreadsheet cell
string orig_text; // Original (not parsed) text of the spreadsheet
cell
} spreadsheet_cell;

4.4.12.3. Collect entities


4.4.12.3.1. Introduction

In META there is a separate group of script functions for META entities. For example, there are
Element functions to collect the elements, Node functions to collect the nodes, etc.
Additionally, there are the following generic functions CollectEntities to collect all the specified
entities that are loaded in META:

Function Description
CollectEntities Collect all existing entities of the specified type in the current
META session
CollectModelEntities Collect all existing entities of the specified type in a model
CollectWindowEntities Collect all existing entities of the specified type in a window

The types of entities that can be collected using these functions are:
ANNOTATIONs
BOUNDARIEs
COORDINATE SYSTEMs
CUT PLANEs
ELEMENTs (SHELLs, SOLIDs, BEAMs, etc)
GROUPs
ISOFUNCTIONs
MATERIALs
META WINDOW entities (WINDOWs, FRINGEs, COLORs)
MODELs
NODEs
PAGEs
PARTs
PLOT2d entites (PLOTs, CURVEs and POINTs)
RESULTSETs
FRINGEs
VISUAL entities (FRAMEs, IMAGEs, VIDEOs)

BETA CAE Systems 170 META Automation User’s Guide


4. Scripting

4.4.12.3.2. Collect entities of the database

For collecting all entities, the appropriate functions are the functions with just the type of the entities
to be collected, e.g. Annotations(), Boundaries(), LoadsOfBoundary(),Elements(), Nodes(), Parts(),
Models(), Groups(),Resultsets(), Connections(), etc. Please note that Groups refer to the entities
Parts/Groups of Part Manager, Includes, Boundaries, Connections, Sets
In the case of model entities, the model id is given as argument.
To access the entities directly according to their id, the matrix with the model structs can be
converted to a map with the XxxMatrixToMap() functions where the key is the entities' id, e.g.
AnnotationsMatrixToMap(), ElementsMatrixToMap(), etc.
#include "meta_structs"

def main()
{
part p;
matrix all_parts;
model_id = 0;
all_parts = Parts(model_id);
foreach p in all_parts {
Print(p.id); Print(p.type); Print(p.subtype);
Print(p.visible);
Print(p.name); Print(p.mat_id); Print(p.shell_thick);
Print(p.model_id);
}
map_parts = PartsMatrixToMap(all_parts);
for(i=GetFirstNode(map_parts,part_id,p); i;
i=GetNextNode(map_parts,part_id,p))
{
Print(p.id); Print(p.name);
}
p = map_parts[ 10 ]; //Get directly part with id 10
Print(p.name);
DestroyMap(map_parts);
}

To get the entities types of a model directly, the functions XxxTypeXxx() are available, e.g.
ElementsTypes(), CurvesTypesNastran(), DeformationTypes(), ScalarTypes(), VectorTypes() etc.

#include "meta_structs"

def main()
{
matrix all_types;
int element_type;
model_id = 0;
all_types = ElementsTypes(model_id);
foreach element_type in all_types {
Print(element_type);
}
}

BETA CAE Systems 171 META Automation User’s Guide


4. Scripting

To retrieve deformation results types of a file the following can be used.


#include "meta_structs"

def main()
{
string deform_type;
string state;
matrix one_type;
matrix all_types;
filename = "/home/proj1.metadb";
deck = "METADB";
all_types = DeformationTypes(filename, deck);
foreach one_type in all_types {
total = MatLen(one_type);
deform_type = one_type[0]; // Deformation type
Print(deform_type);
for(k = 1; k < total; k++) {
state = one_type[k];
Print(state);
Print(k); // Id of the state
}
}
}

For curves types of Dyna, Pamcrash and Radios files the functions
CurvesTypesDynaWithNames(), CurvesTypesPamcrashWithNames() and
CurvesTypesRadiosWithNames() are available to get also their name.

4.4.12.3.3. Collect entities according to their attributes (results, name, id, type, position,
comments, failure, free, outer)

There are specific functions in order to collect entities according to one of their attributes, e.g.
NodesByName(), NodesByField10(), ElementById(), CurvesByName(), ElementsByType(),
FailedElements, FreeNodes(), OuterElements(), FollowNodes() etc.
#include "meta_structs"

def main()
{
part p;
matrix collected_parts;
model_id = 0;
part_type = PSHELL;
collected_parts = PartsByType(model_id, part_type);
foreach p in collected_parts {
Print(p.id); Print(p.type); Print(p.subtype)
Print(p.visible);
Print(p.name); Print(p.mat_id); Print(p.shell_thick);
Print(p.model_id);
}
}
When the function returns only one entity (e.g. ElementById()), then it returns the meta_struct of
this entity, when it may return more than one entities (e.g. ElementsByType()), then it always
returns a matrix with meta_structs (even when only one entity is returned).
For entities that need to be collected and which are neighbors of other entities, the functions

BETA CAE Systems 172 META Automation User’s Guide


4. Scripting

NeighbourElements(),NeighbourMaterials(),NeighbourParts() etc can be used. Neighboring entities


are those which are directly attached to the specified entity or calculated by the solver.
For entities that need to be collected according to their nearest relative position to one given point,
the functions NearestNodeOfPart, NearestNodeOfGroup, NearestElementOfPart,
NearestElementOfGroup, NearestNodeOfMaterial, NearestElementOfMaterial etc can be used.
When entities need to be collected according to results (deformation, scalar, vector) or according to
more advanced filters, then the functions AdvFiltersOnXxx() and XxxFromAdvFilters() can be used,
e.g. AdvFiltersOnNodes(), AdvFiltersOnPoints, ElementsFromAdvFilters(), etc.. The difference
between AdvFiltersXxx() and XxxFromAdvFilters() functions is that in AdvFiltersXxx() the filters are
given as a string argument to the functions, whereas in XxxFromAdvFilters() the execution of the
script will stop and a window will open in order for the user to specify the advanced filters.
An easy way to build the string argument with the advanced filters for AdvFiltersXxx() is to apply an
iFilter from GUI inside a META session. The string, that corresponds to the filters selected, will be
shown as argument of the applied META command in the command line or in the current
META_post.ses.
#include "meta_structs"
def main()
{
elem e;
matrix collected_elements;
matrix adv_filters;
adv_filters[0] = "add:Parts:id:==1:Keep All";
adv_filters[1] = "intersect:Elements:centroidfuncmax::Max 3";
resultset result;
model_id = 0;
all_resultsets = Resultsets(model_id);
result = all_resultsets[1];
collected_elements = AdvFiltersOnElements(model_id, adv_filters,
result);
foreach e in collected_elements {
Print(e.id);
}
}

#include "meta_structs"
def main()
{
curve c;
matrix collected_curves;
window_name = "Window1";
collected_curves = CurvesFromAdvFilters(window_name);
foreach c in collected_curves {
Print(c.id); Print(c.name);
}
}

BETA CAE Systems 173 META Automation User’s Guide


4. Scripting

4.4.12.3.4. Collect entities from other entities

There are many functions to collect entities from other entities, e.g. ElementsOfPart(),
NodesOfElement(), ElementsOfNode(), PartsOfGroup(), etc. There is a separate function for each
combination of the entities to collect and the entity that these belong to.
There are also functions that collect only the entities with specific attributes from other entities, e.g.
ElementsOfNodeByType(), VisiblePartsOfGroupByType(), SelectedCurvesOfWindow(), etc.
#include "meta_structs"

def main()
{
part p;
matrix group_parts;
model_id = 0;
group_name = "My_Group";
group_parts = PartsOfGroup(model_id, group_name);
foreach p in group_parts {
Print(p.id);
Print(p.type);
Print(p.subtype);
Print(p.visible);
Print(p.name);
Print(p.mat_id);
Print(p.shell_thick);
Print(p.model_id);
}
}

4.4.12.3.5. Collect visible entities

For collecting the visible entities, the appropriate functions are the functions which include the word
visible, e.g. VisibleAnnotations(), VisibleElements(), VisibleCurves(), etc.
There are also functions that collect only the visible entities with specific attributes, or only the
visible entities from another entity, or only the visible entities with specific attributes from another
entity, e.g. VisibleElementsByType(), VisiblePartsOfGroup(), VisiblePartsOfGroupByType(),
VisibleCurvesOfPlot(), etc.
#include "meta_structs"

def main()
{
part p;
matrix visible_parts;
model_id = 0;
group_name = "My_Group";
window_name = "Window1";
visible_parts = VisiblePartsOfGroup(model_id, group_name,
window_name);
foreach p in visible_parts {
Print(p.id);
Print(p.type);
Print(p.subtype);
Print(p.visible);
Print(p.name);
Print(p.mat_id);
Print(p.shell_thick);
BETA CAE Systems 174 META Automation User’s Guide
4. Scripting

Print(p.model_id);
}
}

4.4.12.3.6. Collect identified entities

For getting only the identified entities of a model the respective functions are IdentifiedXxx(), e.g.
IdentifiedElements(), IdentifiedNodes(), IdentifiedParts(), etc.

4.4.12.3.7. Collect models information

There is a series of functions to get information from the loaded models, like NumOfNodes(),
NumOfModels(), NumOfPartsByType(), etc.
Also information only for the active Models, Pages, Plots, Plot axes and Windows can be retrieved
through the functions ActiveModels(), ActivePages(), ActivePlots(),ActivePlotAxes() and
ActiveWindows().
#include "meta_structs"
def main()
{
model r;
matrix act_models;
act_models = ActiveModels();
foreach r in act_models {
Print(r.id); Print(r.name); Print(r.label); Print(r.deck);
Print(r.active);
}
}

Information about the currently loaded plot models (the plot files listed in the Read Results >
Curves > Files List) that may exist can be retrieved through the function PlotModels().
#include "meta_structs"
def main()
{
plot_model pmod;
matrix plot_models;
plot_models = PlotModels();
foreach pmod in plot_models {
Print(pmod.id); Print(pmod.deck); Print(pmod.filename);
}
}

4.4.12.3.8. Collect newly created entities

For collecting all newly created entities of a specific type, the respective functions to use are
CollectNewXxxStart(), ReportNewXxx() and CollectNewXxxEnd()
The syntax is, for example: CollectNewAnnotationsStart(), ReportNewAnnotations(),
CollectNewAnnotationsEnd(), etc.
This can be very useful in order to get the number and ids of entities created through filters or
session Commands.
For example, for curves created through the Curve Function User Defined the function
BETA CAE Systems 175 META Automation User’s Guide
4. Scripting

ReportNewXxx() will return the entity‟s structs without ending the recording of the created entities.

To collect newly created entities within a period, the functions to use are CollectNewXxxStart() and
CollectNewXxxEnd()
#include "meta_structs"

def main()
{
curve c;
matrix new_curves;
MetaCommand("xyplot read pamcrash
\"Window1\" \"/home/demo/example.THP\" Node 1/2 xd”);
CollectNewCurvesStart();
MetaCommand("xyplot curve function userdef \"Displacement
Difference\" \"c1.x\" \"c1.y-c2.y\" \"Window1\"”);
new_curves = CollectNewCurvesEnd();
foreach c in new_curves {
Print(c.id);
Print(c.name);
Print(c.plot_id);
Print(c.visible);
Print(c.selected);
Print(c.window_name);
Print(c.page_id);
Print(c.command);
Print(c.entity_id);
}
}
4.4.12.3.9. Collect files and directories

For collecting efficiently a number of files (of specific formats) or directories, the commands FileList
and DirList must be used. Actually, these functions return a matrix with all the paths that were
identified. Then, these paths can be passed as strings in other functions.
When it is needed to identify a directory hierarchy it is recommended to use the DirList recursively.
A typical example is when a number of solver files, that exist in many directories, must be found:
Suppose that all the files exist under 5 directories which are located under a folder named
'my_project'. A simple code should be like the following:
def main()
{
//Get the 5 directories and store the paths into the matrix "dirs".
dirs = DirList("/home/work/my_project/");
//Loop through the directories
foreach dir in dirs
{
//Find only the solver files that exist under each directory
solver_files = FileList("/home/work/my_project/"+dir, "/*.nas");
//Loop through the solver files
foreach file in solver_files
{
Print(file);
}
}
}

4.4.12.3.10. Select files or directories through the file manager


BETA CAE Systems 176 META Automation User’s Guide
4. Scripting

Scripting language interacts directly with the File Manager through the commands SelectOpenDir,
SelectSaveDir, SelectOpenFile, SelectSaveFile, SelectOpenFileIn, SelectSaveFileIn. These
functions open the File Manager and allow the selection or creation of files and directories. This is
an elegant way to use file and directory paths in user scripts, since it enables the interactive
definition of script parameters. The functions that deal with files return a matrix containing strings
that represent the full path to the selected files, while those for directories return a string indicating
the full path to the folder.
def Selection()
{
Print("Select the file for reading");
read_file = SelectOpenFile(0, "csv files (*.csv)");
/*The matrix 'read_file' contains only one entry since the
the first argument of 'SelectOpenFile' was 0 */
Print("The file that was selected is: "+read_file[0]);
Print("Select the log file for writing the error messages");
save_file = SelectSaveFile();
Print("The file that was selected for writing errors is:
"+save_file);
Print("Select the directory where the META files are located");
dir = SelectOpenDir("");
Print("The selected directory is: "+dir);
}

If nothing is selected, it can be identified using the ! operator:


read_file = SelectOpenFile(0, "csv files (*.csv)");
if(!read_file)
{
Print("No file was selected");
}

or
dir = SelectOpenDir("");
if(!dir)
{
Print("No directory was selected");
}

4.4.12.4. Create, Edit, Delete and Handle Entities


4.4.12.4.1. Introduction

The entities Annotations, Cut planes, Groups, Isofunctions, Windows, Models, Pages, Plots,
Curves, Images and Videos can be created edited and deleted through script functions. The entities
nodes, elements, parts, materials and boundaries CANNOT be created, edited or deleted in META
in general, so this is also not possible through scripitng. Coordinate systems can be created but
cannot be deleted. Moreover, specific functions exist for other operations related to the entities, e.g.
to show, hide, get results from them, etc.

4.4.12.4.2. Create entities

For creating entities the respective functions are CreateXxx(), e.g. CreateEmptyAnnotation(),
BETA CAE Systems 177 META Automation User’s Guide
4. Scripting

CreatePlane(), CreateGroupFromElements(), etc..


The entities can also be created by applying the respective session commands (see also chapter
“META session commands for use in Scripting Language”). However, one advantage of creating
the entities through script functions is that the function returns the structs of the created entities. For
example, when creating a curve through scripting, the id of the curve is available.
#include "meta_structs"

def main()
{
annotation a;
window_name = "Window1";
text = "10th Annotation";
a = CreateEmptyAnnotation(window_name, text);
if(IsValidAnnotation(a)) {
Print(a.id);
}
}
4.4.12.4.3. Edit entities

There is a series of script functions for editing directly entities and their settings, for example
SetSettingsOfAllCurves(),SetSettingsOfAllAnnotations(), SetAnnotationPointerOnlement(),
ChangeOriginOfPlane(), AddPartsOnGroup(), RotateView(), etc. However, the full possibilities of
editing entities in META are covered through the META session commands and can be achieved
by using the MetaCommand syntax (see also chapter “META session commands for use in
Scripting Language”).
#include "meta_structs"

def main()
{
plane_name = "plane_axis0";
//Change origin through script function
xorig = 1.26;
yorig = 7.52;
zorig = 3.59;
ChangeOriginOfPlane(plane_name, xorig, yorig, zorig);
//Change section width through session command
MetaCommand(“plane options width 3.0 \””+plane_name+”\””);
}

4.4.12.4.4. Delete entities

For deleting entities the respective functions are DeleteXxx(), e.g. DeleteAnnotation(),
DeleteCurve(), DeleteModel(), etc.
The entities can also be deleted by applying the respective session commands.

4.4.12.4.5. Show / Hide entities

For showing / hiding entities the respective functions are ShowXxx() and HideXxx(), e.g.
ShowAnnotation(), HideCurve(), ShowModel(), etc.
When more than one 3d model entities or curves need to be shown / hidden, it is much faster to
use the functions ShowSomeXxx() and HideSomeXxx(), e.g. ShowSomeElements(),

BETA CAE Systems 178 META Automation User’s Guide


4. Scripting

HideSomeParts(), ShowSomeCurves(), etc. In this case the entities must be given as matrix.
The entities can also be shown / hidden by applying the respective session commands.

4.4.12.4.6. Identify entities

For identifying 3d model entities the respective functions are IdentifyXxx(), e.g. IdentifyNode(),
IdentifyElement(), IdentifyMaterial(), etc.
When more than one 3d model entities need to be identified, it is much faster to use the functions
IdentifySomeXxx(), e.g. IdentifySomeElements(), IdentifySomeParts(), etc. In this case the entities
must be given as matrix.
The entities can also be identified by applying the respective session commands.

4.4.12.4.7. Get /handle material properties

To get the properties of amaterial the script function PropertyOfMaterial() can be used. To set these
attributes the script function Set PropertyOfMaterial() can be used. If „all‟ is used as argument for
property type in PropertyOfMaterial(), then all material information lines, as in the input deck, will be
returned.
// BETA script
#include "meta_structs"

def main()
{
float property_value;
model_id = 0;
material_id = 1;
property_type = "all";
property_value = PropertyOfMaterial(model_id, material_id,
property_type);
Print(property_value);
}
4.4.12.4.8. Get results/attributes of entities

First of all, to get the states for which the resultsets are needed, the functions that can be used are
CurrentResultset(), ResultsetsXxx(), FilterResultsetsXxx(), GeneratedResultsetsXxx().
If more than one labels exist for the resultset, the functions DeformationLabelsOfResultsets(),
FunctionLabelsOfResultsets() can be used to get directly all the label results of the state.
Alternatively, the functions StringDeformationLabelsOfResultsets(),
StringFunctionLabelsOfResultsets() can be used to get the available labels and then the functions
GetResultsetFromDeformationLabel() and GetResultsetFromFunctionLabel() can be used to get
the specific label result of the state.
After the needed resultset is found, the functions to get the loaded results depend on the entity from
which the result which is needed. So, in the Nodes functions group there are functions to get results
on the nodes, in the Elements functions group there are functions to get results on elements, in the
Parts functions group functions to get all results from a part, in the Materials functions group
functions to get all results from a material, in the Groups functions group functions to get all results
from a group and in the Models functions group there are functions to get all results from a model.
Moreover, there is a different function for each specific result needed. For nodes, to get the
deformation results, there is the function DeformationOfNode(), to get the coordinates
CoordinatesOfNode(), to get scalar results NodalScalarOfNode() and to get vector results

BETA CAE Systems 179 META Automation User’s Guide


4. Scripting

NodalVectorOfNode().
Similarly for results on elements, there are functions DeformationsOfElement(),
MaxDeformationOfElement(), CentroidScalarOfElement(), CornerScalarOfElement(),
NodalScalarsOfElement() and more.
For parts / materials / models there are functions that return the results on all the nodes or
elements, e.g. CentroidVectorOfPart(), and functions that return directly the maximum and
minimum result, e.g. MinMaxNodalScalarOfModel().
For CELAS spring connection elements the functions StiffnessOfElasElement,
DampingOfDampElement and MassOfMassElement can be used to get information about the
stiffness, damping and mass respectively.
To get and set the number of steps of an axis the functions StepsOfPlotAxis() and
SetStepsOfPlotAxis() respectively can be used.
To get, calculate, and set the material tension, compression, shear, x_tension, y_tension,
x_compression, y_compression, shear and f12 limits of composites materials, the functions
MaterialLimitOfMaterial() and MaterialLimitOfPart() or AddMaterialLimitOfMaterial() and
AddMaterialLimitOfPart() can be used respectively.
Remarks
When the function returns only one entity (e.g. NodalScalarOfNode()), then it returns the
meta_struct of this entity, when it may return more than one entities
(e.g. DeformationsOfElement()), then it always returns a matrix with meta_structs (even when only
one entity is returned).
#include "meta_structs"
def main()
{
deformation deform;
resultset result;
model_id = 0;
result = CurrentResultset(model_id);
node_id = 7322;
deform = DeformationOfNode(result, node_id);
if(IsValidDeformation(deform)) {
Print(deform.x); // X deformation
Print(deform.y); // Y deformation
Print(deform.z); // Z deformation
Print(deform.total); // Total deformation
Print(deform.node_id); // Id of the node
}
}

#include "meta_structs"
def main()
{
nodal_vector min_nodal; nodal_vector max_nodal;
matrix nodal;
resultset result;
model_id = 0;
all_resultsets = Resultsets(model_id);
result = all_resultsets[1];
nodal = MinMaxNodalVectorOfModel(result);
if(MatLen(nodal)) {
min_nodal = nodal[0]; // Struct with the minimum nodal
vector value
Print(min_nodal.value); // Minimum nodal vector value
BETA CAE Systems 180 META Automation User’s Guide
4. Scripting

Print(min_nodal.x); Print(min_nodal.y); Print(min_nodal.z);


// Normalized coordinates (X, Y, Z) of the minimun nodal vector value
Print(min_nodal.node_id); // Id of the node with the minimum
nodal vector value
Print(min_nodal.part_id); // Id of the part or -1 if no part
exists

max_nodal = nodal[1]; // Struct with the maximum nodal


vector value
Print(max_nodal.value); // Maximum nodal vector value
Print(max_nodal.x); Print(max_nodal.y); Print(max_nodal.z);
// Normalized coordinates (X, Y, Z) of the maximum nodal vector value
Print(max_nodal.node_id); // Id of the node with the maximum
nodal vector value
Print(max_nodal.part_id); // Id of the part or -1 if no part
exists
}
}

BETA CAE Systems 181 META Automation User’s Guide


4. Scripting

4.4.12.4.9. Get measurements from entities

The functions to get measurements depend on the entity from which the measurement is needed.
So, in the Nodes functions group there are functions to get measurements from the nodes, in the
Elements functions group there are functions to get measurements from the elements, in the Parts
functions group functions to get measurements from a part and in the Groups functions group
functions to get measurements from a group.
Moreover, there is a different function for each specific measurement needed. To get the distance
between a node and another node there is the function DistanceNodeToNode(), to get the distance
between a node and a part the function is DistanceNodeToPart(), etc. To get the angle formed by
nodes the function is AngleOfNodes(). To get the distance between a part and a group the function
is DistancePartToGroup().
#include "meta_structs"
def main()
{
float dist_x; float dist_y; float dist_z; float dist_total;
matrix distance;
resultset part_result;
part_model = 0;
all_resultsets = Resultsets(part_model);
part_result = all_resultsets[1];
part_type = PSHELL;
part_id = 4;
resultset group_result;
group_model = 1;
all_resultsets = Resultsets(group_model);
group_result = all_resultsets[1];
group_name = "My_Group";

distance = DistancePartToGroup(part_model, part_result, part_type,


part_id, group_model, group_result, group_name);
if(MatLen(distance) != 0) {
dist_x = distance[0]; // Distance in direction X
dist_y = distance[1]; // Distance in direction Y
dist_z = distance[2]; // Distance in direction Z
dist_total = distance[3]; // Total distance
Print(dist_x); Print(dist_y); Print(dist_z);
Print(dist_total);
}
}

BETA CAE Systems 182 META Automation User’s Guide


4. Scripting

4.4.12.4.10. Get connected and neighbour elements/nodes

In cases that the connected elements or nodes are needed, the functions NeighbourElementsXxx(),
NodesOfElements() and ElementsOfNodes() should be used. In case of mesh independent
spotweld connections, where there is no node connectivity, the functions NeighbourElementsXxx()
can still be used as long as the connectivity is supported in META.
The above script functions should be preferred from the visibility session commands, e.g. “add
connected”, as the first are much faster.
#include "meta_structs"
def main()
{
elem e;
matrix neighbour_elements;
model_id = 0;
element_type = SHELL;
element_id = 1045789;
second_id = -1;
neighbour_type = SHELL;
neighbour_elements = NeighbourElementsByType(model_id,
element_type, element_id, second_id, neighbour_type);
foreach e in neighbour_elements {
Print(e.id);
}
}
In cases that the connected elements, nodes, parts etc to connections are needed, the functions
ConnectedXxxOfConnection() should be used.
#include "meta_structs"
def main()
{
elem e;
matrix connected_elements;
model_id = 0;
connection_id = 100238;
connected_elements = ConnectedElementsOfConnection(model_id,
connection_id);
foreach e in connected_elements {
Print(e.id); Print(e.second_id); Print(e.type);
Print(e.subtype); Print(e.part_id); Print(e.visible); Print(e.model_id);
}
}

BETA CAE Systems 183 META Automation User’s Guide


4. Scripting

4.4.12.4.11. Get spreadsheet entities/data

There are functions to get data stored in a spreadsheet. To get a cells data the function
SpreadsheetCellByRowColumn(sheet_name, row, col) can be used.
Also the entire row‟s or column‟s data can be stored in a matrix through the functions
SpreadsheetCellsByRow(sheet_name, row). and SpreadsheetCellsByColumn(sheet_name, col).
Returned matrix stops at the last non-empty cell. If all cells are empty, an empty matrix is returned)
To get cells data of an entire cells area the functions SpreadsheetCellsByArea(sheet_name,
top_row, left_col, bottom_row, right_col) and SpreadsheetCellsByLabel(sheet_name, cell_label)
can be used. Cells data are stored in a matrix of same size as the defined spreadsheet area.
Also in order to identify the spreadsheet cells area that involves data the function
SpreadsheetBoundingArea(sheet_name) can be used. A matrix that determines the bounding box
of non-empty cells (matrix[0][0]: top-row, matrix[0][1]: left-column, matrix[1][0]: bottom-row,
matrix[1][1]: right-column) will be returned.

4.4.12.4.12. Get attributes of user Toolbars

To get the attributes of specific entities of user Toolbars the functions CheckboxStateOfToolbar(),
SliderValueOfToolbar() and TextboxValueOfToolbar() are available.
#include "meta_structs"
def main()
{ int state;
toolbar_name = "Toolbar1";
checkbox_name = "Checkbox1";
state = CheckboxStateOfToolbar(toolbar_name, checkbox_name);
if(state == 1) {
Print("Checked");
}else if(state == 0) {
Print("Not checked");
}else if(state == -1) {
Print("Failure!");
}
}

BETA CAE Systems 184 META Automation User’s Guide


4. Scripting

4.4.12.5. Load Geometry and Solver Results, Create User-Defined Results


4.4.12.5.1. Load geometry and field / history results

For loading geometry the respective functions are LoadModel() for solver geometry data files and
LoadProjectModel() for geometries from META databases and META projects.
For loading field results the functions are LoadDeformations(), LoadModalDeformations(),
LoadScalar() and LoadVector() for solver results data files and LoadProjectDeformations(),
LoadProjectScalar() and LoadProjectVector() for results from META databases and META
projects.
The argument “data” which is needed for the functions is the same as the argument used in the
equivalent META session commands. The best way to retrieve the correct syntax is to load the
result manually from the META interface and view the session command passed to the current
META_post.ses file.
In order to append the loaded geometry/results the functions LoadAppendDeformations(),
LoadAppendProjectDeformations(), LoadAppendScalar(), LoadAppendScalarGetCoordSystems(),
LoadAppendProjectScalar(), LoadAppendVector(), LoadAppendVectorGetCoordSystems(),
LoadAppendProjectVector() are available.
For loading curves from history results files the respective functions are LoadCurvesXxx(), e.g.
LoadCurvesNastran(), LoadCurvesDyna().
The arguments which are needed for the functions, e.g. entities, variables, etc, are the same as the
arguments used in the META session commands. The best way to retrieve the correct syntax is to
load the result manually from the META interface and view the session command passed to the
current META_post.ses file. The only difference is that the results are passed as matrices to the
script functions. The string expressions can be easily changed to matrices and vice versa through
the functions RangeToMatrix() and MatrixToRange().
Especially for loading curves from RADIOSS history results files, the function LoadCurvesRadioss()
needs the time history id as argument. In case the time history id is not known, strings “*” or “all”
can be used referring to all available time history ids or the function GetRadiossTimeHistoryId() can
be used to find the time history id for a specific history result.
The entities can also be loaded by applying the respective session commands (see also chapter
“META session commands for use in Scripting Language”). However, one advantage of loading the
entities through script functions is that the function returns the structs of the created entities. For
example, when loading a model through the script function, the id of the model is available.

BETA CAE Systems 185 META Automation User’s Guide


4. Scripting

#include "meta_structs"
def main()
{
model r;
resultset res;
window_name = "MetaPost";
filename = "/home/demo/example.op2";
deck = "NASTRAN";
r = LoadModel(window_name, filename, deck);
if(IsValidModel(r)) {
model_id = r.id;
matrix new_resultsets;
states = "1-5,7,9-11";
data = "Displacements,Translational";
new_resultsets = LoadDeformations(model_id, filename, deck,
states, data);
data = "Stresses,VonMises,MaxofTopBottom";
new_resultsets = LoadScalar(model_id, filename, deck,
states, data);
foreach res in new_resultsets {
Print(res.name); Print(res.nodal_data_name);
Print(res.function_data_name);
Print(res.state);
}
}
}

#include "meta_structs"
def main()
{
curve c;
int th_id;
matrix new_curves;
window_name = "Window1";
plot_id = 0;
filename = "/home/demo/ExampleT01";
type = "shell";
entity_id = 3;
entity_type = "Accel";
variable = "";
time_history[0] = GetRadiossTimeHistoryId(filename, entity_id,
entity_type, variable);
//time_history[0] = "all";
matrix entities;
entities[0] = "22021";
entities[1] = "22025";
matrix variables;
variables[0] = "Membrane Strain E1 (e1)";
new_curves = LoadCurvesRadioss(window_name, plot_id, filename,
type, time_history, entities, variables);
foreach c in new_curves {
Print(c.id);
}
}
Remarks
The deck of the results is given as argument in the functions to load geometry and field results,
whereas different functions exist for each deck for loading history results.

BETA CAE Systems 186 META Automation User’s Guide


4. Scripting

4.4.12.5.2. Create user-defined field results

Apart from loading solver results, it is possible to create user defined field results using the results
from calculations realized inside the script.
First of all a new empty state for field results can be created with the function CreateResultSet().
To add a new label to the resultset and set the results to the nodes or the elements, the functions to
be used are AddDeformationOnAllNodes(), AddNodalScalarOnAllNodes() and
AddNodalVectorOnAllNodes().
For more complicated procedures:
To reset all the values of a resultset and add values to the nodes or the elements, the functions to
be used are StartAddingXxx() and EndAddingXxx(), e.g. StartAddingDeformations(),
EndAddindDeformations().
To change the values of a resultset the functions to be used are StartChangingXxx() and
EndAddingXxx(), e.g. StartChangingCentroidVector(), EndAddingCentroidVector().
To append a new label to a resultset and set values to the nodes or the elements for this label, the
functions to be used are StartAppendingXxx() and EndAddingXxx(), e.g.
StartAppendingCentroidScalar(), EndAddingCentroidScalar().
Between the StartXxx() and EndXxx() functions the values can be assigned to the nodes with the
functions AddCentroidScalarOnElement(), AddCentroidScalarOnSomeElements(),
AddCentroidVectorOnElement(), AddCentroidVectorOnSomeElements(),
AddCornerScalarOnElement(), AddCornerScalarOnSomeElements(), AddDeformationOnNode()
and AddDeformationOnSomeNodes(). When values are to be to more than one elements / nodes,
functions XxxOnSomeElements() and XxxOnSomeNodes() should be preferred, as they are much
faster.
Improtant Note: The EndAddingXxx() function must be called at the end, or else the values will not
be assigned to the resultset.

4.4.12.6. Useful notes about META script functions


4.4.12.6.1. Speed up the execution of scripts

When executing scripts in META some points should be taken into consideration in order to achieve
minimum execution times.
- When the script includes functions that change the display of the META windows, each redraw will
result to time consumption. To speed up the execution of the script, the redraws can be disabled,
and enabled only at the end of the script, in order to display directly the final state.
This can be achieved through the lines
MetaCommand(“options session controldraw disable”);
MetaCommand(“options session controldraw enable”);
- When a function needs to be applied on more than one entities, it is always faster to use the
function that applies directly on all the needed entities XxxOnSomeXxx, e.g. IdentifySomeNodes(),
AddElementScalarOnSomeElements(), etc, instead of applying the single function for each entitty.
- When all the results from entitiy are needed, it is faster to use the function that gets all the results
directly, e.g. DeformationsOfModel, CentroidScalarOfPart(), etc, instead of getting the result for
each element / node separately.
- In cases the connected elements or nodes are needed the functions NeighbourElementsXxx(),

BETA CAE Systems 187 META Automation User’s Guide


4. Scripting

NodesOfElements() and ElementsOfNodes() should be preferred from the visibility session


commands, e.g. “add connected”, as the first are much faster.

4.4.13. User defined buttons and custom GUI


4.4.13.1. General

META scripting language enables the creation of user defined buttons and fully customized
graphical interfaces. The buttons that can be created are similar to the buttons of the GUI and are
used to invoke user functions. For the management of specific tasks that must be controlled
through a number of definitions and actions, it is very useful to create a custom GUI. There are two
libraries of functions to create custom user interface. The first supports only the basic widgets that a
GUI can hold, like checkbuttons, radio buttons, menu buttons, lists, tables, while the second library,
BCGUI functions, is more extensive and except from the main widgets mentioned before it also
supports hundreds of more sophisticated tools. These tools allow the creation of any complex
interface that may also contain tab widgets, popup menus, spin boxes, group of buttons, tooltips
and so on. This chapter will focus on the syntax of the functions of the first library. The second
library is described in a separate chapter for both Python and BETA Scripting Lanuage.

4.4.13.2. Creation of custom graphical user interface (GUI)


4.4.13.2.1. Introduction

One of the most advanced capabilities of scripting language is the creation of user-defined
graphical user interfaces. A GUI is defined through a series of matrices. The format of each matrix
is specific and basically contains information regarding the attributes of controls (caption, position,
size), a reference name for handling the control and optionally the name of the function (Callback)
that will be called with the control activation. Each control is defined in a separate matrix while all
these matrices are parts of a total matrix. A typical syntax of a control matrix is the following:

id type x y w h caption reference Callback name


{100, "EDIT", 10, 10, 100, 100, "Text", "edittxt", "onEditChange"};
where 'x' and 'y' correspond to control position and 'w' and 'h' are the width and height respectively.

The available control types are:


1. EDIT → Creates edit fields
2. RADIO → Creates radio buttons
3. CHECK → Creates check buttons
4. BUTTON → Creates simple and menu buttons
5. LABEL → Creates labels
6. LIST_BOX → Creates lists
7. TABLE → Creates tables
8. LIST_VIEW → Creates list views
These matrices compose a total matrix that will be used as basis for the final window description.
controls = {
{ 10,"LABEL", 10, 10, 290, 21, "User defined buttons", "labeltop"},
{ 20,"BUTTON", 10, 40, 91, 41, "My Button 1", "button_LT", "LT_btn"},
{ 30,"BUTTON", 120, 40, 91, 41, "My Button 2", "button_RT", "RT_btn"},
{ 1,"BUTTON", 10, 100, 91, 21, "OK", "okbtn"},
{ 2,"BUTTON", 120, 100, 91, 21, "CANCEL", "cancelbtn"}
};

Finally, an additional matrix must be created for the overall window. Its definition is different from

BETA CAE Systems 188 META Automation User’s Guide


4. Scripting

the control matrix and is like the one below:

id x y w h length of total control total control Window name


dialog={100, 0, 0, 221, 130, MatLen(controls), controls,"Buttons Demo"};

Notice that 'x' and 'y' are set to zero. In this case the window will be placed in a default position.
Since all necessary matrices were created, the function CreateWindow must be called in order to
create the window. This function needs a reference name and the window matrix.

win = CreateWindow ("Win1", dialog);

Remarks
The CreateWindow function creates a window but it doesn't open it.

4.4.13.2.2. Setting Cancel and Ok buttons

Almost all types of user-defined windows need an OK and a CANCEL button. The functions
SetOkButton and SetCancelButton are used in order to give to these special buttons their known
characteristics. Their syntax needs the window reference name and the control reference name of
each button.
SetOkButton ("Win1", "okbtn");
SetCancelButton ("Win1", "cancelbtn");

4.4.13.2.3. Opening and destroying windows

After creating the window and setting the default values of the controls, the user interface is ready
to open. The OpenWindow function opens the window using its reference name:
res = OpenWindow ("Win1");
The output takes a value that corresponds to the pressed button, thus can be very helpful for any
actions that follow its activation. Every code that creates windows must end with the function
DestroyWindow. This function destroys a window that was created by a call to CreateWindow. It
is used to free the internal memory of the windowing system, when the window is no longer
needed.
DestroyWindow("Win1");

In the end the GUI should look like the image on the
left

4.4.13.2.4. Callback functions for custom GUI

BETA CAE Systems 189 META Automation User’s Guide


4. Scripting

A callback function is a separate routine that is called every time a control is activated. Its name is
defined in a control matrix. There are certain arguments required for its definition. In most cases
these are the window reference name, the control reference name and the control result.
controls = {
...
{ 20,"BUTTON", 40, 60, 120, 41,"My Button 1","button_LT","LT_btn"},
...
}

def LT_btn (string window_name, string control_name)


{
Print ("Button 1 was pressed");
}
In the above example the button's callback 'LT_ btn' doesn't have a third argument because a
BUTTON is a control whose result is taken through the OpenWindow function. Nevertheless, in
order to give extra information to the button's callback the SetButtonCallback must be used. It
accepts parameters that describe the window, the button and the function to call. The fourth
parameter can be anything and will be passed to the callback as a third parameter.
Callbacks that are carried from other controls must have 3 arguments.
controls = {
...
{101, "EDIT", 50, 45, 310, 20, "text", "edittxt","onEditChange"},
...
};

def onEditChange(string window_name, string edt_name, string txt)


{
Print("window:"+window_name +", edit_box:"+edt_name +", text:"+txt);
}

BETA CAE Systems 190 META Automation User’s Guide


4. Scripting

4.4.13.3. Callback functions


4.4.13.3.1. Introduction

The code between the CreateWindow and OpenWindow statements is used for an initial set up of
any type of control. Usually, the setting of a control needs additional definitions of matrices, like in
cases of menus and tables, but there are also cases where a simple call to a function is enough like
in edit fields and check buttons.

4.4.13.3.2. Setting edit fields and check buttons

An edit field can be set up using the functions StringSet, IntSet, FloatSet, which assign a string,
integer and float respectively. All of them take three input arguments, which are the window name,
the internal reference name of the control and the value:
controls = {
{1, "EDIT", 50, 45, 310, 20, "text", "ref_name"},
...
}
CreateWindow("Win2", dialog);
IntSet("Win1", "ref_name", 1);
// FloatSet("Win1", "ref_name", 1.34);
// StringSet("Win1", "ref_name", "none");
OpenWindow("Win1");

In case none of this function is called, the initial value will be the one defined in the control matrix
The function for setting the state of a check box is the SetCheckButton. The first two arguments
are the window name and the internal reference name of the control, while the third is an integer
that takes zero value for unchecked state and 1 for checked state.

4.4.13.3.3. Creating and setting up menus and radio buttons

Special attention must be given in the creation of menus and radio buttons since they require some
extra definitions. First, both controls are defined in the control matrix as described in section 4.2.
Their types are "RADIO" and "BUTTON" respectively. In this phase it is not allowed to set a
Callback function since this will be done later with functions SetRadioGroup and SetMenu.
controls = {
{10, "LABEL", 10, 10, 290, 21, "Select Deck", "labeltop"},
{20, "RADIO", 20, 50, 160, 30, "NASTRAN", "radio1"},
{30, "RADIO", 20, 90, 160, 30, "ABAQUS", "radio2"},
{40, "RADIO", 20, 130, 160, 30, "PAMCRASH", "radio3"},
{50, "LABEL", 20, 170, 160, 30, "Select Entities", "labelbottom"},
{60, "BUTTON", 20, 210, 160, 30, "btn", "btn_lower"},
{ 1, "BUTTON", 30, 340, 91, 41, "OK", "okbtn"},
{ 2, "BUTTON", 190, 340, 91, 41, "Cancel", "cancelbtn"}};
dialog = {100, 0, 0, 311, 404, MatLen ( controls ), controls, "Demo"};
win = CreateWindow ("Win4", dialog);
The above control matrix contains 2 labels, three radio buttons and a menu button. After the
creation of the window two group matrices must be defined for radio and menu control. These
matrices will contain the available options with the difference that in case of radio buttons the
internal reference names must be given while in menus the available options are given directly:

radio_group = {"radio1","radio2","radio3"};

BETA CAE Systems 191 META Automation User’s Guide


4. Scripting

menu_group = {"Elements","Nodes"};

In the final step these matrices will be passed to the respective setup functions:

SetRadioGroup ("Win4", radio_group, 0, "rgroup_1", "RadioCallback");


SetMenu ("Win4", "btn_lower", "MenuCallback", menu group, 0);

The SetRadioGroup requires the window name 'Win4', the group matrix 'radio_group', an integer,
indicating the active radio button, an internal reference name for the group 'rgroup_1' and the name
of callback function 'RadioCallback'.
The SetMenu requires similarly the window name 'Win4', the internal reference name as it is
defined in control matrix 'bnn_lower', the name of the callback function, the group matrix 'menu
group' and the active option. Keep in mind that the option number starts always from zero.
After setting up the radio buttons and the menu, the callback functions which will allow to recognize
any change of the controls must be created. These functions accept the typical three arguments
(see section 4.2.3) and in their simpler form can be like the following:
def MenuCallBack (string window_name, string btn_name, string option)
{
if(option=="Elements")
Print("Elements option was selected");
if(option=="Nodes")
Print("Nodes option was selected");
StringSet (window_name, btn_name, option);
}
In this case, the StringSet built in function will change the status of menu.
def RadioCallback (string window_name, string group, string option)
{
if(Atoi(option)==0)
Print("NASTRAN option was selected");
if(Atoi(option)==1)
Print("ABAQUS option was selected");
if(Atoi(option)==2)
Print("PAMCRASH option was selected");
}
After all settings the window must be destroyed.
def main()
{
controls = {
{10, "LABEL", 10, 10, 290, 21, "Select Deck", "labeltop"},
{20, "RADIO", 20, 50, 160, 30, "NASTRAN", "radio1"},
{30, "RADIO", 20, 90, 160, 30, "ABAQUS", "radio2"},
{40, "RADIO", 20, 130, 160, 30, "PAMCRASH", "radio3"},
{50, "LABEL", 20, 170, 160, 30, "Select Entities", "labelbotton"},
{60, "BUTTON", 20, 210, 201, 30, "btn", "btn_lower"},
{ 1, "BUTTON", 20, 250, 91, 41, "OK", "okbtn"},
{ 2, "BUTTON", 130, 250, 91, 41, "Cancel", "cancelbtn"}};
dialog = {100, 0, 0, 241, 281, MatLen ( controls ), controls, "Radio
Buttons Demo"};
win = CreateWindow ("Win4", dialog);
SetOkButton ("Win4", "okbtn");
SetCancelButton ("Win4", "cancelbtn");
radio_group = {"radio1","radio2","radio3"};
SetRadioGroup ("Win4", radio_group, 0, "rgroup_1", "RadioCallback");
menu_group = {"Elements", "Nodes"};

BETA CAE Systems 192 META Automation User’s Guide


4. Scripting

SetMenu ("Win4", "btn_lower", "MenuCallBack", menu_group , 0);


res = OpenWindow ("Win4");
DestroyWindow("Win4");
}
def MenuCallBack (string window_name, string btn_name, string option)
{
if(option=="Elements")
Print("Elements option was selected");
if(option=="Nodes")
Print("Nodes option was selected");
StringSet (window_name, btn_name, opt);
}
def RadioCallback (string window_name, string radio_group, string option)
{
if ( Atoi(option) == 0)
Print("NASTRAN option was selected");
if ( Atoi(option) == 1)
Print("ABAQUS option was selected");
if ( Atoi(option) == 2)
Print("PAMCRASH option was selected");
}

BETA CAE Systems 193 META Automation User’s Guide


4. Scripting

4.4.13.3.4. Creating and setting up List Boxes

A "List Box" is a type of window


where a list of items (entries) can be
displayed, selected or highlighted.
A very simple window is shown on
the left. The method for creating such
a window will be explained step by
step below:

Create the control matrix:


Like in all scripts related with GUI, the definition of the control matrix must be first done. The control
type that must be declared first is the LIST_BOX, while the others will be simple buttons.
controls = {
{100, "LIST_BOX",10,10,360,230, "", "list1"},
{102, "BUTTON",50,270,80,30, "Modify", "modify", "onModify"},
{ 1, "BUTTON",250,270,80,30, "Ok", "okbutton"}
};
dialog = {1000, 100,100, 380,320, MatLen(controls), controls, "Window2"};
window = CreateWindow("Window2", dialog);
SetOkButton("Window2", "okbutton");
Adding items to the list:
Items (entries) can be added in a LIST BOX with the AddListBoxItem function. It takes three
arguments, which are the window name, the reference name of the list box control 'list1' and a
string that will be
written in each line. The number of times that this function must be called is equal to the number of
lines that will be added in the box window. Keep in mind that all functions regarding the LIST BOX
accept always the aforementioned first two arguments and thus they are not going to be mentioned
again.
// add some items in the listbox
AddListBoxItem("Window2","list1","item1");
AddListBoxItem("Window2","list1","item2");
AddListBoxItem("Window2","list1","item3");
AddListBoxItem("Window2","list1","item4");
Multiselection of list entries:
By default, the above definition allows the user to select only one entry from the window. For
multiselection, the LBSetMultiSel function must be called. The third argument is an integer that its
values are zero (multi selection off) or one (multi selection on).
// set the listbox to multiselect mode
LBSetMultiSel("Window2","list1",1);
Creating the callbacks:
As it seems from the control matrix, no callback function was set for the LIST BOX control.
Callbacks for this type of control can be used in order to identify which items were selected or
highlighted in order to perform specific actions. The most important functions in this area are the
OnLBIHighlighted and onLBISelected. Except for the first two arguments the name of the
callback must be given:

BETA CAE Systems 194 META Automation User’s Guide


4. Scripting

// set the event callbacks


onLBIHighlighted("Window2","list1", "onHighlight");
onLBISelected("Window2","list1", "onSelect");

The onHighlight and onSelect have the form:


static def onHighlight(string window_name, string btn_name, string id)
{
Print("Highlight:"+id);
}
static def onSelect(string window_name, string btn_name, string id)
{
Print("Select:"+id);
}

The third argument is the unique id of the item that was selected/highlighted. Note that the counting
starts from zero.
For getting the text of the current item the LBCurText function must be used.
current_text = LBCurText("Window2","list1")
Print("current text:"+ current_text);

For multiselections the above function returns the string represented from the last selected item.
Special attention must be given to the callback onModify of the control matrix that will be used for
items modifications:
static def onModify(string window_name, string btn_name)
{
cur = LBCurrent(window_name, "list1");
res = UserInput("Please type some text", txt);
if (res)
{
if (cur >= 0)
{
SetLBItemText(window_name, "list1", cur, txt);
}
}
}

Before setting a new value to an item, it must be first recognized by its id. This is made with the
LBCurrent function, which returns the unique id of the item. Next, this output is given as third
argument in the SetLBItemText . The new text will be given in the forth argument.

Getting the selected text:


Finally, for getting all the item texts after a multi-selection action, the LBSelectedItems function
must be called. The selected items are returned in a matrix with their id representation.
Selected_items = LBSelectedItems("Window2","list1");

Making a loop in the Selected_items matrix, all item texts are taken with the LBItemText.
foreach sel_item_id in Selected_items
{
BETA CAE Systems 195 META Automation User’s Guide
4. Scripting

Lbitext = LBItemText("Window2", "list1", sel_item_id));


Print("selected item:"+ sel_item_id +", "+ Lbitext);
}

The final code is the following:


static def onHighlight(string window_name, string btn_name, string id)
{
Print("Highlight:"+id);
}

static def onSelect(string window_name, string btn_name, string id)


{
Print("Select:"+id);
}

static def onModify(string window_name, string btn_name)


{
cur = LBCurrent(window_name, "list1");
res = UserInput("Please type some text", txt);
if (res)
{
if (cur >= 0)
{
SetLBItemText(window_name, "list1", cur, txt);
}
}
}

def main()
{
controls = {
{100, "LIST_BOX", 10,10,360,230, "", "list1"},
{102, "BUTTON", 50,270,80,30, "Modify", "modify", "onModify"},
{ 1, "BUTTON", 250,270,80,30, "Ok", "okbutton"}
};
dialog = {1000, 100,100, 380,320, MatLen(controls), controls, "Window2"};
window = CreateWindow("Window2", dialog);
SetOkButton("Window2", "okbutton");

// add some items in the listbox


AddListBoxItem("Window2","list1", "item1");
AddListBoxItem("Window2","list1", "item2");
AddListBoxItem("Window2","list1", "item3");
AddListBoxItem("Window2","list1", "item4");

// set the listbox to multiselect mode


LBSetMultiSel("Window2","list1",1);

// set the event callbacks


onLBIHighlighted("Window2","list1", "onHighlight");
onLBISelected("Window2","list1", "onSelect");

res = OpenWindow("Window2");
if (res)
{
Print("current text:"+LBCurText("Window2","list1"));
Selected_items = LBSelectedItems("Window2","list1");
BETA CAE Systems 196 META Automation User’s Guide
4. Scripting

foreach sel_item_id in Selected_items


{
Lbitext = LBItemText("Window2", "list1",sel_item_id);
Print("selected item:"+sel_item_id+", "+ Lbitext);
}
}
DestroyWindow("Window2");
}

4.4.13.3.5. Hiding and showing controls

The visibility of all controls can be handled through the HideControl and ShowControl functions.
Their syntax is the same and needs the window name and the reference name of the control. In the
example that will follow, the visibility of all buttons is controlled through a callback, which hides or
shows the buttons according to the status of a check box.
static def onCheckChange(string window_name, string btn_name, string state)
{
if (state ==0)
{
ShowControl(window_name, "btn_1");
ShowControl(window_name, "btn_2");
}
else
{
HideControl(window_name, "btn_1");
HideControl(window_name, "btn_2");
}
}

def main()
{
controls = {
{102, "CHECK" , 50,30,250,20, "hide / show buttons", "check1",
"onCheckChange"},
{103, "BUTTON" , 50,75,150,20, "Option 1","btn_1"},
{104, "BUTTON" , 50,100,150,20, "Option 2","btn_2"},
{ 1, "BUTTON", 165,160,70,30, "Ok", "okbutton"}
};
dialog = {1000, 100,100, 400,210, MatLen(controls), controls,
"Hide/Show"};
window = CreateWindow("Hide/Show", dialog);
SetOkButton("Hide/Show", "okbutton");
res = OpenWindow("Hide/Show");
DestroyWindow("Hide/Show");
}

BETA CAE Systems 197 META Automation User’s Guide


4. Scripting

4.4.14. Exchanging data


4.4.14.1. General

META scripting language is capable of handling external ASCII, XML and BINARY files. The
treatment of such files includes operations like opening, reading, creating the file or browsing
through its contents. In this way it is possible to pass any information from a file that contains any
data (engineering data, connection information) to an META database and vice versa. Some basic
functions that can be used for these purposes are presented and explained in the following
paragraphs.

4.4.14.2. TEXT files


4.4.14.2.1. Introduction

The most important functions for handling text files are listed in the following table:

# Function Description
Fopen("/home/work/test.txt","w"); Opens a file for writing.
1. Fopen("/home/work/test.txt","r"); Opens a file for reading.
Fopen("/home/work/test.txt","a"); Opens a file for appending.
2. Fclose(f); Closes a file.
3. Read(f,line); Reads each line of a fille
4. Write(f,"text to write"); Writes into a file.
5. TokenizeString("1,2,5,20",",",0) Breaks a string into tokens
6. MatchString("10_PID:40",": "); Locates a substring

The last two functions are the most significant string functions. Their use is necessary during the
reading of an ASCII file.

4.4.14.2.2. Opening and closing files

In the most general case, when reading or appending to a file, the language checks if the user has
permissions on this file. If everything is ok, it returns an integer which is used later for any action
instead of the filename. The script functions that are used to open and a close a file are the Fopen
and Fclose.
def main()
{
f = Fopen("home/work/test.csv","r"); //Opens a file for reading
.....
Statements
.....
Fclose(f);//Closes the file
}
Remarks
Attempting to open a file for writing or appending to it while the file doesn't exist, it creates the file
automatically.

BETA CAE Systems 198 META Automation User’s Guide


4. Scripting

4.4.14.2.3. Reading files

The reading of an ASCII file is made line-by-line, making use of the output integer of the Fopen
function. The script function that is used is called Read and most of the times it is used together
with a while statement. This is made in order to assure that the file will be read from the beginning
to the end. Suppose that each line of the following text must be read and printed:

SUBSTRUCTURE = side
MODULE_ID = 100
TITLE = B-PILLAR
MODULE_ID = 1000
PID = 20
PIDNAME = MAT1_BP
THICKNESS = 0.8
MAT_NAME = Steel
X_AXIS = 1,0,0
Y_AXIS = 0,1,0
Z_AXIS = 0,0,1
ORIGIN = 0,0,0

def main(){
f = Fopen("/home/work/test.attr","r"); //Opens the file for reading
//Read each line of the file and store it under the variable s
while(Read(f,s))
{
Print(s);//Print each line
}
Fclose(f);//Closes the file
}

TokenizeString and MatchString are the most appropriate functions for handling strings. The
TokenizeString splits a string into tokens taking into account a delimiter. For example, a variable
called „line‟ that indicates a node id and its coordinates, in a comma-separated form, can be split
into four different strings. The new strings are stored in a matrix.
def main()
{
// NID, xcoord, ycoord, zcoord
line = "234,-42.505,-44.245,17.782";
tokens = TokenizeString(line, ",",0);
Print("The string line was separated in "+MatLen(tokens)+ "tokens");
}

After the execution of the script the function will return a matrix with the tokens. In the current
example the length of the matrix is 4 and each entry will have the following values:
tokens[0] = 234
tokens[1] = -42.505
tokens[2] = -44.245
tokens[3] = 17.782

BETA CAE Systems 199 META Automation User’s Guide


4. Scripting

It is recommended to convert each of the tokens to the appropriate form (float, integer etc.) before
any further use. The second argument can host any number of separators:
def main()
{
// NID, xcoord ycoord zcoord
line = "234,-42.505_-44.245:17.782";
tokens = TokenizeString(line, ",_:",0);
Print("The string line was separated in "+MatLen(tokens)+"tokens");
}
The result will be a matrix with the same entries as before.
Some types of separators need the backslash symbol \ for their definition.
For tab separator: TokenizeString(line,"\t",0);
For " separator : TokenizeString(line,"\"",0);
For \ separator : TokenizeString(line,"\\",0);
For a blank separator just leave a space: TokenizeString(line, " " ,0);
The last argument declares if a blank token will be saved in the output matrix (flag=1) or not
(flag=0):
def main()
{
line = 234,-42.505,,-44.245,17.782
tokens = TokenizeString(line,",",1);
Print("The string line was separated in "+MatLen(tokens)+" tokens");
}
In this case the number of entries in 'tokens' will be five, since the function has used 1 as last input
argument. The extra entry will be an empty string.
Optionally, a forth argument denotes if the delimeters will be consider as one word, e.g.:
def main()
{
m = TokenizeString("that is a string to break", "is", 0, 1);
//returns a matrix containing the strings "that " and " a string to
break"
}
The MatchString is used to identify a specific sub-string within a parent string. It returns an integer
indicating the position of the first occurrence of the sub-string. If nothing is found zero is returned.
First input argument is the parent string and second argument is the sub-string that must be
matched.
def main()
{
parent = "name_roof_pid_100";
pos = MatchString(parent, "pid");
}
th
The 'pos' variable will be 11 since the first occurrence of 'pid' is in the 11 position.

A very useful application is demonstrated in the following example were all PSHELLs with names
that contain the string “Default” are identified and deleted.

BETA CAE Systems 200 META Automation User’s Guide


4. Scripting

def SubStitute()
{
//Initialize
count = 0;
pshells = CollectEntities(NASTRAN,0,"PSHELL",0);
foreach pshell in pshells
{
GetEntityCardValues(NASTRAN,pshell,"Name",name);
pos = MatchString(name,"Default");
if(pos)
{
to_del[count++]= pshell;
}
}
DeleteEntity(to_del,1);
}

For more complicated cases, where the sub-string follows a pattern, the MatchRegex function can
be used instead. In the example that follows the function searches in insensitive mode, a material
name starting with the string 'Default' :
def main()
{
match_name = MatchRegex(material_name, "^Default\b", "case_sensitive",
"false");
if ( match_name )
{
Print("Default material: "+material_name);
}
}

4.4.14.2.4. Writing files

The function Write is used to write a file. The arguments that uses are the integer returned by the
Fopen function and the text to write. Every time the function is called a new line is written. Suppose
that the information like the pid, thickness and name of all PSHELL properties must be written in a
csv (comma separated) file. A simple code should be like the following:
def main()
{
part p;
matrix all_parts;
model_id=0;
f = Fopen("home/work/test.csv","w"); //Opens a file for writing
//Write the HEADER
Write(f,"PID,Name,Thickness");
all_parts = Parts(model_id); //Collect all parts of model 0.
//Loop through the Parts
foreach p in all_parts
{
Write(f,p.id+","+p.name+","+p.shell_thick);
}
Fclose(f);
}
For writing more than one lines after each call of Write, use the \n symbol enclosed in quotes.

BETA CAE Systems 201 META Automation User’s Guide


4. Scripting

4.4.14.3. XML files


4.4.14.3.1. Introduction

The most important functions for the handling of xml files are listed in the following table:

# Function Description
1. XmlOpenBase("/home/script.xml", "scripted"); Opens a XML data base
XmlGetNode(base, "VTAElements/"); Fetces a node
2.
XmlGetNode(base, root,"VTAElements/");
XmlGetSubNodes(base,node); Fetches the subnodes of a
3.
node
4. XmlNodeName(base, sub_param); Gets the name of a node
XmlGetStringValue(base,sub_param,"Name",""); Gets the string value of a
5.
node
6. XmlGetNodeData(base,node); Gets node's data
XmlNewNode(base,"Connection Elements",1); Creates new node
7.
XmlNewNode(base,node_connection,"Spotwelds",1);
8. XmlSetStringValue(base, sub_node, "val","str"); Set a string value to a node
9. XmlSetNodeData(base, sub_node, "some_data"); Sets node's data

For the clarification of the most important xml functions the following schema is going to be used for
reading and writing:
<Data>
<Connection_Elements>
<SpotweldPoints>
<Parameter Code = "Connection Name">Spot1</Parameter>
<Parameter Code = "xcoord">1.2</Parameter>
<Parameter Code = "ycoord">5.0</Parameter>
<Parameter Code = "zcoord">3.5</Parameter>
<Parameter Code = "comment">"Connect 2 flanges"</Parameter>
</SpotweldPoints>
<Parts>
<PartInfo Code = "Part Name 1">"upper"</PartInfo>
<PartInfo Code = "Part Name 2">"lower"</PartInfo>
<PartInfo Code = "Prop Id 1">10</PartInfo>
<PartInfo Code = "Prop Id 2">20</PartInfo>
</Parts>
</Connection_Elements>
</Data>

4.4.14.3.2. Opening XML files

For opening an xml file the XmlOpenBase function must be used.


def main()
{
base = XmlOpenBase("/home/work/connections.xml", "internal_name");
...
}
The key point in this function is the output value which is an element (pointer) and indicates the xml
database. Almost all the XML functions that are going to be used later will need this
element(pointer). The second argument is necessary only when writing XML files where it is used
BETA CAE Systems 202 META Automation User’s Guide
4. Scripting

as base node. In case of reading, it can take an arbitrary internal name that will not be used further.
When this function points to a nonexistent file then a file is automatically created.

4.4.14.3.3. Getting nodes and sub-nodes

For getting the element (pointer) of a node the XmlGetNode must be used. In the current example
nodes are considered the tags <Data>, <Connection_Elements>, <SpotweldPoints> and <Parts>.
The root node in this structure is considered the <Data> and this is the node that must be fetched
first. The syntax for getting it is:

data = XmlGetNode(base,"Data/"); //For getting the <Data>

Since "Data" is the root the second argument can be also blank:

data = XmlGetNode(base,""); //This will get the <Data>

The output data is a matrix that contains the element (pointer) of ,"Data"
The nodes that comes hierarchically just after the root, like the <Connection_Elements>, can be
taken as following:
//For getting the <Connection_Elements>
connection_elements = XmlGetNode (base,data[0],"Connection_Elements");
Alternatively, after getting a node it is easy to get its sub-nodes using the XmlGetSubNodes.
Attention must be given in the function's second argument since it must be taken from the output
matrix of the XmlGetNode that was called before. The node <Connection_Elements> is the
subnode of <Data>, while the nodes <SpotweldPoints> and <Parts> are the subnodes of
<Connection_Elements>. The code that must be used is:
data = XmlGetNode(base,"Data/");
//For getting the <Connection_Elements>
connection_elements = XmlGetNode (base,data[0],"Connection_Elements");
//For getting the <SpotweldPoints>, <Parts>
subnodes = XmlGetSubNodes(base, connection_elements[0]);
The output is always a matrix that contains the elements (pointers) of the sub-nodes.

4.4.14.3.4. Getting the name of the node

In an XML file each node holds a name, which describes most of the times an area of interest. The
name can be extracted using the XmlNodeName function. Its syntax needs the base and the node
element (pointer).
connection_elements = XmlGetNode (base,data[0],"Connection_Elements");
//For getting the <SpotweldPoints>, <Parts>
subnodes = XmlGetSubNodes(base, connection_elements[0]);
foreach subnode in subnodes
{
node_name = XmlNodeName(base,subnode);
Print(node_name);
}
In the above example the names 'SpotweldPoints' and 'Parts' are going to be displayed on the
screen.

BETA CAE Systems 203 META Automation User’s Guide


4. Scripting

4.4.14.3.5. Getting attributes and node data

Apart from its name, a node can have attributes and data that are also important for the process.
Consider the node <SpotweldPoints> that has the sub-nodes <Parameter> which in turn have the
attribute 'Code'. This attribute has five parameter names ('Connection Name', 'xcoord', 'ycoord',
'zcoord', 'comment'), while each node holds data that is associated with each of these parameters
('Spot1, 1.2, 5, 3.5, Connect 2 flanges'). To extract this information, the functions
XmlGetStringValue and XmlGetNodeData. Can be used as follows:
def main()
{
base = XmlOpenBase("/home/work/connections.xml", "internal_name");
data = XmlGetNode(base,"Data/");
connection_elements = XmlGetNode(base,data[0],"Connection_Elements");
sub_nodes = XmlGetSubNodes(base,connection_elements[0]);
foreach sub_node in sub_nodes
{
node_name = XmlNodeName(base,sub_node);
if(node_name=="SpotweldPoints")
{
subs_of_spots = XmlGetSubNodes(base,sub_node);
foreach sub_of_spots in subs_of_spots
{
param_name = XmlGetStringValue(base,sub_of_spots,"Code","");
if(param_name=="Connection Name")
connection_name = XmlGetNodeData(base,sub_of_spots);
if(param_name=="xcoord")
xcoord = XmlGetNodeData(base,sub_of_spots);
if(param_name=="ycoord")
ycoord = XmlGetNodeData(base,sub_of_spots);
if(param_name=="zcoord")
zcoord = XmlGetNodeData(base,sub_of_spots);
if(param_name=="comment")
comment = XmlGetNodeData(base,sub_of_spots);
}
Print("connection_name:"+connection_name);
Print("xcoord:"+xcoord);
Print("ycoord:"+ycoord);
Print("zcoord:"+zcoord);
Print("comment:"+comment);
}
}
}
Remarks:
- The name of an attribute is necessary for retrieving the attribute values.
- If the attribute hasn't got a value then a default can be assigned through the forth argument of
XmlGetStringValue.

4.4.14.3.6. Writing XML files and setting the base node

In order to create a new XML file, the function XmlOpenBase must be used. The second defines
the base node, which in this case is the <Data>.

base = XmlOpenBase("/home/tmp/test.xml","Data");

BETA CAE Systems 204 META Automation User’s Guide


4. Scripting

4.4.14.3.7. Creating nodes

A new node can be created with the function XmlNewNode. Its syntax accepts either 3 or 4
arguments. Depending on the syntax a node can be created just after the base node (3 arguments)
or in any other place (4 arguments). In the latter case an element (pointer) indicating the parent
node will be needed.
In the following example the node 'Connection Elements' will be placed after the node 'Data':

node_connection = XmlNewNode(base,"Connection Elements",1);

while writing:

node_spot = XmlNewNode(base,node_connection,"SpotweldPoints",1);

the node 'SpotweldPoints' will be created after the 'Connection Elements'. It is clear that in this case
the output of the previous call was used. Last argument indicates whether the node appears once
(1) or more (0). In the current example it is 1 since both nodes are written once. On the other hand
the node 'Parameter' which appears more than once, must be created using as 0 as last option.

node_param = XmlNewNode(base,node_spot,"Parameters",0);

4.4.14.3.8. Setting attributes and node data

Attribute names and parameters can be set using the XmlSetStringValue function:

XmlSetStringValue(base,node_param,"Code","Connection name");
or
XmlSetStringValue(base,node_param,"Code","xcoord");

In a similar way the function XmlSetNodeData sets data to a node.

XmlSetNodeData(base,node_param,"Spot1");
or
XmlSetNodeData(base,node_param,"1.2");

To sum-up the above, the final code for writing the whole xml file is the following:
def main()
{
base = XmlOpenBase("/home/tmp/test.xml","Data");
node_connection = XmlNewNode(base,"Connection Elements",1);
node_spot = XmlNewNode(base,node_connection,"SpotweldPoints",1);
parameter_names_spots = {"Connection
name","xcoord","ycoord","zcoord","comment"};
node_data_spots = {"Spot1","1.2","5.0","3.5","Connect 2 flanges"};
for(i=0;i<5;i++)
{
node_param = XmlNewNode(base,node_spot,"Parameters",0);
XmlSetStringValue(base,node_param,"Code",parameter_names_spots[i]);
XmlSetNodeData(base,node_param,node_data_spots[i]);
}
node_parts = XmlNewNode(base,node_connection,"Parts",1);
parameter_names_parts = {"Part Name 1","Part Name 2","Prop Id 1","Prop
Id 2"};
node_data_parts = {"upper","lower","10","20"};

BETA CAE Systems 205 META Automation User’s Guide


4. Scripting

for(i=0;i<4;i++)
{
node_param = XmlNewNode(base,node_parts,"Parameters",0);
XmlSetStringValue(base,node_param,"Code",parameter_names_parts[i]);
XmlSetNodeData(base,node_param,node_data_parts[i]);
}
XmlCloseBase(base,1);
}

4.4.14.4. Binary files


4.4.14.4.1. Introduction

The functions for handling binary files are listed in the following table:

# Function Description
1. ReadCharacter Reads a character from a binary file
2. ReadDouble Reads a double precision number from a binary file
3. ReadFloat Reads a single precision number from a binary file
4. ReadInt Reads an integer number from a binary file
5. ReadString Reads a character string from a binary file
6. WriteCharacter Writes a character in a binary file
7. WriteDouble Writes a double precision number in a binary file
8. WriteFloat Writes a single precision number in a binary file
9. WriteInt Writes an integer number in a binary file
10. WriteString Writes a character string in a binary file

4.4.14.4.2. Setting attributes and node data

A binary file can be opened for writing or reading with the Fopen function using either the wb or rb
mode.

Fopen("/home/user/file.dat","wb"); //Opens a binary file for writing


Fopen("/home/user/file.dat","rb"); //Opens a binary file for reading

BETA CAE Systems 206 META Automation User’s Guide


4. Scripting

4.4.14.4.3. Reading and Writing binary files

The way of reading and writing binary files is the same with the one used for ASCII files. The only
exception is that each type of variable must be handled with different function. For example the
WriteFloat and ReadFloat are used for floats, the WriteInt and ReadInt are used for integers etc.
All functions used for writing accept 2 arguments which are the file identifier and the value to write.
Only for string types a third argument, which is the number of bytes to write, is used.
Fopen("/home/user/file.dat","wb"); //Opens a binary file for writing
WriteInt(fw,10);
WriteFloat(fw,1.3);
WriteString(fw,"The value is:"+12,11);
Fclose(fw);

The functions used for reading accept 2 arguments which are the file identifier and the variable
where the value will be stored. Again, only for string types, a third argument is needed for declaring
the number of bytes to read.
fr = Fopen("/home/user/file.dat","rb"); //Opens a binary file for reading
ReadInt(fr,int_val);
ReadFloat(fr,float_val);
ReadString(fr, str_val,11);
Fclose(fw);

Remarks
- A binary file is written and read sequentially.

BETA CAE Systems 207 META Automation User’s Guide


4. Scripting

4.5. BCGUI Functions

4.5.1. What is the BCGUI


BCGUI (BETA C interface Graphical User Interface) is a powerful and versatile library of GUI
functions. It is meant to help script users build easily windows that consist of any type of graphical
interface, like lineEdits, comboBoxes, checkBoxes, Lists etc. in order to interact faster and easier
with META entities.

4.5.2. BCGUI structure and philosophy


4.5.2.1. Classes of BCGUI entities

BCGUI entities are divided in 3 categories of classes:


1. Widget classes or widgets
2. Layout classes or layouts
3. Items

4.5.2.2. Widget classes or widgets

This category includes the important GUI entities that are visible and manageable by the user, like
windows, buttons, combo boxes etc.
BCWindow
Provides a window that may hold any other widget, layout or item. It is the highest-level widget that
can be created by the BCGUI library. A vertical layout is provided by default.
BCPushButton
It is a button that can perform an action on click or on toggle.
BCLineEdit
Provides a one-line text editor.
BCCheckBox
Provides an option box with a text label on the right.
BCPopupMenu
Provides a pull down menu of choices.
BCComboBox
It is a combination of a 'BCPushButton', a 'BCLineEdit' and a 'BCPopupMenu'.

A simple 'BCWindow' with a


'BCLineEdit', a 'BCCheckBox', a
'BCComboBox' and 'BCPushButton'
are shown on the left.

BETA CAE Systems 208 META Automation User’s Guide


4. Scripting

BCFrame
The 'BCFrame' class provides a flexible visual box which can obtain several shadow styles and
accommodate other widgets. A layout must be set in a 'BCFrame' since they do not have one by
default. For placing widgets inside, vertically or horizontally, use functions BCVBoxCreate or
BCHBoxCreate respectively.
BCLabel
Provides text or image display.
BCLabelTicker
Provides an auto-scrolling label
BCSpinBox
Provides a widget that allows the user to choose a value either by clicking the up/down buttons to
increase/decrease the value currently displayed or by typing the value directly into it.
BCSeparator
Creates a thin line to separate widgets.
BCSlider
Provides a vertical or horizontal widget for controlling a bounded value. It lets the user move a
slider along a horizontal or vertical groove and translates the slider's position into an integer value
within the legal range.
BCStatusBar
Provides a horizontal bar suitable for presenting status information.
BCToolBox
Provides a column of tabbed widget items. It displays a column of tabs one above the other, with
the current item displayed below the current tab. Every tab has an index position within the column
of tabs. A tab's item is a widget (e.g. a 'BCFrame').
BCDrawerGrid
It is a widget that can accommodate other widgets and manage their visibility.
BCButtonGroup
Provides a box frame with a title at the top.
'BCPushButtons', 'BCToolButtons', 'BCRadioButtons' and 'BCCheckBoxes' can be inserted. These
widgets can be arranged vertically or horizontally.
BCRadioButton
Provides a two-state button with a text label, that can be switched on (checked) or off (unchecked).
Radio buttons when grouped, provide a "one of many" choice.
BCDialogButtonBox
It is a widget that automatically adds to itself an 'Ok' and a 'Cancel' 'BCPushButton' when it is
created. This is the recommended way to create the 'Ok' and 'Cancel' buttons since they are
automatically connected to the accept and reject functions of the 'BCWindow'.
BCToolButton
Performs an action on press, on click or on toggle. Unlike 'BCPushButtons', they tend to occupy all
available space and they have a different look and feel. They are also ideal to be used with other
widgets, like 'BCButtonLineEdits', 'BCButtonComboBoxes', 'BCListViews' etc.

BETA CAE Systems 209 META Automation User’s Guide


4. Scripting

BCButtonLineEdit
Provides a one-line text editor that can hold buttons to its left or to its right.
BCCalculator
This class consists of a function set that create and manage a calculator window. It can be easily
combined with a 'BCButtonLineEdit' by inserting a 'toolButton' which provides a calculator when
pressed. The calculator's output can be sent back to the 'BCButtonLineEdit' by pressing the '->'
calculator's button (See the images below).
BCButtonComboBox
The 'BCButtonComboBox' can be seen as a combination of a 'BCComboBox' and a
'BCButtonLineEdit'. It has the advantage that one or many buttons can be displayeComboVal_d left
or right of its 'lineEdit'.
In the following picture a 'BCWindow' containing a 'BCLabel', a 'BCButtonLineEdit' are shown. The
'BCPushButton' inside the 'BCButtonLineEdit', when pressed pops up a calculator. The upper
lineEdit displays user's input and the lower the calculation's output. By pressing the '->' button the
calculator's output, shown in the second lineEdit is inserted into the 'BCButtonLineEdit' from which
the calculator was called.

BCPushButtonit

BCButtonLineEdit
BCLabel

BCWidgetStack
Provides a stack of widgets of which only one (the top most) is visible at any time.
BCSplitter
Provides a splitter widget that lets the user control the size of child widgets by dragging the
boundary between the children.
In the following image a 'BCSplitter' separates a 'BCListView' from a 'BCWidgetStack'. The
selection of a 'BCListViewItem' from the 'BCListView' raises a different 'BCFrame' (i.e. widget) on
the widget area.

BETA CAE Systems 210 META Automation User’s Guide


4. Scripting

BCTabWidget
Provides a 'tabBar' of tabs and a 'page area' below the tabs. Each tab is associated with a different
page. Only the current tab's page is shown in the page area; all the other tabs' pages are hidden.
BCTextEdit
Provides a powerful single-page rich text editor. 'BCTextEdit' by default allows undo/redo history to
be kept while some other word processing attributes (for example <Ctrl+C> for copy, <Ctrl+V> for
paste). It works on paragraphs and characters. A paragraph is a formatted string which is word-
wrapped to fit into the width of the widget. By default when reading plain text, one newline signify a
paragraph. A document consists of zero or more paragraphs, indexed from 0. Characters are
indexed on a per-paragraph basis, also indexed from 0.
BCTextBrowser
Provides a BCTextEdit with hypertext navigation.
BCTable
The BCTable class provides a flexible editable (spreadsheet-like) table widget. In 'BCTable's' other
widgets can be inserted as well.
A 'BCTable' has a vertical and a horizontal header. Rows and columns can be selected through the
headers.
BCListView
It implements a list/tree view. It can display and control a hierarchy of multi-column items, and
provides the ability to add new items at any time.
BCListViewInfoBox
It is a 'BCFrame' placed at the bottom of a 'BCListView' providing information about the total and
the selected items of a 'BCListView', as well as custom texts.
BCWidgetExpand
It is a widget used to save space in forms. Use this class to provide expansion functionality to the
widgets without having to resize the parent window. The class is simple to use and really useful in
widgets applying a scroll bar (such as 'BCListViews' or 'BCTextEdits'). Drag the mouse towards the
direction where the widget must be expanded, while holding 'Shift' and middle mouse button. The
widget remains expanded while the mouse cursor is inside it.

BETA CAE Systems 211 META Automation User’s Guide


4. Scripting

BCLineEditPath
It is a 'BCFrame' containing a 'BCComboBox' with the more recent paths used, a 'BCToolButton' for
browsing files and another 'BCToolButton' for clearing the history. These paths will be available any
time META is used.

The history-box frame can be a 'files', 'folders' or


'everything' type and it can be used with 'open' or 'save
as' mode.

BCTimer
The 'BCTimer' provides timer signals and single-shot timers.
BCProgressBar
It is used to give the user an indication of the progress of an operation and to reassure them that
the application is still running.

4.5.2.3. Layout classes or layouts

These are the invisible entities that manage the layout of widgets.
BCBoxLayout
The 'BCBoxLayout' is one of the most useful tools for managing geometry. It consists of a
rectangular box having transparent outside border which can obtain horizontal or vertical orientation
for its children (either widgets or other layouts). It is usually used as a parent in widgets creation.
BCGridLayout
The 'BCGridLayout' class lays out widgets in a grid. It takes the space made available to it (by its
parent layout or widget), divides it up into rows and columns, and puts each widget it manages into
the correct cell.
Layouts are used to define the widgets' placement inside a 'BCWindow'. A 'BCWindow' has by
default a 'BCBoxLayout' with a vertical orientation (red lines). This means that all children of the
'BCWindow' or its 'BCBoxLayout' will be placed one below the other, according to the order they
have been created.

BETA CAE Systems 212 META Automation User’s Guide


4. Scripting

In the example on the left,


children can be either widgets
(the 'Ok' and 'Cancel'
BCPushButtons) or other
layouts (the horizontal
'BCBoxLayout' and the
'BCGridLayout').

4.5.2.4. Items

BCSpacer
Provides a blank space in a layout. It can be
extended to all directions, according to the
default parameters.

BCListViewItem and BCCheckListItem


These consist the content of a 'BCListView'. They may belong to the 'BCListView' directly (top-level
items) or to other items, if hierarchy is allowed. Controllable widgets can be added to them, like
'checkBoxes', 'comboBoxes' and 'buttons'.

BETA CAE Systems 213 META Automation User’s Guide


4. Scripting

4.5.2.5. General Remarks

The creation of graphical interface with BCGUI may include any of the above widgets, layouts or
items following the parent-child logic. This means that a BCGUI entity is constructed as a child of
another one. In this way the relationship, i.e. the placement and the dependencies of each entity,
can be easily defined. Actions like showing, hiding or destroying a parent widget, automatically are
applied recursively to all its children.
The 'BCWindow' is the highest level widget a user can create in script and META's Main Window is
set automatically as parent:
Pseudocode for a simple BCWindow

w = guitk.BCWindowCreate()
le = guitk.BCLineEditCreate(w) #le has parent w
f = guitk.BCFrameCreate(w) #f has parent w and placed below le
l = guitk.BCBoxLayoutCreate(f) #l has parent f
b1 = guitk.BCPushButtonCreate(l) #b1 has parent l
b2 = guitk.BCPushButtonCreate(l) #b2 has parent l and will be placed next
#to or below b1, according l's orientation.
A pseudocode example for the layouts follows:
Pseudocode for layouts example

w = guitk.BCWindowCreate()
horizontal = guitk.BCBoxLayoutCreate(w) #horizontal layout is the 1st child
guitk.BCLabelCreate(horizontal) #label belongs to horizontal
guitk.BCLineEdit(horizontal) #lineEdit is horizontal's 2nd child
grid = guitk.BCGridLayout(w) #grid layout is placed below horizontal
for row in range(3):
for col in range(3):
but = guitkBCPushButtonCreate(grid) #Create button at (row, col)

ok = guitk.BCPushButtonCreate(w) #'ok' button is BCWindow's 3rd child


cancel = guitk.BCPushButtonCreate(w) #'cancel' button is BCWindow's 4th child
BCGUI functions were built in a way to be immediately comprehensible, even by beginner users.
Help for all BCGUI functions (prototype, arguments, operation etc.) can be found in script editor's
help.
The name of a BCGUI function consists of the class it belongs to (e.g. BCLineEdit) plus the action
performed on an object of this class (e.g. SetText). Thus, the function name is
BCLineEditSetText.
If a function does not begin with a class name, it means that it is a general function, applicable to all
widgets and layouts (not items). For example BCName function returns the name that may have
been set to a widget or layout by the BCSetName.
Also in case of 'BCPushButtons' and 'BCToolButtons' there are many BCButton... functions,
applicable to both classes of buttons.
BETA CAE Systems 214 META Automation User’s Guide
4. Scripting

From the example above it is concluded that:


- All BCGUI functions start with BC.
- Each different word starts with a capital letter.
Generally, the first argument of functions is the widget, layout on which an action will be performed,
or its parent in case of BC...Create functions.

4.5.3. How to (BCGUI)


4.5.3.1. Create a simple BCWindow

The first example is the code implementation of the


pseudocode as presented in the previous section.

def main():
w = guitk.BCWindowCreate('Simple BCWindow',
guitk.constants.BCOnExitDestroy)
le = guitk.BCLineEditCreate(w, 'This is a lineEdit')
f = guitk.BCFrameCreate(w)
l = guitk.BCBoxLayoutCreate(f, guitk.constants.BCHorizontal)
b1 = guitk.BCPushButtonCreate(l, "Button 1", None, 0)
b2 = guitk.BCPushButtonCreate(l, "Button 2", None, 0)
guitk.BCShow(w)
In order for a widget to be displayed, BCShow must be called for it. This will trigger a recursive call
for the widget's children as well. In the example above, only one BCShow call for 'BCWindow' 'w' is
enough to show everything that it contains. The 'BCOnExitDestroy' option used in
'BCWindowCreate' means that when the window closes (by pressing escape <esc>, return or the[x]
button) it will be destroyed. The other available option is the 'BCOnExitHide' but it is strongly
recommended to avoid using it, since a wrong usage may lead to memory leaks.
Note that a 'BCWindow' is good to have a unique name. Any information about the window (e.g
size, position, values of its widgets etc) will be stored in META_post.xml under this name. However,
it must not be confused with the name of the title bar that can be always changed by using the
BCSetCaption.

4.5.3.2. Creating and using callback functions

In the previous example a 'BCWindow' with 2 “dummy” buttons was created, i.e. on button click no
operation has been defined. This is where the user needs to define callback functions, i.e. functions
that will be called when a user interacts with widgets or items.
Callback functions are defined as normal script functions and their name is passed as a string
argument to the appropriate BCGUI functions, followed by a user argument of any data type (float,
string, integer, matrix etc).
Help about BCGUI callback functions (prototype, arguments etc.) can be found at the end of the
description section of each BCGUI function that uses a callback as an argument.

BETA CAE Systems 215 META Automation User’s Guide


4. Scripting

In the following example, a 'BCWindow' is created with 2


'BCLineEdits' and a 'BCPushButton'.
The upper 'BCLineEdit' accepts doubles as input and when
<Enter> is pressed the square root calculation of the current
value is triggered while the calculated value is set to the
lower (output) 'BCLineEdit'. When the 'BCPushButton' is
pressed, the calculated value is printed in the Output
window. In both callback functions the output 'BCLineEdit' is
passed as data.

def calculateFun(le, data):


#le is the input; data is the output
newVal = math.sqrt(guitk.BCLineEditGetDouble(le))#Calculation of
the square root
guitk.BCLineEditSetDouble(data, newVal)#Set calculated value to
the output lineEdit
return 1 # Returns 1 so that the window will
remain open.

def printFun(button, data): #button is butPrint; data is the output


textToPrint = +The calculated value is ' +
str(guitk.BCLineEditGetDouble(data))
print(textToPrint) #Just print the value shown in output lineEdit

def main():
w = guitk.BCWindowCreate('Sqrt calculation',
guitk.constants.BCOnExitDestroy)
grid = guitk.BCGridLayoutCreate(w, 2, 2)
input = guitk.BCLineEditCreateDouble(grid, 0)
guitk.BCGridLayoutAddWidget(grid, input, 0, 0,
guitk.constants.BCAlignLeft+guitk.constants.BCAlignVCenter)
output = guitk.BCLineEditCreateDouble(grid, 0)
guitk.BCGridLayoutAddWidget(grid, output, 1, 0,
guitk.constants.BCAlignLeft+guitk.constants.BCAlignVCenter)
#Alignment enumerators OR'ed together
guitk.BCLineEditSetReadOnly(output, 1);
guitk.BCLineEditSetEnterPressedFunction(input, calculateFun,
output)
butPrint = guitk.BCPushButtonCreate(grid, None, printFun, output)
guitk.BCButtonSetPixmapFile(butPrint, "print_16.png")
guitk.BCGridLayoutAddWidget(grid, butPrint, 1, 1,
guitk.constants.BCAlignCenter)

guitk.BCGridLayoutSetColStretch(grid, 0, 1) #The 1st column


should take all
guitk.BCGridLayoutSetColStretch(grid, 1, 0) #the expansion.
guitk.BCDialogButtonBoxCreate(w)
guitk.BCShow(w)
Keep in mind that it is not allowed to pass directly a matrix with its contents to a callback,
e.g.:
guitk.BCLineEditSetEnterPressedFunction(input, calculateFun, [output,1])

Important Note: Any changes of the user argument of callbacks can be known to the 'main'
function if the datatype of the argument is defined with the 'byref' statement.

BETA CAE Systems 216 META Automation User’s Guide


4. Scripting

4.5.3.3. Moving more data around Creating and using callback functions

An alternative way to pass more data to callbacks is to use the BCSetUserDataKey and
BCGetUserDataKey functions. The first one associates key- data pairs (of types string-element)
to a widget or layout and the second one retrieves the data using the corresponding string keys.

def calculateEquation(data):
#Retrieving widgets from BCWindow w (==data)
input = guitk.BCGetUserDataKey(data, "input")
sp1 = guitk.BCGetUserDataKey(data, "sp1")
sp2 = guitk.BCGetUserDataKey(data, "sp2")
lab = guitk.BCGetUserDataKey(data, "lab")
output = guitk.BCGetUserDataKey(data, "output")

#Calculation
d = guitk.BCLineEditGetDouble(input);
if d == 0: return
i_1 = guitk.BCSpinBoxGetInt(sp1)
i_2 = guitk.BCSpinBoxGetInt(sp2)
result = math.power(d, i_1) * math.exp(i_2) / math.log(d)

#Show result
guitk.BCLabelSetText(lab, d)
guitk.BCLineEditSetDouble(output, result)

def lineEditChangedFun(le, text, data):


#le here is the input lineEdit; data is the w BCWindow
calculateEquation(data)
return 0

def spinBoxChangedFun(sp, val, data):


#sp here could be sp1 or sp2 BCSpinBoxes; data is the w BCWindow
calculateEquation(data)
return 0

def printFun(button, data):


#button here is butPrint; data is the w BCWindow
#Just print the value shown in output lineEdit
output = guitk.BCGetUserDataKey(data, "output")

BETA CAE Systems 217 META Automation User’s Guide


4. Scripting

textToPrint = "The calculated value is " +


guitk.BCLineEditGetDouble(output)
print(textToPrint)

def main():
w = guitk.BCWindowCreate("Equation calculation",
guitk.constants.BCOnExitDestroy)
l1 = guitk.BCBoxLayoutCreate(w, guitk.constants.BCHorizontal)
input = guitk.constants.BCLineEditCreateDouble(l1, 0)
guitk.BCLineEditSetDouble(input, 1)
guitk.BCLabelCreate(l1, " ^ ")
sp1 = guitk.BCSpinBoxCreate(l1)
guitk.BCSpinBoxSetMinValue(sp1, 2)
guitk.BCSpinBoxSetMaxValue(sp1, 15)
guitk.BCLabelCreate(l1, " * e ^ ")
sp2 = guitk.BCSpinBoxCreate(l1)
guitk.BCSpinBoxSetMinValue(sp2, 1)
guitk.BCSpinBoxSetMaxValue(sp2, 10)
guitk.BCLabelCreate(l1, " / log(")
lab = guitk.BCLabelCreate(l1,
guitk.BCLineEditGetText(input))
guitk.BCLabelCreate(l1, ")")
guitk.BCSpacerCreate(w)
l2 = guitk.BCBoxLayoutCreate(w, BCHorizontal)
output = guitk.BCLineEditCreateDouble(l2, 0)
guitk.BCLineEditSetReadOnly(output, 1)
butPrint = guitk.BCPushButtonCreate(l2, None, printFun, w)
#You can #also set the widget before the
data assignment
guitk.BCButtonSetPixmapFile(butPrint, "print_16.png")
guitk.BCSpacerCreate(l2) #Horizontal spacer. Keeps output and
butPrint to the left

guitk.BCSetUserDataKey(w, "input", input)


guitk.BCSetUserDataKey(w, "sp1", sp1)
guitk.BCSetUserDataKey(w, "sp2", sp2)
guitk.BCSetUserDataKey(w, "lab", lab) #We hold the lab in order to
change its text.
guitk.BCSetUserDataKey(w, "output", output)

guitk.BCSpinBoxSetValueChangedFunction(sp1, spinBoxChangedFun, w)
guitk.BCSpinBoxSetValueChangedFunction(sp2, spinBoxChangedFun, w)
guitk.BCLineEditSetTextChangeFunction(input,lineEditChangedFun, w)

guitk.BCDialogButtonBoxCreate(w)
guitk.BCShow(w)

BETA CAE Systems 218 META Automation User’s Guide


4. Scripting

4.5.3.4. Advanced BCGUI functionality

This example demonstrates how widgets can be placed inside container widgets, such as
'BCDrawerGrids', 'BCToolBoxes' and 'BCTabWidgets'. It also demonstrates how the widgets' state
can be saved in the current xml file (apart from the 'BCWindow's' position and size, which is done
automatically) and retrieve it on demand. Finally, some interesting ways of controlling and
displaying data are shown.

For simplicity reasons most callback functions have been omitted.


A 'BCWindow' is created under the name 'AutoSavingSettings'. It contains a 'BCTabWidget' with 2
tabs.
The first contains a 'BCToolBox' and the other a 'BCButtonLineEdit' with a calculator button, a
'BCGridLayout' with 9 'BCPushButtons', a 'BCTextEdit' and 'BCLabelTicker' (i.e. a 'BCLabel' whose
text can scroll when mouse pointer is over it and can be dragged to the left or to the right).
Only the first tab's widgets' state can be saved to and read from xml, that's why the 2 extra buttons
in 'BCDialogButtonBox' are enabled only when this tab is current.

BETA CAE Systems 219 META Automation User’s Guide


4. Scripting

The 'BCWindow' flashes when 'Enter' is pressed with an invalid 'BCSpinBox' value.
When the current tab changes, the 'BCCaption' of 'BCWindow' (the title) changes as well to the
tab's label. Nevertheless, its 'BCName' ('AutoSavingSettings') must never change and it must be
unique, i.e. no other window with the same 'BCName' should exist in META. The reason for this is
that all settings are saved to xml under this name.
A control has been set for closing 'BCWindow's' when pressing 'Enter'. Normally, a window closes
on 'Enter' unless a BCWindowSetCheckFunction or a BCWindowSetAcceptFunction are set. In
this case the first one must be used, and the 'BCWindow's' exit is controlled by the current value of
the 'BCSpinBox' found in the “Red frame”. If it is higher than 6, a warning appears in META Info ,
the 'BCWindow' flashes and stays open.
Initially, the 'BCComboBox' in the “Green frame” has 3 options: 'All', 'None' and 'Write Protected'.
The first 2 operate as normal 'comboBox' options. If the last is selected a 'BCPopupMenu' appears
containing a hierarchical 'BCListView' and a 'BCPushButton' at the bottom. In this way any options
offered by a 'BCComboBox' can be refined to the finest detail.

#Creation of the BCPopupMenu


def fillList(lview):
num = 8;
rename = (0,)
iName = ("tmpItem",)

for i in range(num):
lvitem = guitk.BCListViewAddItem(lview, 1, iName, rename)
guitk.BCListViewItemAddItem(lvitem, 1, iName, rename)

def comboActFun(combo, index, data):


title = ("",)
if index == 0: #Write Protected
popup = guitk.BCPopupMenuCreate(combo)
frame = guitk.BCFrameCreate(popup)
vbox = guitk.BCBoxLayoutCreate(frame,
guitk.constants.BCVertical)
guitk.BCBoxLayoutSetMargin(vbox, 0)
guitk.BCBoxLayoutSetSpacing(vbox, 0)
lview = guitk.BCListViewCreate(vbox, 1, title, 1)
guitk.BCListViewSetResizeMode(lview,
guitk.constants.BCLastColumn)
guitk.BCListViewHeaderHide(lview)
guitk.BCListViewSetIsRootDecorated(lview, 1)
guitk.BCListViewSetSelectionMode(lview,
guitk.constants.BCMulti)
guitk.BCListViewSetSortingColumn(lview, 0, 1)
ok_but = BCPushButtonCreate(vbox, "OK", "", 0)
fillList(lview)
guitk.BCPopupMenuInsertWidget(popup, frame)
guitk.BCPopupMenuPopupToParentWidget(popup)

def radioButtonGroupPressed(bgroup, index, data):


i = index + 1
print("radioButtonGroupPressed " + i)

def toolboxCreation(window, element vb):


numButtons = 4
wp = "Write Protected"
a = "All"
BETA CAE Systems 220 META Automation User’s Guide
4. Scripting

none = "None";
comboVals = (wp, a, none)

guitk.BCLabelCreate(vb, "Default Widgets")


#Create the whole toolBox
toolBox = guitk.BCToolBoxCreate(vb)
blueFrame = guitk.BCFrameCreate(vb)
guitk.BCBoxLayoutCreate(blueFrame, BCVertical)
guitk.BCSetBackgroundColor(blueFrame, 160, 160, 255)
redFrame = guitk.BCFrameCreate(vb)
guitk.BCSetBackgroundColor(redFrame, 255, 160, 160)
guitk.BCBoxLayoutCreate(redFrame, BCHorizontal);
greenFrame = guitk.BCFrameCreate(vb)
guitk.BCSetBackgroundColor(greenFrame, 160, 255, 160)
guitk.BCBoxLayoutCreate(greenFrame, BCHorizontal)
guitk.BCToolBoxAddItem(toolBox, blueFrame, "Blue frame")
guitk.BCToolBoxAddItem(toolBox, redFrame, "Red frame")
guitk.BCToolBoxAddItem(toolBox, greenFrame, "Green frame")

#'Blue frame'
#Check out the widget setting to a BCDrawerGridCreate
drawer = guitk.BCDrawerGridCreate(blueFrame)
checkFrame = guitk.BCFrameCreate(drawer)
guitk.BCBoxLayoutCreate(checkFrame, guitk.constants,BCHorizontal)
checkBoxA = guitk.BCCheckBoxCreate(checkFrame, "CheckBox A")
checkBoxB = guitk.BCCheckBoxCreate(checkFrame, "CheckBox B")
checkBoxC = guitk.BCCheckBoxCreate(checkFrame, "CheckBox C")
bgroup = guitk.BCButtonGroupCreate(drawer, "Exclusive Radios",
guitk.constants.BCVertical)
guitk.BCButtonGroupSetCheckable(bgroup, 1)
for i in range(numButtons):
ii = i + 1
name = "RadioButton " + str(ii)
rb = guitk.BCRadioButtonCreate(bgroup, name, "", 0)
guitk.BCRadioButtonSetPressFunction(rb, "", 0)
guitk.BCButtonGroupInsert(bgroup, rb, i)

guitk.BCButtonGroupSetPressedFunction(bgroup,
"radioButtonGroupPressed", 0)
buttonFrame = guitk.BCFrameCreate(drawer)
guitk.BCBoxLayoutCreate(buttonFrame, guitk.constants.BCHorizontal)
toggleButton1 = guitk.BCPushButtonCreate(buttonFrame,
"toggleButton1", "", 0)
guitk.BCRadioButtonAddManagedWidget(rb, toggleButton1,
BCManagedShow,
BCManagedHide)
toggleButton2 = guitk.BCToolButtonCreate(buttonFrame,
"filter_16.png",
"toggleButton2", "", 0)
guitk.BCButtonSetToggleButton(toggleButton1, 1)
guitk.BCDrawerGridInsertWidget(drawer, checkFrame, 1,
"CheckBoxes")
guitk.BCDrawerGridInsertStableWidget(drawer, bgroup)
guitk.BCDrawerGridInsertWidget(drawer, buttonFrame, 1, "Buttons")

BETA CAE Systems 221 META Automation User’s Guide


4. Scripting

#'Red frame'
guitk.BCLabelCreate(redFrame, "Degrees");
spin = guitk.BCSpinBoxCreate(redFrame);
guitk.BCSetUserDataKey(window, "spin", spin);

#'Green frame'
guitk.BCLabelCreate(greenFrame, "Include Files")
combo = guitk.BCComboBoxCreate(greenFrame, comboVals)
guitk.BCComboBoxSetActivatedFunction(combo, "comboActFun", 0)

//This is for reading and saving to xml


guitk.BCSetSaveSettings(toolBox, "coloredToolBox")
guitk.BCSetSaveSettings(checkBoxA, "CheckBox A")
guitk.BCSetSaveSettings(checkBoxB, "CheckBox B")
guitk.BCSetSaveSettings(checkBoxC, "CheckBox C")
guitk.BCSetSaveSettings(bgroup, "Exclusive Radios")
guitk.BCSetSaveSettings(toggleButton1, "toggleButton1")
guitk.BCSetSaveSettings(toggleButton2, "toggleButton2")
guitk.BCSetSaveSettings(spin, "Degrees")
guitk.BCSetSaveSettings(combo, "writeProperties")

def calcCallBack(button, data):


#The callback that creates and shows a BCCalculator connected to the BCLineEdit
calcWin = guitk.BCWindowCreate("Calculator",
guitk.constants.BCOnExitDestroy)
calc = guitk.BCCalculatorCreate(calcWin)
guitk.BCCalculatorConnectWithButtonLineEdit(calc, data)
guitk.BCShow(calcWin)
return 1

def buttonsCreation(window, vb2):


#Create BCButtonLineEdit with calculator
leCalc = guitk.BCButtonLineEditCreate(vb2, "")
buttonCalc = guitk.BCToolButtonCreate(leCalc, "calculator_16.png",
"",
"calcCallBack", leCalc)
guitk.BCButtonLineEditAddRightButton(leCalc, buttonCalc)

#Create dummy buttons in a gridLayout


g = guitk.BCGridLayoutCreate(vb2, 3, 3)
for r in range(3):
for c in range(3):
b = guitk.BCPushButtonCreate(g, "button_"+r+"_"+c,
"", 0)
guitk.BCGridLayoutAddWidget(g, b, r, c,
guitk.constants.BCAlignCenter)

guitk.BCTextEditCreate(vb2, "")
guitk.BCLabelTickerCreate(vb2, "BCTicker has the ability to scroll
from left to right if the text can not
fit in the widget`s width.
User can also scroll left or right by pressing (and keep pressed)
the left mouse button and moving the cursor
BETA CAE Systems 222 META Automation User’s Guide
4. Scripting

right or left.")

def tabChangedFun(tw, oldPage, newPage, window):


readOnDemand = guitk.BCGetUserDataKey(window, "readOnDemand")
saveOnDemand = guitk.BCGetUserDataKey(window, "saveOnDemand")
vb1 = guitk.BCGetUserDataKey(window, "vb1")
if newPage == vb1:
e = 1
else:
e = 0
#Disable read and save button for second tab, since they are not applicable
guitk.BCSetEnabled(readOnDemand, e)
guitk.BCSetEnabled(saveOnDemand, e)
guitk.BCSetCaption(window, guitk.BCTabWidgetGetTabLabel(tw,
newPage))

def checkWindow(wid, usd):


spin = guitk.BCGetUserDataKey(wid, "spin")
if guitk.BCSpinBoxGetInt(spin) > 6:
guitk.BCWindowFlash(wid) #That's a flashy feature...
return "The spin box value is too high!"
return ""

def readSettingsOnDemand(b, window):


guitk.BCWindowReadControlSettings(window)

def saveSettingsOnDemand(b, window):


guitk.BCWindowSaveControlSettings(window)

def main():
window = guitk.BCWindowCreate("AutoSavingSettings",
guitk.constants.BCOnExitDestroy)

#Check on 'Enter' press


guitk.BCWindowSetCheckFunction(window, "checkWindow", 0)

#Do save settings to xml


guitk.BCWindowSetSaveSettings(window, 1)
#Creation of BCTabWidget
tw = guitk.BCTabWidgetCreate(window)
vb1 = guitk.BCVBoxCreate(tw)
guitk.toolboxCreation(window, vb1)
guitk.BCTabWidgetAddTab(tw, vb1, "toolBox")
#NOTE: We create a BCFrame to be able to insert a gridLayout.
vb2 = guitk.BCFrameCreate(tw)
guitk.BCBoxLayoutCreate(vb2, guitk.constants.BCVertical)
buttonsCreation(window, vb2)
guitk.BCTabWidgetAddTab(tw, vb2, "buttons and textEdit")
guitk.BCTabWidgetSetTabMovingEnabled(tw, 1)
guitk.BCTabWidgetSetCurrentTab(tw, vb1)

BETA CAE Systems 223 META Automation User’s Guide


4. Scripting

#Creation of BCDialogButtonBox with the 2 extra buttons


dbb = guitk.BCDialogButtonBoxCreate(window)
readOnDemand = guitk.BCPushButtonCreate(dbb, "Read On Demand",
readSettingsOnDemand, window);
saveOnDemand = guitk.BCPushButtonCreate(dbb, "Save On Demand",
saveSettingsOnDemand, window)
guitk.BCDialogButtonBoxAddButton(dbb, readOnDemand)
guitk.BCDialogButtonBoxAddButton(dbb, saveOnDemand)

#Setting the CurrentChangedFunction


guitk.BCSetUserDataKey(window, readOnDemand, readOnDemand)
guitk.BCSetUserDataKey(window, saveOnDemand, saveOnDemand)
guitk.BCSetUserDataKey(window, vb1, vb1)
guitk.BCTabWidgetSetCurrentChangedFunction(tw, tabChangedFun,
window)
guitk.BCShow(window)

BETA CAE Systems 224 META Automation User’s Guide


4. Scripting

4.6. BCGUIDesigner

4.6.1. Introduction
The Designer is a tool that enables the easy generation of windows using a graphical user
interface. The functions used for creating the interface belong to the BCGUI function group. The
great advantage of the Designer is the automatic generation of code that reduces the preparation
time of a script. The following paragraphs will focus in the presentation of the Designer's interface
but without any particular emphasis on the BCGUI functions that are used in the background.

4.6.2. The Designer's interface


The Designer, depicted below, is accessed through the Script Editor through the function
Tools > Designer.

The interface contains, by default, the following sections:


ToolBox
This is the window that hosts all the functions for creating widgets, layouts or items.
Constructed Items
This is a tree list with all created items.
Common Parameters (BC)
This window lists all the parameters that are common for each BCGUI item.

BETA CAE Systems 225 META Automation User’s Guide


4. Scripting

CallBack Functions
This is the window where it hosts all created callback functions.
Parameters
This window displays all the parameters related to the selected item of the Constructed Items list
window.
Source Code
This is the area where the automatically created code resides.
Help
This is the area where the help text of the selected parameter is displayed.
The visibility of the aforementioned sections can be controlled from the View menu. The interface is
customizable. All sections can be untagged double clicking on their title bar and tagged in another
window side position.

4.6.3. Toolbox
The ToolBox, depicted on the left, is the starting
point of all actions performed in Designer.
It hosts in separate tabs all the necessary
functions for creating the main window, buttons,
containers, views, widgets and input items.
Initially, only the Window tab is active since this
will create the window that will be used as the
parent of all features.
Expand the Window tree and press the Apply
Settings button to create the main window, named
'TopWindow'. This will make the rest of categories
available.

BETA CAE Systems 226 META Automation User’s Guide


4. Scripting

Expanding any object under any category will


reveal a set of basic options necessary for the
creation of the object. These options are actually
the input arguments of a BCGUI function and thus
they are characterized by their type (integer,
string, element etc) and their value. The options
initially have the default values but they can be
also set up by the user, except those that are of
element type.
The button Apply Settings always creates the
object.
In the following example a button and a check box
have been created under the top window.

The parent object controls the objects' order. The created items are listed in the Constructed Item
list in the order they have been created. Selected Item in the Constructed Item list is highlighted in
yellow color.
As it is shown above, any object that is added directly to the top window is distributed vertically. To
control the order add the same objects under a BoxLayout container of the Containers group. In
BETA CAE Systems 227 META Automation User’s Guide
4. Scripting

order to do so first create the BoxLayout container throught the Toolbox and then in the
Constructed Item list mondify the items tree structure in the desired way by siply dragging theitems
in the list. In order to add an item as a child of another it should be draged on to the parent item:

4.6.4. Constructed items list


All the created objects are listed under the Constructed Items list. The list has a tree structure
where it is easy to recognize any parent-child relationship or objects' classes.
Drag-n-drop actions are allowed so the position of an object can be altered at any time.
Pressing on an object of the list, highlights with yellow the corresponding object of the TopWindow.
On the contrary, pressing <Ctrl+Left mouse button> over an object of the TopWindow, highlights
the object on the list.
Objects can be deleted either pressing the Delete key or from the Delete Item context menu option.

BETA CAE Systems 228 META Automation User’s Guide


4. Scripting

4.6.5. Common parameters (BC)


The Common Parameters (BC) window,
depicted on the left, lists all the options
that are considered as common for all
individual objects.
The name and the input arguments of the
parameters are displayed in two separate
columns.
In order to change the default parameter
options, expand the parameter and type
where it is allowed the new value. At the
end, press the Apply Settings button to
confirm the changes.

In the following image, a tooltip is going to be added for the button 'BCPushButton_1'. Select the
button object from the Constructed Items list or from the screen and type the tooltip text under the
Values column of the AddToolTip>string tip parameter.
After confirmation, place the cursor over the button to see the tooltip. Fields that can be edited
became editable double clicking on them.

BETA CAE Systems 229 META Automation User’s Guide


4. Scripting

4.6.6. Parameters
The Parameters window, depicted on the left,
lists all the unique options of a selected object.
As soon as an object is selected either from
the screen or from the Constructed Items list,
the title of the Parameters window and the
actual parameters change accordingly.
The name and the input arguments of the
parameters are displayed in two separate
columns. The name of each parameter
describes its use.
As in any other list of parameters, the
corresponding options have the default values
but they can get new ones by the user. For
example, to change the button's name,
expand the 'ButtonSetText' and type a new
value for the option 'text'.

At the end, press the Apply Settings button to confirm the changes.

BETA CAE Systems 230 META Automation User’s Guide


4. Scripting

4.6.7. CallBack functions


Those parameters that their name ends in „Function‟ set up the callback functions of the object. In
order to find all parameters related to callback functions, activate the filter and type 'function' in the
Parameters field:

Two callbacks of different type have been filtered. The user can change any option according to his
needs. When the Apply Settings button is pressed the callback type and its name automatically are
listed under the CallBack window. The title of the window indicates the parent object type:

The last argument of all callback functions can be of any type and corresponds to user data.
Note that a callback function should be already set for the object in order to be listed in the
CallBack Functions list. In order to do so the name of th efunction that will be called when the
button is pressed shouldbe entered in the BC_BUTTON_CLICKED_FUNCTION value.

BETA CAE Systems 231 META Automation User’s Guide


4. Scripting

4.6.8. Help area


Each parameter corresponds to a BCGUI function. Selecting either, a common parameter or a
unique parameter, the Help area displays the help text of the parameter-function.

4.6.9. Source code area


The Source Code window is the area where the Designer automatically writes the code as soon as
an action is performed. An action is performed every time the Apply Settings button is pressed. The
generated code consists of one main nameless function and any number of callback functions.

The source code is not editable and changes automatically only when an action is performed or
when an object is deleted. However, it can be totally cleared without destroying the created window
through the Code>Clear Source Code. The next time an action will be performed, the source code
will be again generated.

4.6.10. Editing the source code


The source code, including the main function and the callbacks that are constructed by the
Designer tool, will be probably only a small portion of an extensive script. The rest of the code must
be manually added by the user through the script editor. The script code can be saved as any other
script through the File>Save and then can be reopened by the Script Editor for further editing.
Alternatively, it can be directly sent to the Script Editor through the Code>Set Code to Script Editor.
Replace the <add_function_name> with 'main' and run the code in order to launch the created
interface.
Note that the Designer cannot be used for opening scripts unless it is free of user defined code.

BETA CAE Systems 232 META Automation User’s Guide


4. Scripting

4.7. Running scripts

4.7.1. Introduction
A script can be executed from META GUI through one of the following ways:

- From File > Open Session/Script - As Part of a session


- Through the Script Editor - Called from inside another script
- From META commands - As a Built-in function
- As a session, also in batch mode - Inside the Statistics

4.7.2. Running scripts from GUI


4.7.2.1. Running script from the Script Editor

To run a script through the Script Editor, it must be loaded in the Editor window. Through the option
Debug > Run (F5), normally the main function of the script loaded in the current opened window is
executed (see comments below).
Through the option Debug > Run Function, the function to be executed can be selected from the list
of the functions which exist in the open Beta script and Python files. In the field Type functions
arguments, the arguments of the function are typed separated by comma. Any syntax errors are
reported in the output area.

Running the script through the Script Editor, the comments #!script and #!EOF are not
necessary, but no session commands should be included.
Which function is called – Python Scripting
By default, a newly created Python script contains the lines
If (__name__ ==„ __main__„):
main()
at the end of the script. These lines define the function to be called when the script is executed in
the script editor or through the read session command described below. By default the main
function is set to be called.
Which function is called – BETA Scripting

BETA CAE Systems 233 META Automation User’s Guide


4. Scripting

By default, if the script contains a function called “main”, then running it, this particular function is
executed. However, adding the keyword “entrypoint” in front of the “def“ statement of a
function, then this function becomes stronger than “main” and it will be finally executed when
running the script. In the following code example, the “test” function will be executed instead of
“main”.
entrypoint def test()
{
Print("test function will be executed");
}

4.7.2.2. Running script from the META command line

To run a script, the following command can be applied in the META command line:
script execute "<path>\<script filename>::<function name>(<arguments>)"
This way the specified function inside the defined filename will be executed with the arguments
given.
To run a script saved within a project, the following command can be applied in the META
command line:
script project execute <path>\<project filename> <script_ids>
This way the specified script inside the defined project will be executed. Also multiple scripts can be
executed entering the ids of scripts (e.g. 1,2 or 1-5 or all to execute all scripts).
To run a script and assign the return value of the script to a META variable apply one of the
following META commands:

script execute getresult <variable name> "<path>\<script filename>::


<function name>(<arguments>)"
options var fromscriptfunc <variable name> <path>\<script filename>::
<function name>(<arguments>)
options var add <variable name> "`<path>\<script filename>:: <function
name>(<arguments>)`"

Examples:
- The following command will execute the function Funct_1 inside the file /home/example.bs
with arguments 10 and string meta and the above expression will be replaced by the return value
of the function:
script execute "/home/example.bs::Funct_1(10, „meta„)"
Note that string arguments of called function should be written between single quotes „‟.

- The following command will execute the function Funct_1 inside the file /home/example.bs
with arguments 10 and string meta and the return value of the function will be assigned to variable
var1:
script execute getresult var1 "/home/example.bs::Funct_1(10, „meta„)"

- A module can also be loaded by applying the following command:

BETA CAE Systems 234 META Automation User’s Guide


4. Scripting

script module load <script filename>


Once a module is loaded, its functions can be called directly in a built in function. So the previous
example will become:
`::Funct_1(10, „meta„)`
Only one module can be loaded, so in case another module is loaded, the already loaded one will
be unloaded.
The following commands can be used to unload or reload the loaded module:
script module unload / reload

4.7.2.3. Running a script as a session

A script can be run as a session file in three ways:


1. From File > Open Session/Script or through the Read Results > Geometry interface

2. Through read session command, in META command line. Which function is called is
explained in Chapter “Running scripts from the script Editor”

3. Point the script file as META running option in META Launcher either:

or by running the META execution command with the –s running option

BETA CAE Systems 235 META Automation User’s Guide


4. Scripting

In that case script file should be located in the META current directory.
However, if the script is to be executed as a session, the following comment lines have to be placed
in the script code.
BETA Scripting language

At first line of the script: #!script or //#!script or // BETA script

At last line of the script: #!EOF or //#!EOF or

Python

At first line of the script: #PYTHON script

At last line of the script: #!EOF

4.7.2.4. Running a script as part of a session

A script can also be a part of a session file. In this case, it is also mandatory to have the comments:
BETA Scripting language

In the beginning of script: #!script or //#!script or // BETA script

In the end of the script: #!EOF or //#!EOF

Python

In the beginning of script: # PYTHON script Note: Space char. between # and PYTHON

In the end of the script: #!EOF

More than one scripts can be embedded in a single session file, so that parts of session file and
scripts are executed sequentially.

4.7.2.5. Running a script from inside a script

A function that exists in another script file can be run through LoadExecuteFunc() script function.
This function returns the return value of the called function.

Examples:
The following will run the function some_fun located in example.bs:
LoadExecuteFunc("/home/demo/example.bs", "some_fun");

BETA CAE Systems 236 META Automation User’s Guide


4. Scripting

If the function needs arguments the following can be written:


LoadExecuteFunc("/home/demo/example.bs", "some_fun", 10, "string");
In case the function returns a value this can be reserved in a variable throught:
Return_Value = LoadExecuteFunc("/home/demo/example.bs", "some_fun");

4.7.2.6. Running a script as a Built-in function

To run a script as a built-in function inside other META tools (e.g. Annotations, Variables, Curves,
User defined function etc) the following should be typed:
`<path>\<script filename>::<function name>(<arguments>)`
This way the specified function inside the defined filename will be executed with the arguments
given and this part will be replaced by the return value of the function.
This can also be used for when applying any command from command line. The built-in function
will be replaced by the return value of the script and the command will be applied with the replaced
value.

Example
The following function will execute the function Funct_1 inside the file /home/example.bs with
arguments 10 and string meta:
`/home/example.bs::Funct_1(10, „meta„)`
The above expression will be replaced by the return value of the function.

Remarks
When a function is called from a built-in function, all the messages that are printed by the script in
the message window are hidden by default. This can be changed through the META commands
script messages show / hide

4.7.2.7. Running a script inside the Statistics tool

To run a script inside the statistics tool, a user defined column should be created. In the column‟s
expression the following should be typed:
<path>\<script filename>::<function name>(<arguments>)
This way the specified function inside the defined filename will be executed with the arguments
given and the return value of the function will be displayed in the column. The values of other
columns can be given as arguments to the function.

Example
The following command will execute the function Funct_1 inside the file /home/example.bs,
with arguments 10 and the value of column C0 for each row:
`/home/example.bs::Funct_1(10,C0)`

BETA CAE Systems 237 META Automation User’s Guide


4. Scripting

4.7.3. Running a script without GUI


4.7.3.1. General

META can also run without GUI. In such case META runs in batch mode.
META can be run in batch mode through the running options:
–b and –noqui
In batch mode a script can be run as a session through the:
–s running option
and a script function can be run as a session through the:
–exec running option.
Note that only the main function of the script will be executed. Also in order to execute the script as
a session the following comment lines have to be placed as first and last lines of the script code:

At first line of the script: #!script or //#!script or // BETA script

At last line of the script: #!EOF or //#!EOF

Remark
The script function BatchMode() is available in order to get whether META runs in batch mode.

BETA CAE Systems 238 META Automation User’s Guide


4. Scripting

4.7.3.2. Running a script with the –s running option

If meta_post64.sh is the shortcut command used to launch META and test.bs is the willing
script, regarding the OS, the following can be written:

Linux OS:

meta -b -s /home/demo/test.bs
or
meta -nogui -s /home/demo/test.bs

Windows OS:

For filepaths that do not contain blank spaces:


meta -b -s C:/temp/demo/test.bs
or
meta -b -s C:\temp\demo\test.bs
For filepaths that contain blank spaces:
meta -b -s “C:\Documents and Settings\test.bs”

Remark
In case arguments need to be passed, these can be passed as session arguments after the –s
running option.
The arguments can be retrieved as $0, $1, etc variables and stored to META variables.
Then arguments can be retrieved afterwards from the script function through the script function
MetaGetVariable().
The script that follows next can be run through:
meta –b -s /home/demo/test.bs "This is argument 1" 10 23.2
input variables are This is argument 1, 10 and 23.2.
The script prints the first variable and the sum of second and third.
// BETA script
#include "meta_structs"

def main()
{
MetaCommand("opt var add var0 $0");
MetaCommand("opt var add var1 $1");
MetaCommand("opt var add var2 $2");
script_var0 = MetaGetVariable("var0");
script_var1 = Atof(MetaGetVariable("var1"));
script_var2 = Atof(MetaGetVariable("var2"));
Print(script_var0);
x = script_var1 + script_var2;
Print(x);
}
Note that counting arguments starts from 0. Arguments must be separated with space. If the string
of an argument contains a space character, then it is mandatory to enclose is in double quotes “”.

BETA CAE Systems 239 META Automation User’s Guide


4. Scripting

4.7.3.3. Running a script with the -exec running option

If meta_post64.sh is the shortcut command used to launch META and fun1 is the function in
test.bs script to be executed, regarding the OS, the following can be written:

Linux OS:

meta -b -exec "script execute /home/demo/test.bs::fun1()"

Windows OS:

For filepaths that do not contain blank spaces:


meta -b -exec "script execute C:/temp/demo/test.bs::fun1()"
or
meta -b -exec "script execute C:\temp\demo\test.bs::fun1()"
For filepaths that contain blank spaces:
meta -b -exec "script execute C:\Documents and Settings\test.bs::fun1()"

Remark
The function fun1, in the script named test.bs that follows next can be run through:
meta -b -exec "script execute /home/demo/test.bs::fun1('This is argument
1', 10, 23.2)"
input arguments are This is argument 1, 10 and 23.2.
The function prints the first argument and the sum of second and third.
// BETA script
#include "meta_structs"

def fun1(string script_var0, int script_var1, float script_var2)


{
Print(script_var0);
x = script_var1 + script_var2;
Print(x);
}

4.7.4. Stopping the execution of a script


A running script can be stopped using the the keyboard buttons Esc / Pause. The script function
script.CheckBreak()must exist inside the script as below:
# PYTHON script
import beta
from beta import script

def main():

for i in range (0,1000000):

BETA CAE Systems 240 META Automation User’s Guide


4. Scripting

print(i)
script.CheckBreak()

if __name__ == '__main__':
main()

4.8. META KEYWORDS

A list with all the META KEYWORDS and their correspondence can be found as following:
- Open Script Editor
- Go to Function List window (if this is not visible go to main menu is Script Editor window, Window
> Funciton List)
- In Library tab select betameta_structs for Python or Meta help for BETA Scripting language and
and then double click on META_KEYWORDS to get all the lists in the Output window of the Script
Editor. If the Output window is not visible, activate it from main menu in Script Editor, Window >
Output window
- In Python Scripting in order to use the KEYWORDS the module constants needs to be imported
first as in example below:

from meta import constants


part_type =constants.PSHELL

BETA CAE Systems 241 META Automation User’s Guide


Index

Index
B Data types ............................................. 88
Exceptions ...........................................100
BCGUI Designer ....................................... 225 Handling Dictionaries ............................ 96
Callback functions ............................... 231 Handling Lists ........................................ 94
Common Parameters .......................... 229 Handling Strings .................................... 95
Help ..................................................... 232 Interacting with META ........................103
Parameters .......................................... 230 Loop statements ................................... 92
Toolbox ............................................... 226 META Classes ......................................104
Window Designer ................................ 225 Modules and namespaces..................... 90
BCGUI Functions ...................................... 208 User functions ....................................... 97
BETA Scripting Language
Conditional statements and branching S
........................................................ 137
Script Editor
Custom GUI ......................................... 188
Debug .................................................... 84
Data types ........................................... 126
META Window Designer ....................... 79
Exchanging data .................................. 198
Monitor ................................................. 83
Handling Maps .................................... 145
Project ................................................... 86
Handling Matrices ............................... 142
ScriptEdit window ................................. 71
Handling String.................................... 144
Snippets................................................. 80
Interacting with META ........................ 159
Session
Introduction ........................................ 125
Encrypt Session ..................................... 10
Loop statements ................................. 139
Suppress Redundant Commands .......... 10
Matrices and Maps ............................. 130
Session decoding ......................................... 7
META session commands ................... 158
Session Editor .............................................. 8
META Structs ....................................... 160
Create Package ..................................... 22
Operators and basic calculations ........ 131
Create User Toolbar .............................. 24
User functions ..................................... 147
Debug .................................................... 27
Variables ............................................. 127
Snippets................................................. 25
XML files .............................................. 202
Session files ................................................. 3
C T
Controldraw ............................................ 4, 7
Toolbar Designer ....................................... 33
I Checkbox ............................................... 41
Directory textbox .................................. 47
Installation directory ............................... 112 Filetextbox............................................. 45
Property Editor ...................................... 48
P Radio button ......................................... 42
Python Slider ..................................................... 43
Conditional statements and branching . 91 Textbox.................................................. 44
Custom GUI ......................................... 124

BETA CAE Systems 242 META Automation User’s Guide


BETA CAE Systems International AG
D4 Business Village Luzern, Platz 4
CH-6039 Root D4, Switzerland
T +41 41 545 3650, F +41 41 545 3651
[email protected]
www.beta-cae.com
physics on screen

You might also like