HM-8040: Create a Macro from a Tcl Script
In this tutorial you will create a Utility menu macro from a Tcl script.
- Determine the commands to save the current HyperMesh model
-
Create a Utility menu macro to execute the commands
- Create a new button on the User page of the Utility menu to run the macro
In order to execute command file commands or Tcl scripts from a button on any of the HyperMesh Utility menu pages, a Utility menu macro must first be defined. A Utility menu macro contains valid command file or templex commands that execute the appropriate operations, and is defined using the *beginmacro and *endmacro commands. Macros may accept data passed to them using the arguments $1, $2, and so on. Each argument specifies where the values should be substituted. These macros are defined within the .mac files, including the userpage.mac file.
*beginmacro(macroname)
command statements go here
*endmacro()
Utility menu macros consist of HyperMesh Tcl modify commands.
Delete the Command File
In this step you will delete the existing command file.
- Locate the existing command.tcl file in the working directory.
- Delete the file.
Perform Operations
In this step you will perform operations in HyperMesh.
Every command issued in HyperMesh appears in the order executed and is reflected in the command file.
- From the menu bar, select .
- Using the File Browser, locate a directory to save the temporary file with the name temp.hm.
- Click Save.
Extract Commands
In this step you will extract the commands from the command file.
- Open the command file using any text editor.
- Locate the *writefile command at or near the end of the command file. This is the command that writes the model file.
- Select and copy this line.
Create a Script and Convert Commands
In this step you will create a Tcl script named savefile.tcl and convert the commands to tcl format.
Create a Macro to Run a Script
In this step you will create a Utility menu macro that runs a Tcl script.
Add the Macro Button
In this step you will add the macro button to the User page.
Reload the Command File
In this step you will reload the current .mac file to load the modified userpage.mac.
Make sure to load the proper .mac file from the hm\scripts\<profile name> directory based on the current user profile, or load the default hm.mac in hm\bin\<platform> if no user profile is loaded.
Test the Macro
In this step you will test the macro.