Académique Documents
Professionnel Documents
Culture Documents
Chapter 4
HyperWorks 12.0
Introduction to HM Customization 47
Proprietary Information of Altair Engineering, Inc
Tcl Script
Not used in Tcl
*setbackgroundcolor 255 255 255
*setmeshlinecolor 6
*jpegfile
*setbackgroundcolor 0 0 0
*setmeshlinecolor 0
Not used in Tcl
Notice that while the parentheses and commas have been removed, each of the
commands still begin with an asterisk (*) and that the command name hasnt
changed. In addition to the syntax change, Tcl core commands can also be used
(these are the commands presented in Chapter 1). The addition of the Tcl
commands provides added functionality to the macros.
HyperWorks 12.0
This command can be used with the set Tcl command to assign the string
entered in the panel to a variable:
set loadname [hm_getstring Load collector name Enter
name for load collector]
In addition to getting a string, the hm_getint and hm_getfloat commands
can be used to get values by posting a panel in the HyperMesh panel area. The
hm_getint command returns a user input integer value while hm_getfloat
returns a user input floating point value. Both these commands have the same
options as the hm_getstring command. As an example, lets assign a floating
point value to a variable called force:
set force [hm_getfloat Force Enter force value]
With the addition of the HyperMesh Tcl commands, there are a few commands
which replace the HyperMesh Modify commands. Specifically there are the
hm_createmark and hm_clearmark commands. These commands perform
the same functionality as the *createmark and *clearmark commands, but
they are the HyperMesh Tcl equivalent. The advantage of using these
commands is that it avoids situations where additional Tcl commands need to be
used to evaluate the HyperMesh command. Using hm_createmark and
hm_clearmark when writing Tcl scripts is the more efficient and recommended
method.
HyperWorks 12.0
Introduction to HM Customization 49
Proprietary Information of Altair Engineering, Inc
The following table contains a list of the commonly used HyperMesh Tcl
commands as well as a short description of that command. For a full explanation
of the commands, please refer to the Reference Guide in the HyperWorks help.
HyperWorks 12.0
In the Command Window, users can evaluate any command that can be issued
in Tcl or in HyperMesh through Tcl. Lets examine a few commands. General
Unix command such as ls, pwd, and cd can be used within the Command
Window. The ls command will return the directory contents, the pwd command
will return the current working directory, and the cd command allows users to
change directories.
In addition to general UNIX commands, general and HyperMesh specific Tcl
commands can be entered. For example, lets use the HyperMesh specific Tcl
command hm_info with the following options:
hm_info appinfo SPECIFIEDPATH TEMPLATES_DIR
The above command with the provided options will return the current template
directory. Any command that can be issued in Tcl or in HyperMesh through the
Tcl command layer can be entered at the Command Window prompt and it will
be evaluated. This capability provides the automation tool developer an easy
means of testing a concept before writing the full procedure.
The Command Window also provides the ability to run Tcl scripts by either using
the source command or using the File/Load Menu option. When using the
source command, the complete path and filename needs to be given (unless
the file is located in the directory the user is currently in within the Command
Window).
source C:/temp/my_macro.tcl
The other option is to use the File/Load Menu. This menu is available in the
Command Window by right clicking in the Command Window (shown below).
You can also save the session contents in the Command Window using the
File/Save Menu option.
HyperWorks 12.0
Introduction to HM Customization 51
Proprietary Information of Altair Engineering, Inc
Tcl scripts can also be run in HyperMesh by creating a button on the Utility
menu User page. As was shown in Chapter 2, when creating a button for a Tcl
script, the EvalTcl basic macro will need to be referenced in the
*createbutton() command. In the examples and exercises following, we will
be using this macro to add buttons to the User page for the Tcl scripts that will be
written.
Introduction to HM Customization 52
Proprietary Information of Altair Engineering, Inc.
HyperWorks 12.0
Step 3: Run HyperMesh Tcl and core Tcl commands from the
Command Window
1. Run the command set a [list 1 2 3 4 5]
A Tcl list variable named a is created and values 1-5 are added to this
list.
2. Run the command set a_length [llength $a]
The length of the list a is set to the variable a_length.
Step 6: Retrieve the element ids from the mark and store them
in a Tcl list variable.
In order to get the elements ids stored in the mark, the hm_getmark command is
used. This command returns the entity IDs of the passed entity type from the
specified mark In the Command Window, type the following:
set elemIds [hm_getmark elems 1]
Step 7: Count the number of elements in the list and display the
result
By using the llength Tcl command, the number of entities in the list elemIds
can be found.
HyperWorks 12.0
Introduction to HM Customization 53
Proprietary Information of Altair Engineering, Inc
HyperWorks 12.0
Introduction to HM Customization 55
Proprietary Information of Altair Engineering, Inc
HyperWorks 12.0
1. Open a text editor and create a new text file named create_force.tcl.
Save the file to your HyperMesh working directory (My Documents on
Windows).
2. From your HyperMesh working directory, open the command.cmf file.
3. Locate the following four commands at or near the end of the file.
*collectorcreateonly(loadcols, forces, , 7)
*loadsize(1,15,0,1)
*createmark(nodes,1) 3237
*loadcreateonentity(nodes,1,1,1,0,0,23,0,0,23,0,0,0,0,0)
4. Copy these commands and add them to the text file create_force.tcl
Introduction to HM Customization 57
Proprietary Information of Altair Engineering, Inc
2. Substitute the hard coded force magnitude with the variable mag_val.
*loadcreateonentity nodes 1 1 1 0 0 $mag_val 0 0 $mag_val 0 0 0 0 0
Step 11: Test the script by running it from the command window
1. Go to the currently open HyperMesh session.
2. Open the file c_channel-tcl_vector.hm.
This refreshes the HyperMesh database. The load collector and forces
you created earlier no longer exist.
3. Go to the View menu and select Command Window.
4. In the Command Window, type the following and then press Enter:
source create_force.tcl
A HyperMesh panel with a nodes selector appears.
5. Select node(s) in any manner you wish.
6. Click proceed to continue the scripts task.
A HyperMesh panel with an input field for the force magnitude appears.
7. For Magnitude =, type any number.
8. Click proceed to continue the scripts task.
The force(s) are created.
HyperWorks 12.0
Step 13: Load the userpage.mac file into the current HyperMesh
session.
The userpage.mac file can be loaded into the current HyperMesh session in a
couple of ways. By changing the User Profile the userpage.mac file gets
reloaded. While this method works, if you dont want to change the user profile,
another method is to simply reload the hm.mac file or to simply close and reopen
HyperMesh.
1. Close HyperMesh and then reopen HyperMesh.
Step 14: Test the script from the Utility menus button.
1. Open the file c_channel-tcl_vector.hm.
2. In the Utility tabs User page, click the Create Force button. A
HyperMesh panel with a nodes selector appears.
3. Select node(s) in any manner you wish.
4. Click proceed to continue the scripts task.
A HyperMesh panel with an input field for the force magnitude appears.
5. For Magnitude =, type any number.
6. Click proceed to continue the scripts task.
The force(s) are created.
HyperWorks 12.0
Introduction to HM Customization 59
Proprietary Information of Altair Engineering, Inc
Practical Exercises
Exercise 4a
Description
Using the file c_channel-tcl_vector.hm, create a HyperMesh Tcl script to
automate the following task
1) Create a component collector with a user specified name
2) Select elements and move those elements into the new component
collector.
3) Translate the elements in the new component collector a user
specified distance in the z direction.
Writing this script will make you more familiar with the general process for
creating HyperMesh Tcl scripts.
HyperMesh commands used
hm_getstring
*createmarkpanel
*clearmark
hm_getfloat
*collectorcreateonly
*movemark
*createvector
*translatemark
Introduction to HM Customization 60
Proprietary Information of Altair Engineering, Inc.
HyperWorks 12.0
Exercise 4b
Description
Using the file c_channel-tcl_vector.hm, for each element in the HyperMesh
model, build a list where the contents of the list are as follows
ELEMID {NODE1 NODE2 }
These lists should then be included in a list of lists:
{{ELEMID1 {NODE1 NODE2 } {ELEMID2 {NODE1 NODE2 }
Thus generating a record of the element information. No means of reporting this
to the user is necessary for this exercise
HyperMesh commands used
*createmark
hm_nodelist
hm_getmark
foreach
lappend
incr
elseif
Hints
The majority of this assignment will be discovering where to find information
about commands and how to apply the information you find. Be patient and use
the resources available to you, including the HyperWorks online help.
HyperWorks 12.0
Introduction to HM Customization 61
Proprietary Information of Altair Engineering, Inc
Introduction to HM Customization 62
Proprietary Information of Altair Engineering, Inc.
HyperWorks 12.0