• No results found

Debugging scripts

In document Ansa Scripting (Page 99-105)

9. SCRIPT EDITOR

9.9 Debugging scripts

Scripts can be run in two ways. First, the ‘normal’ run, executes the code directly. Second, is through the debugger which executes the code line by line. In the later case we can pause the execution of a script in order to investigate the status of variables. This is very useful in cases where a script function have logical errors which probably lead to strange results. There are also times that unidentified problematic areas of functions like endless loops or wrong input data result in an infinite execution. All these situations can be traced using the debugger of Script Editor. Usually, in such cases the first step is to identify the variables that produce the error. If there is no such clue, we select the most important of them. Next, we add them in the watch list which help us to inspect their history during the execution of the script. A variable can be added in the watch list if we right click on it and select the Add watch option.

In the above example the cursor is pointing on variable p and therefore when selecting on the menu that opens the option Add watch: main::p, p is added in the watch list. This list can be displayed pressing the button or through the View>Watch window of the main menu.

This window displays also the variable name, the function where it belongs, its type (local or global) and the current value.

Finally, we must define the lines where the execution of the script will be paused. After each stop we are able to identify in the watch list any change of the variable. Consequently, it is recommended the lines that are selected to be just before or after the variable definition. For letting the editor to distinguish these lines, breakpoints are inserted to them. Having the cursor on a line and pressing the button inserts a breakpoint. On the other hand pressing the button deletes a breakpoint. Whenever a breakpoint is inserted, the respective line is colored red.

For running the function in debug mode the button must be pressed. Alternatively, we can press {Shift+F5} or Project>Debug.

Important Note: The name of the function must be "main"

Suppose that you would like to trace any changes of matrix p. Insert a breakpoint in line 5 and open the watch window. Press <Shift+F5> to run in debug mode. The execution stops in line 5 and the current status of p is displayed in watch window. From now on every time you press the button or <F10>, the execution continues and stops in each line. Pressing anytime the button , the script runs without stop until the next breakpoint. In our example after the second stop the matrix p changes and now holds the first value which is 20.

Keep pressing or until the execution is finished.

Important Note: When the execution stops over a breakpoint the line is colored blue.

If the variable that we are looking for is not in the "main" function but in a sub function, the debugger cannot reach it unless we change the way that searches the code. This can be achieved through the buttons and . The first instructs the execution sequence to step into a sub function, while the second to step out of a sub function. Let’s see this with an example:

Assume we are interested in watching the values of the variable k which is located in sub function foo. For this, we set a breakpoint in a line prior to foo call (line 6) and press <Shift+F5>. The execution stops in this line and from that point we press the button until we get inside foo.

APPENDIX

Sample scripts

In ANSA installation directory, under the path docs/scripts, there is a list of user defined scripts that can be served as examples for either a beginner or an expert user. These scripts can be loaded automatically if you move the file user_ANSA_TRANSL from the config directory into the current directory and rename it as ANSA_TRANSL. Additionally, for every function a button will be created under TOOLS>USER MENU.

Some of the most important scripts that can be found within this directory are:

Script Name Description

AlphabetSorting Renumbers the properties according to the alphabetical order of their names. In the input window that appears, the user must write the DECK, the type of property (For example PSHELL,PSOLID etc) and the starting id. The starting id must be out of the current range of all property ids.

CheckContactsDyna Reads the ‘messag’ file of DYNA solver and reports the results in a check window.

CheckEmptySets Checks the sets of the database whether they are

empty.

CheckPlink Reads the "*msg" file exported from PAMCRASH

and displays in the check window the warning messages regarding the PLINKs definitions. The user must select the "*msg" from the file manager that opens.

CombineSets Adds, subtracts or intersects sets into a target set.

CompareConnectionPoints Compare the positions of current connection points with the ones that exist in a selected vip file. Geometric points are created and stored in 4 new ANSAPARTS indicating the results. The user must select a ‘vip’ file from the file manager and to define a tolerance.

CompressRbe2 Compress the RBE2s that have free dependent nodes

CompressRbodys Compress the RBODYs that have free dependent

nodes

OutputVpmFromPartManager Creates an ‘xml vpm’ tree describing the already defined hierarchy of ANSA Part Manager.

DetectSingleTripleBounds Detects elements that have single or triple bounds and stores them in 2 sets respectively. The functions works for 1st order elements. If a shell has single and triple bounds then it is stored in both sets. Note that elements with single or triple bounds are considered those who have a whole side that lies in such a bound and not those that have at least one of their nodes in this bound.

Filename2Pid Renames the only existing PID of the ansa database with the ansa filename and saves the file. The ansa files are located in a directory. The functions works for NASTRAN deck and PSHELL property

FindVisibleParts Finds visible parts. A part is considered visible even it has only one of its shells or faces visible. The entities are stored in a matrix.

Return: The function returns a matrix with the

elements (pointers) of visible parts

IgesPerPart Output an iges for each part

InputGEBsAndConnectors Input Connectors and Generic Entities of all types simultaneously.

The script will:

- Resolve all dependencies of GEBs and CONNECTORs upon other GEBs and CONNECTORs

- Create the properties (DEFINED=NO) and parts that are referenced in the "connectivity" and "Part1", "Part2" fields of GEBs and CONNECTORs respectively but probably do not exist in the database

- Create all SETs that are referenced by GEBs in the "ResultsFromSet" search option, if they don't exist

- Create all local coordinate systems that are referenced by GEBs and CONNECTORs in the "cord" field, if they don't exist

- Notify the user in case GEBs or CONNECTORs with the same ids already exist in the database

- The current deck during the input must support the generated entities

- The xml files are produced through the "InputGEBsAndConnectors.c" and "OutputConnectorEntities.c" scripts.

Tips: The user can read the xml files in an empty

ANSA db, save it and then merge it in the assembly db with the options:

-Properties ->Keep Old -Merge Sets By Name -> Yes -Merge Parts -> Yes

MakeSkin Applies the skin function to all ansa files that are

located in a user defined source directory, and outputs the files in a user defined output directory. If the skin function is applied correctly the name of the ansa file is changed to

<ansa filename>_done.ansa and if not to

<ansa filename>_not_done.ansa

MergeInDir Merges files located in a specific directory and saves with the name "merged.ansa". The filenames must not have spaces.

OpenCatiaInANSA Translates the selected Catia File and opens it in ANSA. The ansa file is saved in the current directory. This function must be used in Linux OS.

OutputActran Outputs in ACTRAN solver.

OutputConnectors Outputs connectors entities in XML format.

OutputGEs Outputs all Generic Entities of selected type in XML

format.

PartName2Pid Renames the user given type of property with the

name of the ANSAPART. It is required the pids to be equal with the module ids and the desired deck to be activated.

PartToPid Creates a "PSHELL" property for each part of the database. The ids of the created "PSHELLS" start from a user value. The names of the properties are the names of the parts. Note that the script can work also in FE models. When running this function TOPO menu must be active.

PedestrianWithIncludePam Reads the Points (target or contact or test) from a file, positions the headform to them and creates an PAMCRASH INCLUDE file for each point.The user is prompted to select the file containing the points The form of this file is :

ID;X;Y;Z

!!!! No empty line should exist in the points text file !!!! Details: The coordinate system should be defined with nodes (attached to the headform mesh)

The arguments of the array are:

Head model SET id, [Default value is 1000] Bonnet SET id, [Default value is 1001]

The angle that you want as hit angle on the bonnet, [Default value is 30]

The user must give the reference include name [Default "impactor.pc"]

The include files are named as "Incshot*.pc".

PlinksToCwelds Switch CWELDS to PLINKS and the opposite. The

script takes into account the 'RSEAR' values of PLINK for the realization of CWELDS and the "D" values of CWELDS for the realization of PLINKS. It keeps also the initial properties during the conversion.

PropsFromPart Finds the properties that the given part is using. The part must contain only geometry.

Return: A matrix with PIDs

PropShellToSet Creates a set for each 'SHELL' property. The user

must select the Deck, the type of property and must give the starting set id. The set takes the name of the property.

QualityReport Makes a report of violating shells according to the specified values. The user is prompt to create the log file through the file manager.

RandomColorsPID Applies new random colors to all visible properties.

RedConsGridsInSet Places the grids of red CONS into a set. The name of set is "Red Cons Grids". The model must be meshed.

RedConsShellsTriasInSet Place the shells and trias of red CONS in 2 sets. The names of sets are "Red Cons Shells" and "Red Cons Trias". The model must be meshed.

ReleaseConnections Releases FE-representations of Connection Entities from their Connection Entity. The FE- representations are added to a separate part in Parts Manager while the Connection Entities remain intact.

SplitConnectionCurve Splits the selected curves from the original connection curves (Adhesive, Seamline, Spotweldline, Hemming). At the end, the created curves have the same characteristics as the original one, while they keep the original id in their comments.

SampleBatchMesh Reads from a directory the ansa_mpar and the ansa_qual files, creates a session, adds in the session all the ANSAPARTS of the database, runs the session and exports statistics in the same directory. The statistics file is exported in the format that is defined in ANSA.defaults. (Html, text, text csv). The ansa_mpar must be called "sample_parameters.ansa_mpar". The ansa_qual must be called "sample_quality.ansa_qual".

TakePictures Sets the 6 views of ANSA and takes from each one

a snapshot. The pictures are saved in 'jpeg' format. The user is prompt to select the directory where the pictures will be saved. The entities must be visible. Furthermore, under the docs/scripts/Windows directory, there are useful examples regarding the creation of user custom gui using the windows scripting library of functions.

In document Ansa Scripting (Page 99-105)

Related documents