TiGL Viewer comes with a powerful JavaScript console that allows automatizing small workflows or helps debugging of geometries. To show and hide the console, press ALT+C.
The console has two purposes
In many cases, the user wants to open a CPACS file and execute TiGL function to compute and draw some points on the aircraft surface. Another use case would be to automate the creation of screenshots of a changing aircraft geometry.
We copied some practical features from the famous bash terminal to improve the usability of the console. This includes a history of the recently typed commands. Just type
To navigate through the recent commands from the history, use the up and down arrow keys.
To clear the console, enter
For a general help, type in
The console understands all kinds of JavaScript elements. Thus, typical constructs like loops, functions, and even classes can be defined. Instead of typing the code into the console, TiGL Viewer can also load and execute a script file. If you want to load a script file during the startup of TiGL Viewer, use the --script
option:
TIGLViewer --script myscript.js [--filename aircraft.cpacs.xml]
The ans
object: The result of the last command will be stored in a variable ans
. This can be sometimes quite practical:
In addition to pure JavaScript, TiGL Viewer offers some function to draw points, vectors and TiGL shapes.
Draw a point at (0,0,0)
Draw an arrow in z direction
Draw the first fuselage of a cpacs file
In case you want to do some vector arithmetic, we defined the Point3d
class, which offers some basic vector functionality:
To get a list of all Point3d
methods, enter
The TiGL Viewer scripting engine consists of four main objects. The whole application can be controlled with only these four objects. These are app, app.viewer, app.scene, and tigl.
The scripting engine contains a help() function that shows the available methods and properties for each object. To show the help for e.g. the tigl object, enter
This is the main object of the application. It is used to load and save files, load scripts, control the application's window size, and also close the application. Some methods of the app object are
method | description |
---|---|
openFile | opens a file (CPACS, STEP, IGES, BREP) |
saveFile | saves all visible objects to a file (STEP, IGES, BREP, STL) |
openScript | executes a TiGL Viewer script file |
closeConfiguration | closes the current CPACS configuration and clears the scene |
close | terminates TiGL Viewer |
To get a list of all methods and properties, enter help(app) in the TiGL Viewer console.
This object controls the rendering of the 3D view. It can be used to
There are different options, to make a screen shot of the viewer. The simplest is
This will create a screenshot with a white background color and the size of the image will be the size of the viewer's window. To disable the white background, type
In addition, you can also control the size of the resulting image file. However, this feature does not work in Linux or Max OS X. The syntax is the following:
The most important methods of the app.viewer object are:
method | description |
---|---|
setBackgroundColor | sets a solid background color (RGB triple, 0..255) |
setBackgroundGradient | sets a background with gradually darkening color(RGB triple, 0..255) |
viewTop | moves camera to the top view |
viewFront | moves camera to the front view |
viewLeft | moves camera to the left view |
viewAxo | changes camera to axonometrix view (top, left, front) |
fitAll | fits all objects into the viewer window |
zoomIn | zooms in the camera |
zoomOut | zooms out the camera |
To get a list of all methods and properties, enter
in the TiGL Viewer console.
The application scene controls, which objects are shown in the 3D view. Thus, it offers methods to display objects and points, to clear the whole scene and modifying the grid display.
The most important app.scene methods are:
method | description |
---|---|
wireFrame | if argument is true, all objetcs will be displayed in wireframe mode |
displayShape | displays a TiGL geometry (e.g. got from tigl.getShape("wingUID")) |
drawPoint | draws a point (e.g. app.scene.drawPoint(0,0,10)) |
drawVector | draws a vector/arrow (e.g. app.scene.drawVector(x,y,z,dx,dy,dz)) |
deleteAllObjects | clears the scene |
gridOn | displays the grid |
gridOff | turns of the grid display |
gridXY | Sets the grid into the X-Y plane |
gridXZ | Sets the grid into the X-Z plane |
gridYZ | Sets the grid into the Y-Z plane |
gridCirc | Switches the grid into polar form |
gridRect | Swictehs the grid into cartesian form |
To get a list of all app.scene methods and properties, enter:
The tigl object is used to access the TiGL library functions. Currently, not all functions are wrapped.
These are the functions currently wrapped by the scripting interface
In comparison to the C/C++ API, the scripting functions don't return error codes. Instead, an exception is thrown in case of an error, e.g. if no CPACS file is currently open.
The use of these functions is analog to the TiGL functions of the C API. The only exception is the tigl.getShape(uid)
method. It can be used to return the CAD representation of a CPACS entity. Currently, only wings, fuselages, wing segments, and fuselage segments can be returned by getShape
. The returned shape can then be rendered using the drawShape
command.
The point sampling functions (e.g. fuselageGetPoint
, wingGetChordPoint
, ...) return a Point3d object.
Example
Here are some real life examples how to use the scripting engine:
Open a file
Change to top view and save screenshot to image.png
Convert a STEP file into IGES format and close TiGL Viewer
Display all wings of an aircraft (which is already opened)
Switch to fullscreen view
Delete all visible objects
Disable the coordinate grid
Show polar grid in y-z plane