HM-8050: Create Forces on Nodes

In this tutorial you will create forces on nodes and add a button on the User page.

You will:
  • Determine the commands to create forces on nodes
  • 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.

The following skeleton code shows the format of a Utility menu macro:
*beginmacro(macroname)
            command statements go here
        *endmacro()

Utility menu macros consist of HyperMesh Tcl modify commands.

Load collectors can be created and edited using the Model Browser. Simply right-click in the Model Browser and select Create > Load Collector to create one. To edit the name, color, or card image of a load collector, right -lick on the load collector name in the Model Browser and select Edit.

The Forces panel can be accessed from the menu bar by selecting BCs > Create Forces.

The Forces panel allows you to create and update forces.


Figure 1.

Delete Existing Command File

In this step you will delete the existing command file.

  1. Navigate to the current working directory and locate the file, command.tcl.
  2. Delete the file.

Perform Operations

In this step you will perform operations.

Every command issued in HyperMesh appears in the order executed and is reflected in the command file.

  1. From the menu bar, select File > Open > Model and then load the file, c_channel-tcl.hm.
  2. Right-click in the Model Browser and select Create > Load Collector.
  3. In the name field, type forces.
  4. Click Create.
  5. Open the Forces panel.
  6. Activate the create subpanel.
  7. Click nodes and select one node in the model.
    1. For the direction of the force, choose the z-axis option.
    2. For magnitude=, type 23.
    3. Toggle from magnitude % option to uniform size option for load size and set the value to 15.
  8. Click create.

Extract Commands

In this step you will extract the commands from the command file.

  1. Open the command file using any text editor, or use the Open Command File option on the Scripting toolbar.
  2. Select and copy the following three lines into the file:
    *loadsize(1,15,0,1)
    *createmark(nodes,1) 3237
    *loadcreateonentity_curve(nodes,1,1,1,0,0,23,0,0,23,0,0,0,0,0)

    Observe the *createmark command and the list of entity id numbers. A mark is a storage buffer in HyperMesh. For some actions performed on entities, the entity ID is first entered into the designated mark.

    There are two marks available to the user (1 and 2) for each entity type (elements, nodes, lines, surfaces, points, and so on). At the execution of the command using the mark, the changes apply to all entities identified in the mark.

Create a Tcl Script

In this step you will create a Tcl script named create_force.tcl, convert the commands to Tcl format, and modify as necessary.

  1. Create a new file named create_force.tcl using any text editor.
  2. Paste the copied commands from the command file into the create_force.tcl file.
  3. Remove all () and replace them with spaces. The commands should look similar to the following:
    *loadsize 1 15 0 1 
    *createmark nodes 1 3237
    *loadcreateonentity_curve nodes 1 1 1 0 0 23 0 0 23 0 0 0 0 0

    Simply running the above commands will work without a problem, but note that the *createmark command is hard coded to the single node picked when generating the command file. Also notice that the magnitude is hard coded as well. This is not very useful for a generic utility.

  4. Replace the *createmark command with the *createmarkpanel command.
    The command *createmarkpanel presents the user with a selection panel for the entity specified. The commands should now look like this:
    *loadsize 1 15 0 1 
    *createmarkpanel nodes 1 "Select nodes for load creation"
    *loadcreateonentity_curve nodes 1 1 1 0 0 23 0 0 23 0 0 0 0 0
  5. If you want to specify the magnitude, you are prompted for a value using hm_getfloat. Then replace the hard coded magnitude in the *loadcreateonentity_curve command with the user defined value. The commands should now look like this:
    *loadsize 1 15 0 1 
    *createmarkpanel nodes 1 "Select nodes for load creation"
    set mag_val [hm_getfloat "Magnitude=" "Enter force magnitude:"]
    *loadcreateonentity_curve nodes 1 1 1 0 0 $mag_val 0 0 $mag_val 0 0 0 0 0
  6. Save the create_force.tcl script.

Create a Utility menu Macro

In this step you will create a Utility menu macro that runs a Tcl script.

  1. Create a new Utility menu macro that calls the *evaltclscript command to run a Tcl script, using the macro wrapper commands *beginmacro and *endmacro. In the *beginmacro command, name the macro EvalTcl.
    *beginmacro("EvalTcl")
        *evaltclscript($1,0)
    *endmacro()

    The macro name EvalTcl will be used to connect the button with the macro via the macroName field in the *createbutton command.

  2. Save the userpage.mac file.

Add the Macro Button

In this step, you will add a macro button to the User page.

  1. Create a new button in the userpage.mac file.
    *createbutton(5,"Create Force",16,0,10,GREEN,"Create z-direction force on 
    selected nodes","EvalTcl","create_force.tcl")

    This creates a button on page 5 (User page), names it, places it in the 16th row, places its start at column 0, gives it a width of 10 columns, applies to it the color green, provides a help string and references the macro create_force.tcl defined in Step 6.

    Notice that the full path is not used to reference the create_force.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. Users can add additional search paths using the TCL_INCLUDE environment variable. Relative paths can also be used from these search paths.

  2. Save the userpage.mac file.

Reload the Current File

In this step you will reload the current .mac file to load the modified userpage.mac.

From the menu bar, select Preferences > Menu Config and click on retrieve next to macro file.

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.

  1. Click the User button on the Utility menu.
    The new button labeled Create Force should be on the User page.
  2. Click this button to run the Tcl script that automatically creates forces in the z-direction of the selected nodes.
    The new forces are created on the specified nodes with the given magnitude and placed in the current load collector. If no load collector exists, the forces are placed in a load collector called auto1.

    It is often necessary to debug Tcl scripts using the command window. This allows you to run the Tcl script and easily review error messages, as well as print out debug information.