02 HyperMesh Automation v2022.1
02 HyperMesh Automation v2022.1
1
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Altair HyperWorks Customization and
Automation
Session Objectives
02 - HyperMesh Automation
• Understand the scope of HyperMesh API layer,
the organization and the logic of its Tcl
commands.
3
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
HyperView
Intro to HyperMesh and
Tcl/Tk Automation HyperGraph
Automation
4
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
HM API to
HM Entity
HM API Enhance
Introduction Data Names Extensions
Commands Script
and Attributes
00‘ 30‘ 80‘ Performance 100‘ 180‘
150‘
• HyperWorks Reference • HyperMesh Entities • Impact Factors • Entity Data Names • Overview
Guide • HyperMesh Marks • Preferences and Attributes • Extension Manager
• Tcl GUI, Modify, Query • Creating HyperMesh • Commands Overview • Scripted Context
• HyperMesh Automation Marks • Exercise 2F • What are Data • Context Automation
• Tcl Console • Querying HyperMesh • Q&A Names? How to • Demo
• Command File Marks access? • Exercises 2R-2S
• Q&A • Commands Involving a • Pointers
Path • Setting Data Names
• Basic HyperMesh Input and Attributes
Widgets • Querying Data Names
• Exercises 2A-2E and Attributes
• Q&A • hmcustom.tcl
• Exercises 2G-2Q
• Q&A
5
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
HM API to
HM Entity
HM API Enhance
Introduction Data Names Extensions
Commands Script
and Attributes
00‘ 30‘ 80‘ Performance 100‘ 180‘
150‘
• HyperWorks Reference • HyperMesh Entities • Impact Factors • Entity Data Names • Overview
Guide • HyperMesh Marks • Preferences and Attributes • Extension Manager
• Tcl GUI, Modify, Query • Creating HyperMesh • Commands Overview • Scripted Context
• HyperMesh Automation Marks • Exercise 2F • What are Data • Context Automation
• Tcl Console • Querying HyperMesh • Q&A Names? How to • Demo
• Command File Marks access? • Exercises 2R-2S
• Q&A • Commands Involving a • Pointers
Path • Setting Data Names
• Basic HyperMesh Input and Attributes
Widgets • Querying Data Names
• Exercises 2A-2E and Attributes
• Q&A • hmcustom.tcl
• Exercises 2G-2Q
• Q&A
6
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
7
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
• Data Names: Details on the core data that can be queried and manipulated.
A Data Name is a string that represents a piece of data.
• Ext API: This API allows external applications to link HyperMesh client as a
library and provides a limited set of functions and structures to access
specific functionality.
8
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
• Solver Templates: Solver templates are ASCII data files containing Altair
HyperMesh Template Language Commands and Altair HyperMesh
Template Language Functions.
9
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
• These guides are meant to highlight new features and their scripting
implementations so that scripts can take advantage of these new features.
• In addition, they provide valuable information about how to update existing scripts
to be compatible with new developments and required API changes.
10
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Tcl GUI
Commands
11
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Tcl Modify
Commands
12
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Tcl Modify
Commands
• Use + F to quickly find the command that you are interested in.
13
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Tcl Query
Commands
14
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
HyperMesh Automation
What is it?
• Uses:
• HyperMesh Tcl Commands
• Tcl/Tk Commands
15
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
HyperMesh Automation
Why and When to Use Tcl Automation?
Note: Before trying to build up a full process in Tcl, we recommend users review HyperWorks capabilities to
make sure you do not develop a feature from scratch that is already available in the product.
16
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
HyperMesh Automation
Using the Command Window
• An interactive Command Window is provided and can be activated through the View menu.
• In the Command Window, users can evaluate any command that can be issued in Tcl or in
HyperMesh through Tcl.
• Commands such as ls, pwd, and cd can be used within the Command Window.
17
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
HyperMesh Automation
Using the Command Window
• General Tcl and HyperMesh specific Tcl commands can also be entered.
• Using the Command Window provides the automation tool developer an easy way of testing a
concept before writing the full procedure.
• Run scripts using the source command, i.e. source test.tcl, or, run scripts using the File > Load menu option.
• Save the session’s command history using the File > Save menu option.
18
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
HyperMesh Automation
Tcl Console and HWC Console
• There are various types of customizations that are possible for HyperWorks, for example:
• Tcl Console - Enables you to enter and execute Tcl/Tk commands instead of using the user interface.
• HWC Console - Supports auto-completion and interactive help and allows easy modification and re-execution of
commands.
• Command File (*.cmf) - Opens a file browser to load and run an HyperMesh Command Files (legacy format).
• Script (*.tcl, *.tbc) - Opens a file browser to load and run a Tcl file.
19
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Tcl Console
Overview
• Tcl Console enables you to enter and execute Tcl/Tk commands instead of using the User Interface.
• View > Tcl Console. By default, the Tcl Console opens at the bottom of the application.
• HyperWorks commands can be entered in the Tcl Console to manipulate the model in the
Pre- or Post-Processing Client.
• Examples:
• Adds the elements based on the arguments supplied from the model loaded in the active window.
• Masks the elements based on the arguments supplied from the model loaded in the active window.
Tcl Console
Intellisense
• The Intellisense window allows you to quickly locate commands for a given handle, as well as their
parameters.
• You can use the Popup (Default) or the Command Line at the bottom of the console. Type commands which
contain Tcl handles and a popup Intellisense window is shown above for the Popup option.
22
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
23
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
24
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Command File
Definition
• command<#>.tcl
• The command file is a command history file
containing the commands executed
in HyperWorks whenever an operation is
performed.
Command File
Definition
• If this file does not already exist, then HyperMesh creates it at the start of a session.
• If the file does already exist, HyperMesh appends the commands from the new session to the original file.
• Commands executed in active HyperMesh session are not immediately written to the command file.
• They are stored in memory and are written to the command file during idle time (when HyperMesh is not busy
performing user operations).
• HM_COMMANDFILE_MODE
• APPEND
• OVERWRITE
• UNIQUE
26
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Command File
Content
• *startnotehistorystate/*endnotehistorystate
• Useful for Undo/Redo in the session. No need to keep it for Tcl authoring.
• *viewset
• Command to position the model (views). No need to keep except for specific reasons involving target views
(screenshots).
• Commands starting with "*" are actions in HyperMesh (*createvector), whereas commands
with prefix hm_ stand for query.
• Among Tcl commands in the command.tcl file, attention must be paid to:
• *createmark
• *setvalue (optional).
27
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
28
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
29
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
30
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
HM API to
HM Entity
HM API Enhance
Introduction Data Names Extensions
Commands Script
and Attributes
00‘ 30‘ 80‘ Performance 100‘ 180‘
150‘
• HyperWorks Reference • HyperMesh Entities • Impact Factors • Entity Data Names • Overview
Guide • HyperMesh Marks • Preferences and Attributes • Extension Manager
• Tcl GUI, Modify, Query • Creating HyperMesh • Commands Overview • Scripted Context
• HyperMesh Automation Marks • Exercise 2F • What are Data • Context Automation
• Tcl Console • Querying HyperMesh • Q&A Names? How to • Demo
• Command File Marks access? • Exercises 2R-2S
• Q&A • Commands Involving a • Pointers
Path • Setting Data Names
• Basic HyperMesh Input and Attributes
Widgets • Querying Data Names
• Exercises 2A-2E and Attributes
• Q&A • hmcustom.tcl
• Exercises 2G-2Q
• Q&A
31
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
HyperMesh Entities
Entity Types
Collected Tcl Name Named Tcl Name
• There are 3 basic types of Entities Entities
HyperMesh Entities: Nodes nodes Blocks blocks
Elements elems
1. Collectors (ie. Components, Load Collectors) Contact
contactsurfs
Points points Surfaces
2. Collected Entities (ie. Elements, Loads) Lines lines groups
Groups
3. Named Entities (ie. Materials, Properties) Surfaces surfs loadsteps
Load Steps
Solids solids
Materials mats
Collectors Tcl Name Connectors connectors
Parameters params
Components comps Loads loads
Properties props
Load Collectors loadcols Equations equations
Sets sets
System Collectors systemcols Systems systems
Vector Collectors vectorcols Vectors vectors Tags tags
32
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
HyperMesh Entities
Entity Types
• HyperWorks Desktop entities are often used as string parameters in commands that act directly
on entities in some fashion, such as creating filtered sets that contain only a specific entity type.
• Example: Elements, Line, Groups, Sets, Nodes, Components, Loads, ...
• Example: Creating filtered sets that contain only a specific entity type.
• Any command supporting different entity types will have to be executed for each entity type
separately.
• Example: Delete all materials and properties.
*createmark properties 1 1 2 3
*delemark properties 1
*createmark materials 1 1 2 3
*delemark materials 1
33
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
HyperMesh Marks
Definition
• Marks specify groups of entities that are transferred to the command processor.
• Marks can be created for most entities, and they are passed to commands that perform operations on the entities
on the mark.
• HyperMesh allows for two concurrent marks and one user mark per entity type.
• Standard marks are referenced by the mark IDs 1 and 2.
• Example: Allow the user to select the elements and then delete the elements.
• *createmarkpanel elements 1 "Select elements to delete"
• *deletemark elements 1
35
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
• *deletemark elements 1
• This *createmark command populates mark 1 with elements 50, 51, and 52.
• In order to make a macro useful for multiple models, we can change the selection method.
36
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
37
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
38
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
• The HyperMesh *createvector and *createplane commands have special reserved IDs 1
and 2 for storing up to two vectors or planes.
• The vectors and planes can be defined at any time during the processing of a command file or Tcl script.
39
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
• If the script is not intended to provide interactivity for entity selection, several list of options in exist
*createmark Online Help to make the selection as smart as possible:
• Similar to interactive filters: "all", "displayed", "by collector", "retrieve", …
• "by card image": All materials with MAT1 card image, all loads type SPC, …
• With geometric shapes: "by box" (rectangular box), "by cylinder", "by cone", "by sphere"
• Looking for an attribute-specific value (e.g. all properties whose thickness is above 2 mm):
• "contains value", "equal to value", "greater than value", "less than value", "by value range"
• Same goes with metadata: "by metadata contains value", "by metadata equal to value", ...
40
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
• In order to force the user to select a single entity, *createenitytpanel can be used together
with hm_info lastselectedentity <entity_type> to retrieve the selected entity ID.
*createentitypanel entity_type message
41
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
• *marknointersection
*createmark elements 1 50 51 52
*appendmark elements 1 "by adjacent"
• *findmark: Find entities OR find attached entities (e.g. Elements attached to a rigid).
42
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
• Once entities are selected in a mark, the user can save an ID list through the hm_getmark
command.
*createmark elements 1 "by component id" 1
• Operations can be performed on each entity of the list obtained through hm_getmark, using
foreach operator:
foreach el $ElemList {
<body>
43
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
• hm_entitymaxid: Get the maximum ID for a given entity (element, node, …).
• hm_getsolverid: HyperMesh manages solver profiles allowing duplicate IDs (e.g., a hexa and a
beam element sharing the same ID). Internally it assigns a single ID to each entity.
• hm_getsolverid: Used to retrieve solver ID from the internal ID.
• hm_getboundingbox: Get the min and max x, y, z values of a box containing selected entities
(components, surfaces, …).
44
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
• Example of a command:
*feoutputwithdata "C:/../hmdesktop/templates/feoutput/optistruct/optistruct"
"D:/calcul/test.fem" 1 0 0 1 1
• "C:/../hmdesktop/templates/feoutput/optistruct/optistruct"
• "D:/calcul/test.fem"
45
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
• The installation path needs to be changed to avoid any issue when upgrading your version:
*feoutputwithdata [file join [hm_info -appinfo SPECIFIEDPATH TEMPLATES_DIR]
feoutput/optistruct/optistruct] "D:/calcul/test.fem" 1 0 0 1 1
46
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
• Setup of this path will depend on the macro structure, and can be done in multiple ways:
• Asking the user to select a file with tk_getOpenFile or tk_getSaveFile widget.
• Browsing with cd / glob commands into a directory to find the relevant file.
• Using command script info to look for a file in the same directory as the Tcl file.
• …
• In order to make the script robust whatever the platform (Windows, Linux), it is recommended to
use file normalize command.
47
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
hm_getstring "Load collector name" "Enter a name for the load collector"
• This command can be used with the set Tcl command to assign the string entered in the panel to a
variable:
set loadname [hm_getstring "Load collector name" "Enter name for load collector"]
48
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
• Both these commands have the same options as the hm_getstring command.
49
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
• The macros that have been created thus far are very powerful in their automation of repetitive tasks.
However, there are limitations.
• The Tcl scripting language can be utilized to provide support for more advanced tasks.
• Tcl could be used to request a name for the load collector from the user and use that information to
tell the HyperMesh session to create a load collector with the user provided name.
50
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
51
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
52
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
53
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
• HyperMesh Tcl and core Tcl commands will be used in the Tcl/Tk commands used:
Command Window to determine the number of elements in a • list
component collector for a pre-defined HyperMesh model.
• llength
• set
• Use the file c_channel-tcl_vector.hm.
• source
54
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Exercise Hints:
• Do all the steps in HyperMesh and extract the appropriate commands from the
command.tcl file.
55
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
56
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
57
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Exercise Hints:
• Be sure to do the steps in HyperMesh and then extract the appropriate commands from the command.cmf file.
Modify the commands as necessary and be sure to clear the mark when needed.
58
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
HM API to
HM Entity
HM API Enhance
Introduction Data Names Extensions
Commands Script
and Attributes
00‘ 30‘ 80‘ Performance 100‘ 180‘
150‘
• HyperWorks Reference • HyperMesh Entities • Impact Factors • Entity Data Names • Overview
Guide • HyperMesh Marks • Preferences and Attributes • Extension Manager
• Tcl GUI, Modify, Query • Creating HyperMesh • Commands Overview • Scripted Context
• HyperMesh Automation Marks • Exercise 2F • What are Data • Context Automation
• Tcl Console • Querying HyperMesh • Q&A Names? How to • Demo
• Command File Marks access? • Exercises 2R-2S
• Q&A • Commands Involving a • Pointers
Path • Setting Data Names
• Basic HyperMesh Input and Attributes
Widgets • Querying Data Names
• Exercises 2A-2E and Attributes
• Q&A • hmcustom.tcl
• Exercises 2G-2Q
• Q&A
59
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
1. Efficiency of the Tcl code and speed of its execution in the Tcl interpreter.
• Recommendations: Efficient structure of the code, optimize I/O, push heavy math operations to compiled code
(C++) via APIs.
• Recommendations: Perform operations in bulk rather than per entity, optimize the session settings (Preferences).
60
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
• Via GUI: File menu > Preferences > HyperMesh > Performance
hm_getoption option
61
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
62
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
63
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
64
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
65
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
66
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
HM API to
HM Entity
HM API Enhance
Introduction Data Names Extensions
Commands Script
and Attributes
00‘ 30‘ 80‘ Performance 100‘ 180‘
150‘
• HyperWorks Reference • HyperMesh Entities • Impact Factors • Entity Data Names • Overview
Guide • HyperMesh Marks • Preferences and Attributes • Extension Manager
• Tcl GUI, Modify, Query • Creating HyperMesh • Commands Overview • Scripted Context
• HyperMesh Automation Marks • Exercise 2F • What are Data • Context Automation
• Tcl Console • Querying HyperMesh • Q&A Names? How to • Demo
• Command File Marks access? • Exercises 2R-2S
• Q&A • Commands Involving a • Pointers
Path • Setting Data Names
• Basic HyperMesh Input and Attributes
Widgets • Querying Data Names
• Exercises 2A-2E and Attributes
• Q&A • hmcustom.tcl
• Exercises 2G-2Q
• Q&A
67
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
1. Data Names - “Out of the box” variables defined in the HyperMesh Database.
2. Attributes - "Customized” variables defined in the HyperMesh template for each User Profile (i.e. OptiStruct,
Nastran, Abaqus, etc…).
68
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
• Data Names are generic references to the information that defines an entity in the HyperMesh
Environment.
• Example: The x, y, and z coordinates that define node’s location in three-dimensional space.
• This information is part of the entity’s definition and is consistent for all solvers.
• Data Names can change from one HyperMesh version to the next.
• For this reason, please refer to the Altair HyperWorks Online Help. Information on the Data Names can be
found in the following location:
69
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
• Also returns the value at a specific index for Array type of Data Names and Attributes.
70
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
node When a load is applied to a node, this serves as a pointer to the node
comp1 X component of the vector
comp2 Y component of the vector
comp3 Z component of the vector
magnitude Magnitude of the load vector
collector Collector that owns the load (pointer)
71
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
• Tcl script which prompts the user to select several nodes and then displays their x, y, z coordinates:
hm_markclear nodes 1
*createmarkpanel nodes 1
set nodes [hm_getmark nodes 1]
foreach node $nodes {
set xVal [hm_getvalue nodes id=$node dataname=x]
set yVal [hm_getvalue nodes id=$node dataname=y]
set zVal [hm_getvalue nodes id=$node dataname=z]
tk_messageBox -message "Node $node = $xVal $yVal $zVal"
}
id The ID of the node (integer).
inputsystem Pointer to the node input system (pointer).
• Some Data Names
outputsystem Pointer to the node output system (pointer).
available for nodes:
x The x coordinate of the node in its local system (real).
y The y coordinate of the node in its local system (real).
z The z coordinate of the node in its local system (real).
72
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
• Several of the Data Names in the two tables are defined as pointers.
• This means they “point” to Data Names available for either collectors or nodes.
• In order to retrieve any data from a pointer, the Data Name requested for the particular pointer must also be
supplied.
73
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
74
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
• Another example is with component collectors. There is no Data Name associated with a
component collector to get the material name, only the material ID.
• The following set of commands is used to get the material ID:
• A second set of commands would then be required to get the name of the material with that ID:
• set matName [hm_getvalue mats id=$matID dataname=name]
• From this pointer, any valid material Data Name can be substituted by separating the pointer and the new Data Name with a
period (.). From the example above the following line can replace the previous two lines:
75
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
• Solver Templates define every solver specific attribute including Data Names, Attribute IDs,
Card Image formats, and the format of the Data upon Export.
• Templates exist for each solver supported by HyperMesh and are located in subfolders under the
<altair_home>/templates/feoutput directory.
76
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
• There are several different types of attributes including array, double, entity, integer and string.
The difference is that each entity type uses an appropriate *attributeupdate command based
on its type or the generic *setvalue command.
77
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
• A sample Card Image for an OptiStruct MAT1 material collector is shown on the bottom.
• For each field, there is a corresponding attribute and data name in the OptiStruct template in:
<altair_home>/templates/feoutput/common_nas_os/attribs
*defineattribute(G,2,real,none)
*defineattribute(Nu,3,real,none)
*defineattribute(Rho,4,real,none)
• Additionally, there are card image definitions that define how the card editor is generated inside of
HyperMesh for each attribute.
79
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
• *menufield command determines how a field is created in Card Editor for a particular Attribute.
• For example, the Attribute and Card Image definitions for the Young’s Modulus for the
MAT1 Material are:
*defineattribute(E,1,real,none)
*menufield(E,real,$E,8)
Note: The first argument in *menufield is the text string to show above the data field and the third argument is
the particular Data Name that is associated with that field.
• Knowing all of this information allows us to assign, update and query the data.
80
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
• Table with Data Name Strings, Attributes IDs, Data Types and Value shown.
81
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
• When the MAT1 material was created, the relevant commands to assign values to its attributes
were written to the command.tcl file:
*createentity mats cardimage=MAT1 name=steel
82
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
• Creating or updating solver attribute of an existing solver card is done using *setvalue
command:
*setvalue mats id=2 STATUS=1 1=210000
• Where:
• Looking at the OptiStruct attributes template, attribute 1 corresponds to the data name E (Young’s Modulus).
83
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
• Create a Tcl procedure to substitute variables for the Name, Color and Data Values.
• Make the template file path modular across different platforms.
• Make the material ID a variable that references the newly created material ID, so that the
*attributeupdatedouble and *attributeupdateint commands or *setvalue command work
properly.
• The variables are then used in the later commands to pass the appropriate arguments.
• This procedure also checks to see if a material with that name already exists and if it does, a message is returned
in the HyperMesh message bar.
85
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
• It is also possible to update an existing card image. Procedure to do this is almost identical to the
procedure to create a new card image, except that the material is not created and thus the
procedure requires a material ID to be passed instead of a material name.
• The complete list of attributes for an entity can be retrieved using hm_attributelist command.
hm_attributelist material 1 id
146 3240 1 2 3 4 5 6 7 341 343 345 4417 5237 7142 7143 7144 3916
87
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Or
88
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
89
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
• Example: Query a material (MAT1 card image) and its values of Young’s Modulus, Density and
Poisson’s Ratio.
1. Open Matrix Browser and select HMdata as DataSource.
90
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
5. Click on the column label where it says materials to update all of the
data names in the Datanames block at the bottom of the browser. All
of the available data names used in the material card are displayed
in the Datanames block. 6
5
6. Choose which data names you want to query and click Query.
91
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
hmcustom.tcl
What is it?
• HyperWorks allows you to create a script file named hmcustom.tcl that can be used to
automatically execute a series of commands or to define custom settings during startup for the
HyperMesh Client.
• When HyperMesh Client is started, it first runs all other startup procedures, options and
commands, and then looks for the hmcustom.tcl file.
• This file is then processed as the absolute last step of the HyperMesh Client startup process.
• hmcustom.tcl file may contain any relevant Tcl commands or procedures that you desire.
92
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
hmcustom.tcl
Where is it located?
• HyperMesh uses the following search order to find the hmcustom.tcl file.
• If copies exist in multiple locations, each one is run in sequence in the following order:
1. HW_CONFIG_PATH Environment Variable
• You can point this to any location.
2. Home directory
• Typically, C:/Program Files/Altair/2022.1/hm/bin/win64
3. Start-in directory
• To alter this:
93
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
hmcustom.tcl
What can it be used for?
• It can contain any Tcl commands user wishes to execute at the start of HyperMesh.
• Defining various callbacks, i.e. procedures that are typically triggered automatically at certain events
(e.g., opening a file, saving the model, executing specific command).
94
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
95
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
96
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
97
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
100
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Note: Pay careful attention to vector directions and look Tcl/Tk commands used:
closely at the data you have generated.
Can you speed-up the script using the knowledge from • for foreach set
Exercise 2F? • if elseif else
101
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Exercise Hints:
• In the HyperWorks installation, open the file <altair_home>\hwdesktop\templates\feoutput\
optistruct\optistruct. This file contains the card image definitions for the Optistruct template.
103
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Exercise Objectives:
HyperMesh commands used:
• The purpose of this exercise is to become familiar with creating HyperMesh
• *createentity
Tcl scripts which automate defining solver data in HyperMesh card
images. This example, as well as previous, will help you become comfortable • *setvalue
with defining and calling Tcl procedures. • *createmark
• Define the task to be automated: • hm_getmark
1. Create an OptiStruct MAT1 material with the following parameter values (assume
the OptiStruct template is already loaded): Young’s modulus (E), shear modulus
(G), Poisson’s ratio (Nu), density (Rho). Tcl/Tk commands used:
2. Upon automating the task, wrap the code into a Tcl procedure.
• set proc
Exercise Hints:
• The advantage of creating a procedure is that it is accessible from any part of the script. The developer only needs to
pass the material name and its parameter values to create desired material.
104
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
105
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Exercise Hints:
• Do the steps in HyperMesh and then extract the commands from the command.cmf file.
106
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
107
MORE TO EXPLORE
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
108
MORE TO EXPLORE
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
2. Create a copy of the component (including the mesh) for each material in • *createmark hm_getmark
mat.txt. Use the material names as the component names. • *setvalue hm_getvalue
2. Automate the following steps: • loadcreateonentity_curve
a) Read the materials from mat.txt and create the relevant materials in HyperMesh.
Tcl/Tk commands used:
b) Create a property for each component, associate the material and assign it to the
elements. • set return
c) Create the loads and constraints on the nodes selected by the user. Define a subcase. • while foreach
• open gets
Exercise Hints:
• tk_messageBox
• Assume the element thickness, load magnitude, constrained DoFs, subcase name
etc. will always be the same. User has no control over it and the value of these
parameters can be hard-coded in the script.
109
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
HM API to
HM Entity
HM API Enhance
Introduction Data Names Extensions
Commands Script
and Attributes
00‘ 30‘ 80‘ Performance 100‘ 180‘
150‘
• HyperWorks Reference • HyperMesh Entities • Impact Factors • Entity Data Names • Overview
Guide • HyperMesh Marks • Preferences and Attributes • Extension Manager
• Tcl GUI, Modify, Query • Creating HyperMesh • Commands Overview • Scripted Context
• HyperMesh Automation Marks • Exercise 2F • What are Data • Context Automation
• Tcl Console • Querying HyperMesh • Q&A Names? How to • Demo
• Command File Marks access? • Exercises 2R-2S
• Q&A • Commands Involving a • Pointers
Path • Setting Data Names
• Basic HyperMesh Input and Attributes
Widgets • Querying Data Names
• Exercises 2A-2E and Attributes
• Q&A • hmcustom.tcl
• Exercises 2G-2Q
• Q&A
110
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
111
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Extensions
Overview
Extensions
2022.1 Highlights
113
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Extensions
Extension Manager
114
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Extensions
Start-up Procedures
• Extension packages may include a Tcl script that gets executed when the parent extension is
loaded.
• By having various extensions with different init.tcl files, user can easily control start-up
procedures by loading and unloading extensions as needed.
• Multiple init.tcl can be deployed by registering multiple extensions that can be switched on/off
(load/unload extensions).
115
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Extensions
116
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Extensions
Package Structure
117
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Extensions
Actions
118
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Extensions
Example
exercise_ribbon.png
exercise_toolbar.png
toolbar.xml
119
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Extensions
Example
• The name of the extension must be unique in
the context of all registered extensions in an
application.
• The supportedClient specifies which
application the extension supports. Currently,
the valid values are HyperWorksDesktop
and Inspire.
120
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Extensions
Example
• Paths to the script files are not hard-coded, the location is established relative to the init.tcl file.
• Individual scripts are called via procedures defined in the init.tcl file.
toolbar.xml
init.tcl
121
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
122
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Scripted Context
Definition
• Scripted Context provides user with mechanisms to create custom tools fully embedded in the UI
(multipurpose icons, guide bars, context menus, etc.).
1. Link to Custom
1 Ribbon
2
2. Fully Customized
Ribbon
3
4 3. Custom Guide Bar
4. Custom Help
5. Custom Options
5 Dialog
123
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Scripted Context
Core Contexts
124
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Scripted Context
Structure
my_context.xml my_context.tcl
Scripted Context
APIs
• Provide means of working with contexts via the Tcl interpreter (script or console) in HyperWorks.
Example: Get selected entities, set/get a context option, register context and Tcl class…
Context Automation
Step 1
• Establish all the required names (context name, options names, selection names etc.) that will have
to be referenced in the commands.
ctx::ui print
• The print command will output the DOM object (XML content) of the active context.
127
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Context Automation
Step 2
128
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Context Automation
Step 3
ctx::selection active
• Note: You can also see the selection name in the context XML DOM.
• You can also copy entities from a mark to the context selection.
ctx::selection copyfrom <selection_name> -mark <mark_id>
129
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Context Automation
Step 4
• Assuming the context allows adjusting some parameters (options), we can control those via APIs.
• The option names can be retrieved from context XML DOM as mentioned earlier or run:
ctx GetOptions
130
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Context Automation
Step 4
• Assuming the context allows adjusting some parameters (options), we can control those via APIs.
• The option names can be retrieved from context XML DOM as mentioned earlier.
131
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Context Automation
Step 5
• Once everything is set up and defined as needed, we can execute the context action.
• Again, you can verify the action definition in the XML DOM, but you can safely assume the following
command will apply:
ctx Proceed
Or
ctx::manager exit
• List of existing context Tcl API commands can be found here: Context Tcl APIs
132
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Context Automation
Example
• Renumbering all entity type existing in the model using context with starting ID 150000.
ctx::manager exit
133
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Context Automation
HyperView
• Also HyperView contexts can be automated, for instance, starting the HyperView note contexts:
ctx::manager enter HWResultsNoteNew
• Similar to HyperMesh, the print command gives us the context tag, so we have all necessary
information to automate entering the context.
134
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Context Automation
Adjusting Parameters in HyperView
• Assuming the context allows adjusting some parameters (options), we can control those via APIs.
• The option names can be retrieved from context XML DOM as mentioned earlier.
135
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Exercise Objectives:
1. Inspect the Extension folder structure.
2. File > Extension Manager > Add Extension from the folder provided and
make it active.
3. Custom Ribbon, menu and toolbars
will appear in the User Interface.
4. Use what you prefer to launch the Tcl scripts of
the previous exercises from the current
HyperMesh session.
Exercise Hints:
• Test the scripts using HyperMesh files:
c_channel-tcl_vector.hm and
Exercise_2Q.tcl
136
MORE TO EXPLORE
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
137
MORE TO EXPLORE
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Demo Goals:
1. Open a new HyperMesh Client session and load the
*.hm file.
2. In a text editor, review the context_apis.tcl file and set
the mesh size properly for the component with ID 1.
3. Open Tcl Console and source the Tcl file in your working
directory.
4. Create General 2D Mesh will be automatically open.
5. Click Mesh to generate the mesh and review the result.
138
MORE TO EXPLORE
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
Exercise Goals:
1. Load Extension
2. Organize the Assembly
3. Surface Mesh
a Component
139
MORE TO EXPLORE
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
140
MORE TO EXPLORE
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
c) Custom Tools ribbon > Geometry group > . Pick the Assembly component and confirm the operation.
141
MORE TO EXPLORE
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
b) To understand how the context is called, open Tcl Console and type:
ctx::ui print
c) The full content definition of the .xml file of the context is printed. Scroll to the top and see:
context tag="2DMCSGeneral". This is the name of the context. Find the proper one to change the element size.
142
MORE TO EXPLORE
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
h) You can click the Mesh button or use the API command: ctx Proceed
Note: Remember that we need to be in the context to be able to work with it.
143
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1
144
Your Feedback Matters
Training feedback survey
#ONLYFORWARD
THANK YOU
altair.com
#ONLYFORWARD
DISCOVER CONTINUOUSLY.
ADVANCE INFINITELY.
Visit altair.com to learn more.
#ONLYFORWARD