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

- InitGIDProject: will be called when the problem type is selected. It receives the `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.
- InitGIDPostProcess: will be called when the postprocess starts. It has no arguments.
- EndGIDProject: will be called when this project is about to be closed. It has no arguments.
- EndGIDPostProcess: will be called when the user leaves postprocess and opens preprocess. It has no arguments.
- LoadGIDProject: will be called when a GiD project is loaded. It receives the `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.
- SaveGIDProject: will be called when the current opened file is saved to disk. It receives the `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.
- LoadResultsGIDPostProcess: will be called when a results file is opened in the postprocess. It receives one argument, the name of the file being opened without its extension.
- BeforeMeshGeneration: will be called before the mesh generation. It receives as argument 'elementsize' the user desired mesh size. This event can be used tipically to automatically assign some condition.
- AfterMeshGeneration: will be called after the mesh generation. It receives as argument 'fail' a true value if the mesh is not created.
- SelectGIDBatFile: Must be used to switch the default bat file for special cases. This procedure must return the alternative pathname of the bat file. For example must be used as a trick to select a different analysis between a list of bat calculation files.
- ChangedLanguage: will be called when the user change the current language. The argument is the new language (en, es, ...). Must be used, for example, to update problemtype customized menus, etc.

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:

- .central.s process command_1 command_2 ...: used to execute GiD commands
- .central.s info option: used to obtain information about the actual GiD project

### 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
  This command returns a list of the materials of the project.

  Also these options are avalaible:
  - ["material_name"]: If a material name is given, its properties are returned. If the material name is given it's also possible to add the option [OTHERFIELDS] to get the fields of that material, or the option [BOOK], to get the book of that material.
  - [BOOKS]: If this option is given, a list of the material books of the project is returned.

    Examples:
    in: `.central.s info materials`
    out: `"Air Steel Aluminium Concrete Water Sand"`
    in: `.central.s info materials Steel`
    out: `"1 Density 7850"`

- .central.s info conditions ovpnt | ovline | ovsurf | ovvol
  This command returns a list of the conditions in the project. Argument ovpnt, ovline, ovsurf, ovvol must be given to indicate the type of condition: condition over points, lines, surfaces or volumes.

  Instead of ovpnt, ovline, ovsurf, ovvol, the following options are also avalaible:
  - [-interval "intv"] [-localaxes | -localaxesmat | -localaxescenter | -localaxesmatcenter ] "condition_name" [geometry | mesh]: if a condition name is given, the command returns the properties of that condition.
    If the condition name is given, it's also possible to add the option geometry or mesh, and all mesh or geometry entities that have this condition assigned, will be returned.
    If -interval "intv" is set, then are returned the contitions on this interval ("intv"=1,...n) instead the current interval.
    If -localaxes is set, then also are returned three numbers that are the 3 Euler angles that define a local axes system (only for conditions with local axes, See section Local axes). Selecting -localaxesmat are returned the nine numbers that define the transformation matrix of a vector from the local axes system to the global one.
    If -localaxescenter is set, then also are returned the three Euler angles and the local axis center.
    Selecting -localaxesmatcenter are returned the nine matrix numbers and the center.
    Adding the number id of an entity ( ["entity_id"] ) after the options mesh or geometry, the command returns the value of the condition assigned to that entity.
    Other options avalaible if the condition name is given are [OTHERFIELD], to get the fields of that condition, and [BOOK], to get the book of the condition.
  - [BOOKS]: If this option is given, a list of the condition books of the project is returned.

    Examples:
    in: `.central.s info conditions ovpnt`
    out: `"Point-Weight Point-Load"`
    in: `.central.s info conditions Point-Weight`
    out: `"ovpnt 1 Weight 0"`
    in: `.central.s info conditions Point-Weight geometry`
    out: `"E 1 - 2334 , E 2 - 2334 , E 3 - 343"`
    in: `.central.s info Conditions -localaxes Concrete_rec_section mesh 2`
    out: `{E 2 - {4.7123889803846897 1.5707963267948966 0.0} N-m 0.3 0.3 HA-25}`

- .central.s info layers
  This command returns a list of the layers of the project.

  Also these options are avalaible:
  - ["layer_name"]: If a layer name is given, the command returns the properties of that layer.
  - [-on]: returns a list of the visible layers.
  - [-off]: returns a list of the hidden layers.
  - [-hasbacklayers]: returns 1 if the project have entities inside back layers. .central.s info back_layers returns a list with the back layers
    Example:
    in: `.central.s info back_layers`
    out: `Layer2_*back*`
  - [-bbox[-use geometry|mesh] ]: layer_name_1 layer_name_2 ...]: returns two coordinates (x1,y1,z1,x2,y2,z2) which define the bounding box of the entities that belong to the list of layers. If the option [-use geometry|mesh] is used, the command returns the bounding box of the geometry or the bounding box of the mesh. If the list of layers is empty, the maximum bounding box is returned.
  - [-entities]: One of the following arguments must be given: nodes, elements, points, lines, surfaces or volumes.A layer name must also be given. The command will return the nodes, elements, points, lines surfaces or volumes of that layer.

    Examples:
    in: `.central.s info layers`
    out: `"layer1 layer2 layer_aux"`
    in: `.central.s info layers -on`
    out: `"layer1 layer2"`
    in: `.central.s info layers -entities lines layer2`
    out: `"6 7 8 9"`

- .central.s info gendata
  This command returns the information entered in the Problem Data window (see section Problem and intervals data file (.prb)).
  The following options are avalaible:
  - [OTHERFIELDS]: it is possible to add this option to get the additional fields of the Problem Data window.
  - [BOOKS]: If this option is given, a list of the Problem Data books of the project is returned.
    Example:
    in: `.central.s info gendata`
    out: `"2 Unit_System#CB#(SI,CGS,User) SI Title M_title"`

- .central.s info intvdata
  This command returns a list of the interval data in the project (see section Problem and intervals data file (.prb)).
  The following options are avalaible:
  - [OTHERFIELDS]: it is possible to add this option to get the additional fields of the Interval Data window.
  - [BOOKS]: If this option is given, a list of the Interval Data books of the project is returned.
  - [NUM]: if this option is given, a list of two naturals is returned. The first element of the list is the current interval and the second element is the total number of intervals.

- .central.s info Project
  This command returns information about the project. More precisely, it is returned a list with:
  - Problem type name.
  - Current example name.
  - 'There are changes' flag.
  - Current layer.
  - Active part (GEOMETRYUSE,MESHUSE,POSTUSE or GRAFUSE).
  - Quadratic problem flag.
  - Drawing type (normal,polygons,render,postprocess).
  - NOPOST or YESPOST
  - debug or nodebug
  - GiD temporary directory.
  - Geometry changes since the mesh was created (0 or 1).
  - Last size of element used for meshing (`NONE` if there's no mesh).

    Example:
    in: `.central.s info Project`
    out: `"cmas2d e:\models\car_model 1 layer3 MESHUSE 0 normal YESPOST nodebug C:\TEMP\gid2 0 1.4"`

- .central.s info Mesh
  This command gives to the user information about the selected mesh in the project. It returns a `1` followed by a list with all types of element used in the mesh.
  The following two options are avalaible:
  - [MaxNumElements]: returns the total number of elements of the mesh.
  - [MaxNumNodes]: returns the total number of nodes of the mesh.
  - [Elements Elemtype[First_id Last_id]]: returns a list with the element number, the connectivities and the material number, from 'first_id' to 'last_id, if they are specified. Elemtype can be: Linear/Triangle/Quadrilateral/Tetrahedra/Hexahedra/Prisma.
  - [Nodes[First_id Last_id]]: returns a list with the node number and x y z coordinates, from 'first_id' to 'last_id', if they are specified.

    Examples:
    in: `.central.s info Mesh`
    out: `"1 Tetrahedra Triangle"`
    in: `.central.s info Mesh MaxNumNodes`
    out: `"1623"`

- .central.s info Coordinates point_id/node_id [geometry|mesh]
  This command returns the coordinates (x,y,z) of the given point or node.

- .central.s info variables "variable_name"
  This command returns the value of the variable indicated. GiD variables can be found through the right buttons menu (see section Graphical), under the option utilities > variables.

- .central.s info localaxes ?<name>? ?-localaxesmat?
  info localaxes returns a list with all the user defined local axes.
  info localaxes <name> returns the parameters (3 euler angles and the center} that define the local axes named <name>.
  info localaxes <name> -localaxesmat instead to return the 3 euler angles, are returned the nine numbers that define the transformation matrix of a vector from the local axes system to the global one.

- .central.s info ortholimits
  This command returns a list of the limits of the geometry in the project.

- .central.s info perspectivefactor
  This command returns which perspective factor is being currently used in the project.

- .central.s info graphcenter
  This command returns the coordinates (x,y,z) of the center of rotation.

- .central.s info MeshQuality
  This command returns a list of numbers. These naturals are the Y relative values of the graph showed in the option Meshing > Mesh quality (see section Mesh quality).

  This command has the following arguments:
  - MinAngle/MaxAngle: quality criteria.
  - Linear/Triangle/Tetrahedra/Quadrilateral Hexahedra/Prisma: type of element
  - "min_degrees": number of minimum degrees accepted.
  - "max_degrees": number of maximum degrees accepted.
  - "num_divisions": number of divisions.

    Example:
    in: `.central.s info MeshQuality MinAngle Triangle 20 60 4`
    out: `"13 34 23 0"`

- .central.s info postprocess arewein
  This command returns `YES` if the user is in the GiD postprocess, and `NO`, if the user is not.

- .central.s info postprocess get
  This command returns information about the GiD postprocess. The following options are avalaible:
  - all_volumes: returns a list of all volumes.
  - all_surfaces: returns a list of all surfaces.
  - all_cuts: returns a list of all cuts.
  - all_graphs: returns a list of all graphs.
  - all_volumes_colors: returns a list of the volume colors used in the project. Colors are represented in RGB in hexadecimal format. Example: `#000000` would be black, and `#FFFFFF` would be white.
  - all_surfaces_colors: returns a list of the surface colors used in the project. Colors are represented in RGB in hexadecimal format. Example: `#000000` would be black, and `#FFFFFF` would be white.
  - all_cuts_colors :returns a list of the cut colors used in the project. Colors are represented in RGB in hexadecimal format. Example: `#000000` would be black, and `#FFFFFF` would be white.
  - cur_volumes: returns a list of the visible volumes.
  - cur_surfaces: returns a list of the visible surfaces.
  - cur_cuts: returns a list of the visible cuts.
  - all_display_styles: returns a list of all types of display styles avalaible.
  - cur_display_style: returns the current display style.
  - all_display_renders: returns a list of all types of render avalaible.
  - cur_display_render: returns the current rendering method.
  - all_display_culling: returns a list of all types of culling avalaible.
  - cur_display_culling: returns the current culling visualization.
  - cur_display_transparence: returns `Opaque` or `Transparent` depending on the current transparency. Transparency is chosen by the user in the Select & Display Style window.
  - cur_display_body_type: returns `Massive` if the option Massive of the window Select & Display Style is selected. It returns `Hollow` if that option is not activated.
  - all_analisis: returns a list of all analisis in the project.
  - all_steps "analisis_name": returns the number of steps of "analisis_name".
  - cur_analisis: returns the name of the current analisis.
  - cur_step: returns the current step.
  - all_results_views: returns all avalaible result views.
  - cur_results_view: retuns the current result view.
  - cur_results_list: this option has one more argument: the kind of result visualization must be given. The avalaible kinds of result visualization are given by the option all_results_views. The comand returns a list of all the results that can be represented with that visualization in the current step of the current analysis.
  - results_list: this option has three arguments: the first argument is the kind of result visualization. The avalaible kinds of result visualization are given by the option all_results_views. The second argument the analysis name. The third argument is the number of step. The comand returns a list of all the results that can be represented with that visualization in the given step.
  - cur_result: returns the current selected result. The kind of result is selected by the user in the View results window.
  - cur_components_list "result_name": returns a list of all the components of the result "result_name".
  - cur_component: returns the current component of the current result.
  - main_geom_state: returns if the main geometry is `Deformed` or `Original`
  - main_geom_all_deform: returns a list of all the deformation variables (vectors) of the main geometry.
  - main_geom_cur_deform: returns the current deformation variable (vectors) of the main geometry.
  - main_geom_cur_step: returns the main geometry current step.
  - main_geom_cur_anal: returns the main geometry current analysis.
  - main_geom_cur_factor: returns the main geometry current deformation factor.
  - show_geom_state: returns if the reference geometry is `Deformed` or `Original`.
  - show_geom_cur_deform: returns the current deformation variable (vectors) of the reference geometry.
  - show_geom_cur_analisis: returns the reference geometry current analysis.
  - show_geom_cur_step: returns the reference geometry current step.
  - iso_all_display_styles: returns a list of all avalaible display styles for iso surfaces.
  - iso_cur_display_style: returns the current display style for iso surfaces.
  - iso_all_display_renders: returns a list of all types of render avalaible for iso surfaces.
  - iso_cur_display_render: returns the current rendering method for iso surfaces.
  - iso_cur_display_transparence: returns Opaque or Transparent depending on the current transparency of iso surfaces.
  - contour_limits: returns the minimum and maximum value of the contour limits. Before each value, the word `STD` appears if the contour limit value is the default value, and `USER`, if it's defined by the user.
  - animationformat: returns the default animation format.
  - cur_show_conditions: returns the option selected in the Conditions combo box of the Select & Display Style window. (Possible values: `Geometry Mesh None`)
  - all_show_conditions: returns all the options avalaible in the Conditions combo box of the Select & Display Style window. (`Geometry Mesh None`)
  - cur_contour_limits: returns the minimum and maximum value of the current value.
  - current_color_scale: returns a list of the colors used for the color scale; the first element of the list is the number of colors. Each color is represented in RGB in hexadecimal format. Example: `#000000` would be black, and `#FFFFFF` would be white.

- .central.s info AutomaticTolerance
  This command returns the value of the Import Tolerance used in the project. This value is defined in the Preferences window under Import.

- .central.s info RGBDefaultBackground
  This command returns the default background color in RGB. The format is three 8 bit numbers separated by #. Example: `255#255#255` would be white.

- .central.s info list_entities status
  This command returns a list with general information about the current GiD project.

  Example:
  in: `.central.s info list_entities status`
  out:
  `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%`

- .central.s info list_entities
  This command returns information about entities.
  It has the following arguments:
  - Points/Lines/Surfaces/Volumes/Nodes/Elements/Results: type of entity or Results. Note: if the user is postprocessing in GiD, the information returned by Nodes/Elements is the relative to the nodes and elements in postprocess, including its results information. To access the preprocess information about the preprocess mesh the following entities keywords should be used PreNodes/PreElements.
  - entity_id: number of entity. It is also possible to enter a list of entities (example: `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`).
  Using "list_entities Results" must also specify <analysis_name> <step> <result_name> <indexes>
  With option -more returns more information about the entity. Option -more used with lines, returns the length of the line, its radius (arcs), and the list of surfaces which are higuer entities of that line; used with elements, it returns the type of element, its number of nodes and its volume.

  Example 1:
  in: `.central.s info list_entities Points 2 1`
  out:
  `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`

  Example 2:
  in: `.central.s info list_entities lines layer:car_lines`
  out:
  `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`

  Example 3 (using -more):
  in: `.central.s info list_entities -more Lines 2`
  out:
  `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
  This command returns geometric information (coordinates, derivates, etc.) about parametric lines or surfaces.
  For lines it has the following syntax:
  .central.s info parametric line entity_id coord|deriv_t|deriv_tt|t_fromcoord t|x y z
  And for surfaces:
  .central.s info parametric surface entity_id coord|deriv_u|deriv_v|deriv_uu|deriv_vv|deriv_uv|normal|uv_fromcoord u v|x y z
  The result for each argument is:
  - line|surface: type of entity.
  - entity_id: number of entity.
  - coord: 3D coordinate of the point with parameter t (line) or u,v (surface).
  - deriv_t: first curve derivative at parameter t.
  - deriv_tt: second curve derivative at parameter t.
  - t_fromcoord: t parameter for a 3D point.
  - deriv_u,deriv_v: first partial u or v surface derivatives.
  - deriv_uu,deriv_vv,deriv_uv: second surface partial derivatives.
  - normal: unitary surface normal at u,v parameters.
  - uv_fromcoord: u,v space parameters for a 3D point.
  Note: the vector derivatives are not normalized.

  Example:
  in: `.central.s info parametric line 26 deriv_t 0.25`
  out: `8.060864 -1.463980 0.000000`

- .central.s info ListMassProperties
  This command returns properties of the selected entities. It returns the length if entities are lines, area, if surfaces, volume if volumes, or the gravity center if entities are nodes or elements.
  It has the following arguments:
  - Points/Lines/Surfaces/Volumes/Nodes/Elements: type of entity. entity_id: number of entity. It is also possible to enter a list of entities (example: `2 3 6 45`) a range of entities (example: entities from 3 to 45, would be `3:45`).

    Example:
    in: `.central.s info ListMassProperties Lines 13 15`
    out:
    `LINES
    n. Length
    13 9.876855
    15 9.913899
    Selected 2 figures
    ________________________
    Total Length=19.790754`

- .central.s info problemtypepath
  This command returns the absolute path to the current Problem Type.

- .central.s info GiDVersion
  This command returns the GiD version number. For example 6.2.0b.

### 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

- <basename> only required for create, is the name of material from with derive
- <name> is the name of material
- <values> list of all field values for the new material

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

- <name> is the name of the material or condition
- <over> must be: points lines surfaces volumes layers nodes elements body_elements face_elements (elements is equivalent to body_elements)
- <newvalues> only requiered for conditions, if set to "" then are used the default values
- <entities> a list of entities (is valid to use ranges as a:b) (if <over> is face_elements then must specify a list of "entity numface" instead only "entity")

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

- <name> is the material name or interval number
- <values> list of all the new field values for the material, 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

- <name> is the material, condition name or interval number (unneeded for gendata)
- <question> field name
- <attribute> attribute name to change (STATE, HELP, etc.) instead of the field value.
- <value> new field or attribute value

Example:

    GiD_AccessValue set gendat Solver Direct

GiD_IntervalData <mode> <number>|?copyconditions?
To create, delete or set a interval data

- <mode> must be 'create', 'delete' or 'set'
- <number> is the interval number (integer >=1)
  For create mode, instead a <number> can optionally set 'copyconditions'
  For set mode, if <number> is not supplied, then the current interval number is returned.

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.

- <mode>: "create|delete|edit|exists". Operation to make: create, delete edit or exists
- <name>: is the name of local axes to create or delete
- <type>: "rectangular|cylindrical|spherical C_XZ_Z||C_XY_X". At this moment, GiD only supports rectangular axes
  C_XZ_Z is an optional word to specify a point over the XZ plane and other over the Z axe (default)
  C_XY_X is an optional word to specify a point over the XY plane and other over the X axe
- <Cx Cy Cz> tcl list with the point real coordinates of local axes origin
- <PAxex PAxey PAxez> tcl list with the coordinates of a point located over the Z' local axes (with Z' positive). The coordinates must be space separated. If the z coordinate is missing, then it's set to z=0.0
- <PPlanex PPlaney PPlanez> tcl list with the coordinates of a point located over the Z'X'half-plane (with X' positive)

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.

- <num>|append: <num> is the identifier (integer > 0) for the node or element. Can use the word 'append' to automatically set a new number.
- <elemtype>: "onlypoints|linear|triangle|quadrilateral|tetrahedra|hexahedra|prism". Element type
- <N1 ... Nnnode> tcl list with the element connectivities
- <mat> optional element material name
- <x y z> node coordinates. If the z coordinate is missing, then it's set to z=0.0

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:

- CreateMenu {new_menu_name prepost}
  Creates a new menu. New menus are inserted between the Calculate and Help menu.
  - `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
    or `"PREPOST"` to create the menu in the pre and postprocess
- InsertMenuOption {menu_name option_name position command prepost [insert/replace] }
  Creates a new option for a given menu in a given position (positions start at 0). By default, if it already exists an option in the given position, that option is substitued by the new one. If the `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 ">".
    Example: `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
    or `"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.
- GidAddUserDataOptions {option_name command position accelerator}
  Add a new entry to the data menu of GiD (this menu is special, it change loading a problem type).
  - `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 "").
- RemoveMenuOption {menu_name option_name prepost}
  Removes an option of a given menu.
  - `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
    or `"PREPOST"` to remove an option of the pre and the postprocess menus
  Note: `menu_name` and `option_name` are case sensitive.
- UpdateMenus {}
  Updates changes made on menus. This function must be called when all calls to `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

1 - Create a directory named `html` inside your problem type directory
2 - Call HelpWindow "CUSTOM_HELP" "problem_type_name", where `problem_type_name` is the name of your problem type with the `.gid` extension (for example, `cmas2d.gid`).
3 - Function HelpWindow opens the file "index.html" which must be inside the `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}

      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}

      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}

      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.