HM-8020: Create a Utility Menu Macro
In this tutorial, you will create a Utility menu macro from a command file.
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.
Define the Task
In this step you will define the task.
The first step in creating a macro is to define the process you want to automate and recognize the individual tasks to reach the desired conclusion. Here, you want to create a one-button macro to automate saving the current HyperMesh model to a file named temp.hm.
- From the menu bar, select
- Use the File Browser to locate a directory and type the filename.
- Click Save.
Delete the Existing Command File
In this step you will delete the existing command file.
The command file is located in the current working directory. When first opening HyperMesh, the file is created in the directory HyperMesh is launched from. As soon as you begin working in HyperMesh all executed commands are written to the command file. If the file already exists, the commands are appended to the file. Deleting the file allows HyperMesh to create a new file and allows the user to easily find the relevant commands.
- Locate the existing command.tcl file in the working directory.
- Delete the file.
Perform Operations
In this step you will execute the full process within HyperMesh.
Every command issued in HyperMesh appears in the order executed and is reflected in the command file.
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 file. This is the command that writes the model file.
- Select and copy the line.
Add Commands
In this step you will add the commands to the file, userpage.mac.
- Open the userpage.mac file using any text editor.
- Paste the *writefile command copied from the command file inside the userpage.mac file.
Modify Commands
In this step you will modify commands as necessary and add Utility menu macro wrapper commands.
Add the Macro Button
In this step you will create a button on the User page to execute the macro.
Reload the File
In this step you will reload the current .mac file into HyperMesh to load the modified userpage.mac.
Test the Macro
In this step you will test the macro.