TCL-TK EXTENSION |
In this chapter, there are exposed the advanced features of GiD in terms of expandability and total control. The TCL-TK extension is the way to create script files to automatize any process created with GiD. With this language it is possible to add new windows or new functionalities to the program.
For more information about the TCL-TK programming language look at www.scriptics.com.
If such TCL file exists, it must be in the problem type directory; the name of the file has to be the problem type name with the .tcl
extension.
Event procedures |
The structure of problem_type_name.tcl
can optionally implements some of these TCL
prototype procedures (and other user defined procedures).
The procedures listed below are automatically called by GiD. Their syntax correspond
to standard TCL-language:
proc InitGIDProject { dir } { ...body(1)... } proc InitGIDPostProcess {} { ...body(2)... } proc EndGIDProject {} { ...body(3)... } proc EndGiDPostprocess {} { ...body(4)... } proc LoadGIDProject { filespd } { ...body(5)... } proc SaveGIDProject { filespd } { ...body(6)... } proc LoadResultsGIDPostProcess { file } { ...body(7)... } proc BeforeMeshGeneration { elementsize } { ...body(8)... } proc AfterMeshGeneration { fail } { ...body(9)... } proc SelectGIDBatFile { dir basename } { ...body(10)... } proc ChangedLanguage { language } { ...body(11)... }
dir
argument, which is the absolute path to the problem_type_name.gid
directory, which can be useful inside the routine to locate some alternative files.
filespd
argument, which is the path of the file which is being opened, but with a .spd
extension (specific problemtype data). This path can be useful if you want to write specific information of the problem type in a new file.
filespd
argument, which is the path of the file which is being saved, but with a .spd
extension (specific problemtype data). This path can be useful if you want to write specific information of the problem type in a new file.
Note: To use TCL to improve the capabilities of writing the
calculations file, it is possible to use the command *tcl
in the
template file (.bas file); see section Specific commands for details.
Control functions |
GiD offers the following TCL functions:
Process function |
.central.s process command_1 command_2 ...
This is a simple function but really powerfull. It is used to enter commands directly inside the central event manager. The format of the comand has to be a string with the same style as if they were entered by typing on the command line interface.
You have to enter exactly the same sequence as you would do interactively,
including the escape sequences, using the word escape
, and
selecting the menus and operations used.
It is possible to obtain the exact commands that GiD needs, by checking the right buttons toolbar (Utilities > Graphical > Toolbars). It's also possible to save a batch file (Utilities > Preferences > Batch file) and check there the commands used during the GiD session.
One simple example to create one line:
.central.s process escape escape escape escape \ geometry create line 0,0,0 10,0,0 escape
Info function |
.central.s info option
This function provides any information about GiD, the current data or
the state of any task inside the aplication. Depending on the arguments introduced after the .central.s info
sentence, GiD will output different information:
.central.s info materials
"Air Steel Aluminium Concrete Water Sand"
.central.s info materials Steel
"1 Density 7850"
.central.s info conditions ovpnt
"Point-Weight Point-Load"
.central.s info conditions Point-Weight
"ovpnt 1 Weight 0"
.central.s info conditions Point-Weight geometry
"E 1 - 2334 , E 2 - 2334 , E 3 - 343"
.central.s info Conditions -localaxes Concrete_rec_section mesh 2
{E 2 - {4.7123889803846897 1.5707963267948966 0.0} N-m 0.3 0.3 HA-25}
.central.s info back_layers
Layer2_*back*
.central.s info layers
"layer1 layer2 layer_aux"
.central.s info layers -on
"layer1 layer2"
.central.s info layers -entities lines layer2
"6 7 8 9"
.central.s info gendata
"2 Unit_System#CB#(SI,CGS,User) SI Title M_title"
NONE
if there's no mesh).
Example: .central.s info Project
"cmas2d e:\models\car_model 1 layer3 MESHUSE 0 normal YESPOST nodebug C:\TEMP\gid2 0 1.4"
1
followed by a list with all types of element used in the mesh. .central.s info Mesh
"1 Tetrahedra Triangle"
.central.s info Mesh MaxNumNodes
"1623"
.central.s info MeshQuality MinAngle Triangle 20 60 4
"13 34 23 0"
YES
if the user is in the GiD postprocess, and NO
, if the user is not.
#000000
would be black, and #FFFFFF
would be white.
#000000
would be black, and #FFFFFF
would be white.
#000000
would be black, and #FFFFFF
would be white.
Opaque
or Transparent
depending on the current transparency. Transparency is chosen by the user in the Select & Display Style window.
Massive
if the option Massive of the window Select & Display Style is selected. It returns Hollow
if that option is not activated.
Deformed
or Original
Deformed
or Original
.
STD
appears if the contour limit value is the default value, and USER
, if it's defined by the user.
Geometry Mesh None
)
Geometry Mesh None
)
#000000
would be black, and #FFFFFF
would be white.
255#255#255
would be white.
.central.s info list_entities status
Project name: UNNAMED
Problem type: UNKNOWN
Changes to save(0/1): 1
Necessary to mesh again (0/1): 1
Using LAYER: NONE
Interval 1 of 1 intervals
Degree of elements is: Normal
Using now mode(geometry/mesh): geometry
number of points: 6
number of points with 2 higher entities: 6
number of points with 0 conditions: 6
number of lines: 6
number of lines with 1 higher entities: 6
number of lines with 0 conditions: 6
number of surfaces: 1
number of surfaces with 0 higher entities: 1
number of surfaces with 0 conditions: 1
number of volumes: 0
number of nodes: 8
number of nodes with 0 conditions: 8
number of Triangle elements: 6
number of elements with 0 conditions: 6
Total number of elements: 6
Last size used for meshing: 10
Internal information:
Total MeshingData:0 Active: 0 0%
2 3 6 45
) a range of entities (example: entities from 3 to 45, would be 3:45
) or a layer (example: layer:layer_name
).
.central.s info list_entities Points 2 1
POINT
Num: 2 HigherEntity: 1 conditions: 0 material: 0
LAYER: car_lines
Coord: -11.767595 -2.403779 0.000000
END POINT
POINT
Num: 1 HigherEntity: 1 conditions: 0 material: 0
LAYER: car_lines
Coord: -13.514935 2.563781 0.000000
END POINT
.central.s info list_entities lines layer:car_lines
STLINE
Num: 1 HigherEntity: 0 conditions: 0 material: 0
LAYER: car_lines
Points: 1 2
END STLINE
STLINE
Num: 13 HigherEntity: 0 conditions: 0 material: 0
LAYER: car_lines
Points: 13 14
END STLINE
.central.s info list_entities -more Lines 2
STLINE
Num: 2 HigherEntity: 2 conditions: 0 material: 0
LAYER: Layer0
Points: 2 3
END STLINE
LINE (more)
Length=3.1848 Radius=100000
Higher entities surfaces: 1 3
END LINE
.central.s info parametric line 26 deriv_t 0.25
8.060864 -1.463980 0.000000
2 3 6 45
) a range of entities (example: entities from 3 to 45, would be 3:45
).
Example: .central.s info ListMassProperties Lines 13 15
LINES
n. Length
13 9.876855
15 9.913899
Selected 2 figures
________________________
Total Length=19.790754
Special functions |
It exists some special commands to control the redraw and wait state of GiD:
.central.s disable graphics 'value'
The value 0/1 Enable/Disable Graphics (GiD doesn't redraw)
EXAMPLE to disable the redraw:
.central.s disable graphics 1
.central.s disable graphinput 'value'
The value 0/1 Enable/Disable GraphInput (enable or disable peripherals: mouse, keyboard, ...)
EXAMPLE to disable the peripherals input:
.central.s disable graphinput 1
.central.s disable windows 'value'
The value 0/1 Enable/Disable Windows (GiD displays, or not, windows which require interaction with the user)
EXAMPLE to disable the interaction windows:
.central.s disable windows 1
.central.s waitstate 'value'
The value 0/1 Enable/Disable the Wait state (GiD displays a hourglass cursor in wait state)
EXAMPLE to set the state to wait:
.central.s waitstate 1
Usually these command are used jointly:
EXAMPLE
#deactivate redraws, etc wit a witget named $w $w conf -cursor watch .central.s waitstate 1 update .central.s disable graphics 1 .central.s disable windows 1 .central.s disable graphinput 1 ... #reactivate all and redraw .central.s disable graphics 0 .central.s disable windows 0 .central.s disable graphinput 0 .central.s process "redraw" $w conf -cursor "" .central.s waitstate 0
Note: It's more recommended for a tcl developer, to use the more 'user-friendly' procedures defined
inside the file 'dev_kit.tcl' (located in the directory \scripts).
For example, to disable and enable redraws, you can use:
::GidUtils::DisableGraphics ::GidUtils::EnableGraphics
It exists other GiD-tcl special commands to directly manage materials, conditions, intervals or create nodes and elements, as follows:
GiD_CreateData create|delete material ?<basename>? <name> ?<values>?
To create or delete materials
Example:
GiD_CreateData create material Steel Aluminium {3.5 4 0.2} GiD_CreateData delete material Aluminium
GiD_AssignData material|condition <name> <over> ?<values>? <entities>
To assign materials or contitions over entities
Example:
GiD_AssignData materials Steel Surface {1 5} GiD_AssignData condition Point-Load Nodes {3.5 2.1 8.0} {4 8} GiD_AssignData condition Face-Load face_elements {3.5 2.1 8.0} {15 1 18 1 20 2}
GiD_ModifyData materials|intvdata|gendata ?<name>? <values>
To change all field values of materials, interval data or general data
Example:
GiD_ModifyData materials Steel {2.1e6 0.3 7800} GiD_ModifyData intvdata 1 ... GiD_ModifyData gendata ...
GiD_AccessValue set|get materials|conditions|intvdata|gendata ?<name>? <question> ?<attribute>? <value>
To change only some field value of materials, interval data or general data
Example:
GiD_AccessValue set gendat Solver Direct
GiD_IntervalData <mode> <number>|?copyconditions?
To create, delete or set a interval data
Example:
GiD_IntervalData set GiD_IntervalData set 2 GiD_IntervalData create GiD_IntervalData create copyconditions
GiD_LocalAxes <mode> <name> ?<type>? <Cx Cy Cz> <PAxex PAxey PAxez> <PPlanex PPlaney PPlanez>?
To create delete or modify local axes.
For the 'exists' operation, if only it's specified the <name> field, then it's returned 1 when this name exists, and 0 if not.
If also is specified the other values, then <name> is ignored.
The returned value is:
-1 if match the global axes.
-2 if match the automatic local axes.
-3 if match the automatic alternative local axes.
0 if it does not match with any axes.
<n> if match the user defined number <n> (n>0) local axes.
Example:
GiD_LocalAxes create "axes_1" rectangular C_XY_X {0 0 0} {0 1 0} {1 0 0} GiD_LocalAxes delete axes_1 GiD_LocalAxes exists axes_1 GiD_LocalAxes exists "" rectangular C_XY_X {0 0 0} {0 1 0} {1 0 0} this last sample returns -1 (equivalent to global axis)
GiD_Mesh create|delete node|element <num>|append <elemtype> <nnode> <N1 ... Nnnode> ?<mat>? | <x y z>
To create or delete mesh nodes or elements.
Example:
GiD_Mesh create node append {1.5 3.4e2 6.0} GiD_Mesh create element 58 triangle 3 {7 15 2} steel GiD_Mesh delete element 58
Managing menus |
GiD offers some functions to change the GiD menus. With these functions it is possible to add new menus or to change the existing ones. If you are creating a problem type, these functions should be called from the InitGIDProject
or InitGIDPostProcess
functions (see section TCL-TK EXTENSION).
Note: Menus and option menus are identified by its name.
Note: It is not necessary to restore the menus when leaving the problem type, GiD already does it.
The TCL functions are:
new_menu_name
: name of the new menu.
prepost
can have these values:"PRE"
to create the menu only in the preprocess"POST"
to create the menu only in the postprocess"PREPOST"
to create the menu in the pre and postprocess
insert
argument is given, the new menu option is inserted.
menu_name
: name of the menu where you want to insert the new option.
option_name
: name of the new option you want to insert. If option_name
is "---"
, then , a separator line is inserted in the menu. If you want to insert an option to a submenu, you have to specify the path with ">". Geometry>Create>MyOption
position
: position in the menu where the option has to be inserted. Note that positions start at 0, and separator lines also count.
command
: is the command called when the menu option is selected.
prepost
: this argument can have the following values: "PRE"
to insert the option in the preprocess menus "POST"
to insert the option in the postprocess menus "PREPOST"
to insert the option in the pre and postprocess menus
insert/replace
: if this argument is insert
the new option is inserted. If the argument is replace
the new option replaces the option of the given position. This argument is optional, and by default the new option replaces the existing one. option_name
: name of the new option you want to insert. If option_name
is "---"
,
then , a separator line is inserted in the menu.
command
: is the command called when the menu option is selected.
position
: position in the menu where the option has to be inserted: an integer
or end
(default) to indicate the last position in the menu. Note that positions
start at 0, and separator lines also count.
accelerator
: Acceleration key combination (default "").
menu_name
: name of the menu which has the option you want to remove.
option_name
: name of the option you want to remove. If you want to remove a submenu or a submenu option, you have to specify the path with ">". Example: Geometry>Create>Point
prepost
: this argument can have the following values: "PRE"
to remove an option of the preprocess menus"POST"
to remove an option of the postprocess menus"PREPOST"
to remove an option of the pre and the postprocess menus
menu_name
and option_name
are case sensitive.CreateMenu
, InsertMenuOption
or RemoveMenuOption
, are done.
EXAMPLE: creating and modifying menus
In this example we create a new menu called "New Menu" and we modify the GiD Help menu:
The code to make these changes would be:
CreateMenu "New Menu" "PRE" InsertMenuOption "New Menu" "Option 1" 0 "Command_1" "PRE" InsertMenuOption "New Menu" "Option 2" 1 "Command_2" "PRE" InsertMenuOption "New Menu" "---" 2 "" "PRE" InsertMenuOption "New Menu" "Option 3" 3 "Command_3" "PRE" InsertMenuOption "Help" "My Help" 1 "" "PRE" "insert" InsertMenuOption "Help" "My Help>My help 1" 0 "Command_help1" "PRE" InsertMenuOption "Help" "My Help>My help 2" 1 "Command_help2" "PRE" RemoveMenuOption "Help" "Customization Help" "PRE" RemoveMenuOption "Help" "What is new ..." "PRE" RemoveMenuOption "Help" "FAQ" "PRE" UpdateMenus
EXAMPLE: removing a submenu or a submenu option
In this example we remove the option Quadrilateral
of the Meshing
menu.
To remove option Quadrilateral
:
RemoveMenuOption "Meshing" "Element type>Quadrilateral" "PRE" UpdateMenus
HTML support |
The problem type developver can take advantage of the internal HTML browser if he wants to provide an online help.
HelpWindow |
html
inside your problem type directoryproblem_type_name
is the name of your problem type with the .gid
extension (for example, cmas2d.gid
).html
folder.
It's a good idea to call the function HelpWindow "CUSTOM_HELP" "problem_type_name" using the menu functions (see section Managing menus).
EXAMPLE: Adding a customized HTML help in the Help menu for the CMAS2D problem type:
InsertMenuOption "Help" \ "Help CMAS2D" 0 {HelpWindow "CUSTOM_HELP" "cmas2d.gid"} "PREPOST" UpdateMenus
GiDCustomHelp |
GiD version |
Normally a problem type requires a minimum version of GiD to run. Because the problem type can be distributed or sold separately from GiD, it's important to check the GiD version before continuing with the execution of the problem type. GiD offers a function, GiDVersionCmp, which compares the version of the GiD which is currently running with a given version.
GiDVersionCmp { Version }
Returns a negative integer if Version
is greater than the currently executed GiD version; zero if the two versions are identical; and a positive integer if Version
is less than the GiD version.
Note: This function will always return a -1 if the GiD version is previous to 6.1.5.
EXAMPLE
proc InitGIDProject { dir } { global GidPriv set VersionRequired "6.2.0b" set comp -1 catch { set comp [GiDVersionCmp $VersionRequired] } if { $comp < 0 } { tk_dialogRAM .gid.tempwinw Warning \ "This interface requires GiD $VersionRequired or later" error 0 OK } }
Using EXEC in GiD |
The TCL language has the exec
command used to invoke a subprocess. This command treats its arguments as the specification of one or more subprocesses to execute. It's possible to invoke a subprocess from GiD using this option.
Example: invoking a process in the background
exec netscape http://www.gidhome.com &
Note: In Windows, instead of &
it's necessary to put >& NUL: &
to run the process in the background. Example: exec PROGRAM_NAME >& NUL: &
Detailed example - TCL-TK extension creation |
Next is an example of the creation of a TCL-TK extension, step by step. In this example we will create the cmas2d.tcl
file, so, we will extend the capabilities of the cmas2d problem type. The file cmas2d.tcl
has to be placed inside the cdmas2d problem type directory.
Note: The cmas2d problem type calculates the center of masses of a 2D surface. This problem type is located inside problemtypes
, in the GiD directory.
In this example, the cmas2d.tcl
creates a window which appears when the problem type is selected.
Window created in the cmas2d.tcl example file
This window gives information about the location, materials and conditions of the problem type. The window has two buttons: the button CONTINUE lets the users continue working with the cmas2d problem type; the button RANDOM SURFACE creates a random 2D surface in the plane XY.
Here starts the TCL code for the example. There are three main procedures in the cmas2d.tcl
file:
proc InitGIDProject {dir } { set materials [.central.s info materials] set conditions [.central.s info conditions ovpnt] CreateWindow $dir $materials $conditions }This is the main procedure. It is executed when the problem type is selected. It calls the CreateWindow procedure.
proc CreateWindow {dir mat cond} { set w .gid.win_example InitWindow $w "CMAS2D.TCL - Example tcl file" ExampleCMAS "" \ "" 1 frame $w.top label $w.top.title_text \ -text " TCL window example for CMAS2D problem type " frame $w.information -relief ridge -bd 2 label $w.information.path \ -text " Problem Type path: $dir " label $w.information.materials \ -text " Avalaible materials: $mat" label $w.information.conditions \ -text " Avalaible conditions: $cond" frame $w.bottom button $w.bottom.start \ -text "CONTINUE" \ -height 1 -width 14 -command "destroy $w" button $w.bottom.random \ -text "RANDOM SURFACE" \ -height 1 -width 20 -command "CreateRandomSurface $w" pack $w.top.title_text -pady 10 pack $w.information.path $w.information.materials \ $w.information.conditions -side top -anchor w pack $w.bottom.start $w.bottom.random \ -side left -anchor center pack $w.top pack $w.information -expand yes -fill both pack $w.bottom -side top -padx 6 -pady 10 -ipady 2 }This procedure creates the window with information about the path, the materials and the conditions of the project. The window has two buttons: if the CONTINUE button is pressed the window is dismissed; if the RANDOM SURFACE button is pressed, it calls the CreateRandomSurface procedure.
proc CreateRandomSurface {w} { set ret [tk_dialogRAM $w.dialog "Warning!!" \ "Warning: this will create a nurbs surface in your \ current project" "" 1 "ok" "cancel"] if {$ret ==0} { Create_surface destroy $w } }This procedure is called when the RANDOM SURFACE button is pressed. Before creating the surface, a dialog asks the user to continue or to cancel the creation of the surface. If the surface has to be created, the Create_surface procedure is called. Then, the window is destroyed.
proc Create_surface {} { set a_x [expr rand()*10] set a_y [expr rand()*10] set b_x [expr $a_x + rand()*10] set b_y [expr $a_y + rand()*10] set c_x [expr $b_x + rand()*10] set c_y [expr $b_y - rand()*10] if {$a_y < $c_y} { set d_y [expr $a_y - rand()*10] set d_x [expr $a_x + rand()*10] } else { set d_y [expr $c_y - rand()*10] set d_x [expr $c_x - rand()*10] } .central.s process escape escape escape escape .central.s process geometry create line \ $a_x,$a_y,0.000000tol0.176991 \ $b_x,$b_y,0.000000tol0.176991 \ $c_x,$c_y,0.000000tol0.176991 \ $d_x,$d_y,0.000000tol0.176991 \ close .central.s process escape escape escape escape .central.s process geometry create NurbsSurface Automatic \ 4 \ escape \ .central.s process zoom frame escape escape escape escape }
A 2D surface (a 4 side 2D polygon) is created. The points of this surface are chosen at random.
Go to the first, previous, next, last section, table of contents.