HM-8030: Create a Macro to Create Constraints

In this step you will create a Utility menu macro to create constraints on a plane.

In this step you will
  • Determine the commands to create constraints on a plane
  • 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 click on the load collector name in the Model Browser and select Edit.

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

The Constraints panel allows you to create and update constraints.


Figure 1.

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 automatically create constraints on certain nodes.

The following step list is an overview of what you will accomplish in Step 3 of this tutorial.

  1. Create a load collector for the constraints.
  2. Enter the Constraints panel.
  3. Apply constraints to the nodes on the end of the beam lying in the YZ plane.

Delete the Existing Command File

In this step you will delete the existing command file.

  1. Locate the existing command.tcl file in the working directory.
  2. Delete the file.

Perform Operations

In this step you will perform the operations in HyperMesh.

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 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 constraints.
  4. Click create.
  5. Open the Constraints panel.
  6. Activate the create subpanel.
  7. Click nodes and select the on plane option.
    The plane that will be selected is the YZ plane. This is accomplished by selecting the x-axis vector, which is normal to the YZ plane. The base node option is then highlighted, allowing a node on one end of the beam to be selected as the base node for the plane. All nodes on that plane are highlighted when select is clicked.
  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.
  2. Select and copy all lines in the file.

    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 you (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.

Add Commands

In this step you will add the commands to the userpage.mac file.

  1. Open the userpage.mac file using any text editor.
  2. Paste the commands copied from the command file inside the userpage.mac file.

Modify Commands

In this step you will modify commands and add Utility menu macro wrapper commands.

  1. Enclose the commands in Step 5 between the wrapper commands *beginmacro and *endmacro. In the *beginmacro command, name the macro macroEdge_Const. Remove any lines copied from the command file that are not shown in the following:
    *beginmacro(macroEdge_Const)
                    *collectorcreate(loadcols,"constraints","",11)  
                    *createmark(nodes,1) 3358-3360 3296 3297 3142 etc …
                    *loadcreateonentity_curve(nodes,1,3,1,0,0,0,0,0,0,0,0,0,0,0)    
                *endmacro()

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

  2. Change the *createmark(nodes,1) command to *createmark(nodes,1) "on plane" 0 0 0 1 0 0 0.5 1 0.

    "On plane" is one of many selection methods available. This method allows the selection of only entities that lie within a tolerance (in this case, 0.5) of the plane defined at the point (0,0,0) with normal vector (1,0,0). In this exercise, this is the YZ plane.

    The final macro should look like:
    *beginmacro(macroEdge_Const)
                *collectorcreate(loadcols,"constraints","",11)  
                *createmark(nodes,1) "on plane" 0 0 0 1 0 0 0.5 1 0
                *loadcreateonentity(nodes,1,3,1,0,0,0,0,0,0)    
            *endmacro()
  3. Save the userpage.mac file.

Add the Macro Button

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

  1. Create a new button in the userpage.mac file.
    *createbutton(5,"Edge Const",18,0,10,GREEN,"Add constraints to outer edge 
    of elements","macroEdge_Const")

    This creates a button on page 5 (User page), names it, places it in the 20th row, starts it at column 0, makes it 10 columns wide, gives it the color green, provides a help string and references the macro macroSave defined in Step 6.

  2. Save the userpage.mac file.

Reload the File

In this step you will reload the current .mac file into HyperMesh 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 Edge Const should be on the User page.
  2. Click this button to run the macro that automatically creates constraints on the outer row of nodes.

    Some commands used in this exercise are very model-specific. For example, creating a load collector named “constraints” may cause an error if the collector already exists. Also, selecting nodes using the by plane option and specifying the YZ plane may not be applicable to a lot of situations.

    Several options exist to make the *createmark commands general enough to work with any model. For example, to select all the currently displayed elements in the model use the command *createmark(elements,1) "by displayed".

    Another option is to replace the *createmark command with *createmarkpanel. When executed, this command presents the user with a selection panel for the entity specified. For this macro, the *createmarkpanel command could be used to allow the user to select the appropriate nodes.

    Additionally, this Utility menu macro could be converted to a Tcl script that allows for additional logic and error checking controls. This way, you could also be prompted to enter a name for the load collector using hm_getstring. An error check could then be performed to determine if that load collector already exists, and appropriate action would then be taken.