Creating Scripts
The functionality of the HyperMesh Tcl Modify commands are available through Tcl. Additionally, commands that allow you to extract information from the HyperWorks Desktop database, such as entity ID numbers on a mark, a list of assemblies, component names, elements per component, nodes per element, node values, and so forth. These are known as HyperMesh Tcl Query commands. They are used to query information from the database or template system.
- Define the task
- Delete the existing command.tcl file. This file is located in either the start-in directory or the current working directory.
- Perform the operations in HyperWorks Desktop that the script should run.
- Modify as necessary and introduce Tcl decision logic.
- Open the Forces panel.
- Select one node on the channel model.
- For the direction of the force choose the z-axis option.
- For the magnitude enter 23
- Toggle from magnitude % option to uniform size option for load size and set it to size of 15.
- Click create.
- Open the command.tcl file. At the bottom of the file should
be the lines:
*createmark nodes 1 3237 *loadcreateonentity nodes 1 1 1 0 0 23 0 0 23
*createmarkpanel nodes 1 "Select nodes for load creation";
*loadcreateonentity nodes 1 1 1 0 0 23 0 0 23;
set magVal [hm_getfloat "Magnitude=" "Enter force magnitude"];
*createmarkpanel nodes 1 "Select nodes for load creation";
*loadcreateonentity nodes 1 1 1 0 0 $magVal 0 0 $magVal;
source create_force.tcl
set fileName [hm_getfilename "Select the file for input:"];
set fileID [open $fileName];
foreach dataLine [split [read $fileID] \n] {
set nodeID [lindex $dataLine 0];
set magVal [lindex $dataLine 1];
*loadcreateonentity nodes 1 1 1 0 0 $magVal 0 0 $magVal;
}
If a command or Tcl script runs successfully when executed from the command window, a blue 1, or output from the last command will show on the next line. An error will cause the output to be red with a link to the stack trace. Error messages may also appear in popup windows with links to the stack trace as well. These error messages are important in order to debug scripts developed using the Tcl layer. They provide information on the specific command that caused the error, as well as the procedure name and line number of the command in order to quickly find and fix the issue.