HMath-5003: HyperMesh-HyperMath Cross Execution of a Tcl Script |
![]() |
![]() |
![]() |
![]() |
|
HMath-5003: HyperMesh-HyperMath Cross Execution of a Tcl Script |
![]() |
![]() |
![]() |
![]() |
HyperMath can be used as a powerful Tcl script editor. In addition to leveraging the capabilities of the HyperMath editor, it offers specific advantages to bridge between HyperMath and the HyperMesh Tcl interpreter. These include:
• | Graphical interaction between HyperMesh and HyperMath |
• | Auto-completion for HyperMesh APIs |
• | Shortcut for direct access to the APIs help topics |
This tutorial demonstrates how to use HyperMath as an editor during HyperMesh Tcl script development and execution.
Step 1: HyperMesh Desktop – Load the model
1. | From the Start menu, select All Programs > Altair HyperWorks (version number) > HyperMesh Desktop. |
2. | From the menu bar, click File > Open > Model. |
3. | From the Open Model dialogue, open the radius.hm model file, located in the hmath folder. The model appears in the graphics area:![]() |
Step 2: Invoke HyperMath in HyperWorks Desktop
1. | From HyperMesh Desktop menu bar, click View > Toolbars > HyperWorks > Scripting to display the scripting toolbar. |
2. | Click New Tcl/Tk script, ![]() |
Note | The Scripting toolbar also exposes two other ways to invoke HyperMath: |
• | Open Tcl/Tk Script prompts you to choose and open an existing Tcl script. The script can then be executed in HyperMath, interacting with HyperMesh. |
• | Debug Tcl/Tk Script allows you to run a Tcl script on a debug model (step by step, breakpoints, watch window). This is described in tutorial Hmath-5004. Also, please see Hmath-1020 for more details about debugging in the HyperMath environment. |
Step 3: Using the HyperMath Tcl editor
1. | Load the script radius.tcl or type the commands shown below in the Tcl editor. This script requires you to choose a line in HyperMesh model. The diameter is computed and the radius of hole is defined by the selected line. A Tk message box displays the results. |
catch {namespace delete ::hml5003_tcldemo} namespace eval ::hml5003_tcldemo {} proc ::hml5003_tcldemo::main {} { *createmarkpanel lines 1 "please select the line" set a [hm_getmark lines 1] set b [llength $a] if {$b == 1} { *createmark lines 1 $a *nodecreateonlines lines 1 3 0 0 *createmark nodes 1 -1 -2 set c [hm_getmark nodes 1] set d1_x [hm_getentityvalue nodes [lindex $c 0] "x" 0] set d1_y [hm_getentityvalue nodes [lindex $c 0] "y" 0] set d1_z [hm_getentityvalue nodes [lindex $c 0] "z" 0] set d2_x [hm_getentityvalue nodes [lindex $c 1] "x" 0] set d2_y [hm_getentityvalue nodes [lindex $c 1] "y" 0] set d2_z [hm_getentityvalue nodes [lindex $c 1] "z" 0] set d_x [expr $d1_x - $d2_x] set d_y [expr $d1_y - $d2_y] set d_z [expr $d1_z - $d2_z] set d [expr sqrt( pow($d_x,2) + pow($d_y,2) + pow($d_z,2))] set e [expr $d/2] tk_messageBox -message "Diameter = $d & Radius = $e " -type ok *nodecleartempmark } else { tk_messageBox -message "Only one line must be selected" -type ok } } ::hml5003_tcldemo::main |
Note | The HyperMath Tcl editor supports auto-completion for HyperMesh APIs. |
For *createmarkpanel, for example, just type *c in the Tcl editor and a list is returned containing all HyperMesh APIs starting with *c characters. In addition, pressing F1 (Help on Selection) on an API displays the help page for this API in an HTML browser.
2. | Click Run File to evaluate the script. In the HyperMesh Desktop window, select a line: |
3. | Choose any hole in the model. The following Tk is displayed, with the diameter and radius of the selected hole. |
4. | If the Tcl script is successful and you want save it, click File > Save or press the Save File icon,![]() |
5. | To easily reuse this script in the HyperMesh Desktop Tcl console, copy the full path by right-clicking the tab in the editor window and selecting Copy Full Path from the context-sensitive menu. |
HMath-1000: Editing, Executing, Saving, and Plotting in HyperMath
HMath-1010: Working with HyperMath Authoring Mode
HMath-1020: Working with HyperMath Debugging Mode
HMath-2000: Working with HyperMath – Arithmetic and Relational Expressions and Control Structures
HMath-2010: Working with HyperMath – Logical and Relational Expressions and Control Structures
HMath-2020: Working with HyperMath – Functions and Matrix Operators
HMath-2030: Working with HyperMath – Plot Commands
HMath-3000: Working with HyperMath – String Library
HMath-3010: Working with HyperMath – Input/Output Library
HMath-3015: Reading Data from Text Files
HMath-3020: Working with HyperMath – Input/Output Library Continued
HMath-3030: Working with HyperMath – Batch Mode
HMath-4000: Using HyperMath Functions for Curve Fitting
HMath-4001: Using HyperMath for Material Characterization
HMath-4010: Solving Ordinary Differential Equations
HMath-4020: Solving Differential Algebraic Equations
HMath-4030: Optimization Algorithms in HyperMath
HMath-5000: Using HyperMath in HyperView Results Math
HMath-5001: Post Processing Results from FEA
HMath-5002: Registering a Function in HyperGraph 2D
HMath-5004: HyperMesh-HyperMath Cross-debugging of a Tcl Script