HM-8070: Create Spline Surfaces on Tria Elements
In this tutorial, you will create a Tcl script that creates spline surfaces from the nodes of selected tria elements.
The Tcl commands if, foreach, and incr will be used to add logic to the script. The command hm_getentityvalue is used to extract information from HyperMesh entities, based on data names.
Data names are generic references to the information that physically define an entity in the HyperMesh environment. An example of this is the x-, y-, and z-coordinates that define a node location in three-dimensional space. The available data names for each can be found in the HyperMesh Reference Guide Data Names topic.
hm_getentityvalue entity_type id data_name flag
where entity_type is the requested entity type (elements, loads, nodes, and so on), id is the entity ID, the data_name is the data field name of interest, and flag is either 0 or 1 depending on whether the command should return a numeric value (0) or a string (1).
set force_x [hm_getentityvalue loads 12 "comp1" 0]
Define the Process
In this step, you will define the process.
- Prompt you to select a number of tria elements to create spline surfaces.
- Make sure you have selected one or more elements.
- If a selected element is not a tria, skip that element.
- Extract the node IDs of each element.
- Create the spline surface from the nodes.
- Report on the number of spline surfaces created.
Determine Data Names
In this step you will determine the data names to use to extract the element type and node IDs.
Data Name | Description |
---|---|
config | The number, "103" |
node1 | first node (node pointer) |
node2 | second node (node pointer) |
node3 | third node (node pointer) |
Create a Text File
In this step you will create a text file and save it as HM8070.tcl.
- Open a new text file in any text editor.
- Save it as HM8070.tcl.
Select Elements and Add Loads to a List
In this step, you will select the desired elements and add those loads to a list.
The *createmarkpanel command is used to allow you to graphically select the elements from the HyperMesh interface and add them to the mark. The command below adds the elements to mark 1. Once the elements have been added to mark 1, the element IDs are assigned to a list called elems_list, using the Tcl command set.
*createmarkpanel elems 1 "Select tria elements to create surfaces";
set elems_list [hm_getmark elems 1];
Begin an If Loop
In this step you will begin an if loop which checks to see if the variable elems_list has values. If it does, then proceed with the macro.
Before continuing with the macro, you should check to make sure that the variable elems_list has values in it. This is done by using an if loop. In the if loop below, you are checking that the variable elems_list is not empty.
if {$elems_list != ""} {
Initialize a Variable
In this step, you will initialize a variable which counts the number of times the foreach loop is entered.
The variable success_count is initialized and set to 0. This variable is used to count the number of times the foreach loop, defined in Step 7, is entered. You will use this variable at the end of the script.
set success_count 0;
Use a Foreach Loop
In this step you will use a foreach loop to iterate through each element in the let, elems_list, and then set a variable, config, which store the element configuration. This is extracted using the hm_getentityvalue command and the appropriate data name.
Using a foreach loop, each element in the list elems_list will be iterated through. Within the foreach loop, each load is referenced by elem_id and then the variable config is defined. This variable is set to the result of the hm_getentityvalue which uses the element data name config to report the configuration of the element. A tria element will have an element configuration of 103 while a quad element will have a configuration of 104.
foreach elem_id $elems_list {
set config [hm_getentityvalue elems $elem_id "config" 0];
Begin an If Loop
In this step you will begin an if loop which checks to see if the variable, config, has a value of 103. If it does, then proceed with the macro.
Using an if loop, the variable config is checked to see if it does not have a value of 103. A value of 103 means that the element configuration is a tria element. If the value is not equal to 103, the continue statement is used to move outside of the foreach loop. If the value is the config variable is 103, then the macro is continued.
if {$config != 103} {
continue;
}
Set Variables
In this step you will set three variables that contain the node id of each of the nodes used to define the tria element.
Three variables are defined (node1, node2, and node3) which represent the 3 nodes that define the tria element. These three nodes will be used to create the spline surface. Using the hm_getentityvalue command and the element data names node1, node2, and node3 along with the pointer id, the node id is retrieved and assigned to the appropriate variable.
set node1 [hm_getentityvalue elems $elem_id "node1.id" 0];
set node2 [hm_getentityvalue elems $elem_id "node2.id" 0];
set node3 [hm_getentityvalue elems $elem_id "node3.id" 0];
Set the Mode to Create the Surface
In this step, you will set the appropriate mode to create the surface.
- 1
- mesh keep surface
- 2
- mesh delete surface
- 3
- mesh without surface
- 4
- surface only
In this example, you only want to create a surface, so mode 4 is used.
*surfacemode 4;
Create a Node Mark
In this step, you will create a node mark that contains the three nodes defined in Step 9 and then use the *splinesurface command to create a spline surface using the nodes in the mark.
Using the *createmark, mark 1 for nodes is created and it contains the 3 nodes defined in the variables node1, node2, and node3.
*createmark nodes 1 $node1 $node2 $node3;
*splinesurface nodes 1 0 1 1;
Increase the Variable
In this step you will increase the variable, success_count, which is used to count the number of times the foreach loop is entered. Then, close the foreach loop.
Using the incr command, the variable success_count is increased. Following this command, a } is used to close the foreach loop.
incr success_count;
}
Clear the Node and Element Marks
In this step you will clear the node and element marks, and then use the hm_usermessage command to report the number of spline surfaces created.
Using the command *clearmark, mark 1 for the nodes and elements is cleared. Following these commands, the hm_usermessage command is used to report the number of spline surfaces created. The variable success_count is used to do this. Because this variable was increased each time the foreach loop was entered and the element configuration was 103, this variable kept a count of the number of spline surfaces that were created.
*clearmark nodes 1;
*clearmark elems 1;
hm_usermessage "$success_count splines created."
Add an Else Statement
In this step you will add an else statement that compliments the if statement used to see if the elems_list variable was empty. If it is empty, the else statement is executed.
The else statement compliments the if statement defined in Step 5 which checks to see if the elems_list variable is empty. If it is empty the else statement is executed. Inside the else statement, the hm_errormessage command is used to report to you that no elements were selected. Following the hm_errormessage command, the if statement is closed using a }.
} else {
hm_errormessage "No elements selected";
}
Test the Script
In this step you will test the script.