HM-8010: Add a Button

In this exercise, you will create a button on the User page that will launch the lighting.tcl dialog from the HyperMesh installation.

Command files and Tcl/Tk scripts can be added to the userpage.mac file. When HyperMesh starts, it first looks for the userpage.mac file in the directory from which it launches, and then in the installation directory. Unix users also have the option of putting the userpage.mac file in their home directory.

The userpage.mac file controls the display and available operations on the User page of the HyperMesh Utility menu. In order to invoke a command file or Tcl/Tk script from the User page, a button must be defined inside the userpage.mac file. The *createbutton command is used to define the button and its characteristics. The syntax for this command is:
*createbutton(page, name, row,
        column, width, COLOR, helpString, macroName [ , arg1 … ])
where:
Table 1.
Item Description
page The page number on which the button is to appear. For the User page, this value is 5.
name The text to display on the button, enclosed in quotes: " ".
row The row in which to place the button. The number of visible rows depends on your monitor’s graphics resolution. A positive value indicates an absolute row number. A 0 indicates the next highest available row. A negative value indicates the number of rows to skip. Rows begin at the bottom of the menu.
column The column where the button starts (0-10). Columns begin to the right of the menu.
width The width of the button (max = 10).
COLOR The color of the button. The available button colors are: RED, BLUE, GREEN, CYAN, MAGENTA, YELLOW, GRAY, and BUTTON (background). The color name must appear in capital letters.
helpString The string to be displayed in the menu bar when the middle mouse button is pressed and the button is clicked, enclosed in quotes: " ".
macroName The command to run when the button is pressed, enclosed in quotes: " ".
arg1... A list of optional arguments passed to the script.

Create the File

In this step you will create a file called userpage.mac.

Using a text editor of your choice, create a blank file in the appropriate directory and save it as userpage.mac.

When HyperMesh starts, it first looks for the userpage.mac file in the directory from which it launches and then in the installation directory. On Windows, the default launch directory is in the My Documents folder. Unix users also have the option of putting the userpage.mac file in their home directory. It is not recommended to modify the userpage.mac file in the installation directory.

Add the Command to Create a Button

In this step you will add the command to create a button.

  1. Add the following text to the userpage.mac file:
    *createbutton(5,"Lighting",10,5,5,YELLOW,
    "Launch the lighting.tcl script","EvalTcl","lighting.tcl")
    The EvalTcl macro is defined in the globalpage.mac file in the HyperMesh installation. It takes a Tcl script as its argument and executes the script.

    Notice that the full path is not used to reference the lighting.tcl script. A full path can be specified if the file is not located in one of the predefined paths that HyperMesh searches to find scripts. You can add additional search paths using the TCL_INCLUDE environment variable. Relative paths can also be used from these search paths.

  2. Save the modified userpage.mac file.

Load the Updated File

In this step you will load the updated userpage.mac file.

  1. Restart HyperMesh from the working directory or reload the current macro menu .mac file. This allows the current session to use the modified userpage.mac file.
    To reload the current macro menu .mac file while HyperMesh is open, from the menu bar select Preferences > Menu Config and click on retrieve next to macro file.
  2. Click the User button on the Utility menu.
    You will see Lighting, the button defined in Step 2. Compare this button to its definition. It is yellow in color, begins in column 5 of row 10, and extends half way across the Utility menu.