Go to the first, previous, next, last section, table of contents.


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)...
}

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:



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:



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



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:


Go to the first, previous, next, last section, table of contents.