[go: up one dir, main page]

0% found this document useful (0 votes)
238 views146 pages

02 HyperMesh Automation v2022.1

02-HyperMesh-Automation-v2022.1 (1)

Uploaded by

Fred
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
238 views146 pages

02 HyperMesh Automation v2022.1

02-HyperMesh-Automation-v2022.1 (1)

Uploaded by

Fred
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 146

© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.

Altair HyperWorks Customization and Automation, v2022.1

ALTAIR HYPERWORKS CUSTOMIZATION AND AUTOMATION V2022.1


HYPERMESH AUTOMATION

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.

• Learn the key steps to query and modify


HyperMesh Database.

• Feel comfortable automating manual tasks in


HyperMesh.

• Customize HyperWorks User Interface and


package your HyperWorks scripts as
extensions.

• Create custom GUI features such as


ribbons, toolbars and context guidebars.

3
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Altair HyperWorks Customization and Automation - Agenda


Training Sessions

HyperView
Intro to HyperMesh and
Tcl/Tk Automation HyperGraph
Automation

Session 1 Session 2 Session 3


• Introduction
• HM API Commands
• HM API to Enhance
Script Performance
• HM Entity Data
Names and
Attributes
• Extensions
• Exercises 2A-2S
• Q&A

4
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Session 2 - HyperMesh Automation


VIRTUAL

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

Session 2 - HyperMesh Automation


VIRTUAL

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

HyperWorks Reference Guide


Documentation

• Supplies help for the use of


Scripting Commands, Custom
Translators and similar functions
that allow advanced users to
customize how HyperWorks
behaves.
• The Reference Guides are broken
down by specific applications.
• There are separate guides for:
• HyperMesh
• HyperWorks
• Templex
• Math
• …

7
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

HyperWorks Reference Guide


Customization and Tools

• API (Application Programming Interface) Programmer's Guides: Provide


an overview of all additions, updates and changes to the HyperMesh client
APIs for each release.

• 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.

• FE Input Readers: C programs that read information from ASCII or binary


finite element models files into the HyperMesh Database.

8
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

HyperWorks Reference Guide


Customization and Tools

• HMASCII: Details on the HMASCII format and associated commands.


• Input Format, Output Format, Commands and Functions

• Scripts: This section contains details on general HyperWorks scripting


concepts, along with documentation on the Tcl commands that can be used
to query and modify the database and GUI:
• HyperMesh Customization via Tcl/Tk.

• Shell (command line) and script execution possible.

• 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

HyperWorks Reference Guide


API Programmer's Guides

Altair HyperWorks Online Help > HyperWorks Reference Guides >


• These provide an overview of all additions, updates, and changes to the
HyperMesh APIs for each release.

• 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.

• The documents should be used in conjunction with the HyperWorks Reference


Guide for more information on a specific command of interest.

10
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Tcl GUI
Commands

Altair HyperWorks Online Help > HyperWorks Reference Guides >

11
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Tcl Modify
Commands

Altair HyperWorks Online Help > HyperWorks Reference Guides >

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.

• on the command to see more details about Syntax, Type, Description…

13
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Tcl Query
Commands

Altair HyperWorks Online Help > HyperWorks Reference Guides >

14
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

HyperMesh Automation
What is it?

• An automatic or semi-automatic execution of a series of commands, steps or processes in


HyperMesh.

• 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?

• For repetitive tasks.

• For adjusting existing HyperWorks process with your standards.

• For dealing with I/O automations.

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.

• This launches the interactive Tk Console (TkCon)

• 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.

• In the Command Window you can…


• Evaluate any command that can be issued to Tcl or to HyperMesh through Tcl.

• 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.

• File > Load >

• 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.

• Controls the animation of the loaded results in the current page.

• Changes the colors of different entities, depending upon the arguments.

• Masks the elements based on the arguments supplied from the model loaded in the active window.

• Creates/edits a group of the displayed elements in the active window.

• Reads in model/results in a HyperView session.

• Sets the display style.


20
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

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.

Note: The Intellisense menu is available in the following products: HyperGraph


2D and 3D, HyperView, MediaView, MotionView, TableView, and TextView.
21
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Tips & Tricks - Tcl Console

• Increase Font Size in Tcl Console with the


command:
• tkcon font Courier 12 bold

22
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Tips & Tricks - Tcl Console

• Dock and Undock Parts of the User Interface

• and drag dotted rows to reposition parts of the User


Interface (such as browsers, toolbars...)

• For parts docked on the left and right side of the


application, the dotted arrows appear at the top, next to
the name.

23
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Tips & Tricks - Tcl Console

• Dock and Undock Parts of the User Interface

• For parts docked at the bottom of the application, the


dotted rows appear on the left side.

• Reposition your selection


holding and dragging

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.

• This file can be used to rerun operations or as a


basis for determining the commands required to
automate a given process.

• By default, the command file is written to the


Start-in Directory for each session.

• It is possible to customize the location where this


file is written to using the
HM_COMMANDFILE_DIR Environment Variable.

Note: On Linux, the command file is named command.tcl.


25
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Command File
Definition

• HyperMesh writes all commands used in a session to the command.tcl file.


• command.tcl file is an ASCII file that HyperMesh can read or write.

• 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

• Any command involving a path.

• *setvalue (optional).
27
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Questions & Answers

1. What does API stand for?


a) Adaptive Programming Interaction
b) Application Programming Interface
c) Advance Programming Interface

28
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Questions & Answers

2. What is the role of the command.tcl file?


a) Store HyperMesh settings after closing the application.
b) Pass commands to HyperMesh to be executed at the start
of the application.
c) Store the command history, i.e. commands representing
the operations executed interactively in HyperMesh.

29
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Questions & Answers

3. What information can you find in the API


Programmer's Guide?
a) List of HyperMesh API commands.
b) List of new HyperMesh commands and command updates
for a specific release.
c) Tips & tricks on how to create HyperMesh scripts.

30
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Session 2 - HyperMesh Automation


VIRTUAL

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

Beamsection Collectors beamsectioncols Beamsections beamsects Titles titles

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

• HyperMesh mark is a selection of entities on which HyperMesh can perform operations.


• HyperMesh stores the mark as a Tcl list of HyperMesh entity IDs.

• Any user selection of entities is stored in a mark.

• 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.

• HyperMesh marks remain in memory until they are cleared.


• Some commands clear marks automatically after execution. Some commands do not, therefore you must clear
manually (*clearmark).
34
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

HyperMesh API Commands


Creating HyperMesh Marks

• The syntax for the *createmarkpanel command is:


• *createmarkpanel entity_type mark_id message

entity_type Type of entity to be placed on the mark


mark_id ID of the mark to be created (1 or 2)
message Message to display to the user

• 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

HyperMesh API Commands


Creating HyperMesh Marks

• Create/Delete elements using the standard mark:


• *createmark elements 1 50 51 52

• *deletemark elements 1

• This *createmark command populates mark 1 with elements 50, 51, and 52.

• The *deletemark command deletes the elements contained on mark 1.

• Element IDs will not be consistent from model to model.

• 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

HyperMesh API Commands


Creating HyperMesh Marks

• Several options exist to make the *createmark command more general:


"all", "displayed", "by config", etc.

• Use the *appendmark() command to add entities to a mark:


*createmark elements 1 50 51 52
*appendmark elements 1 "by adjacent"
*deletemark elements 1

37
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

HyperMesh API Commands


Creating HyperMesh Marks

• Another option is to replace the *createmark command with *createmarkpanel.


• When executed, this command presents the user with a selection widget for the entity specified in the command.

*createmarkpanel elems 1 "Select target elements"

• If filling a mark with a list, eval must be used before *createmark.


set Elemlist "1 2 3 4"
eval *createmark elems 1 $Elemlist

38
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

HyperMesh API Commands


Creating HyperMesh Marks

• 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.

Example: Translates node 10 along the x axis by 5 units.

*createvector 1 1.0 0.0 0.0


*createmark nodes 1 10
*translatemark nodes 1 1 5.0

• Additionally, a normal and base point are required to define a plane:

*createplane 1 1.0 0.0 0.0 5.0 0.0 0.0


*createmark elements 1 "displayed"
*reflectmark elements 1 1

39
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

HyperMesh API Commands


Creating HyperMesh Marks

• 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 config": Select only quad, hexas, …

• "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

HyperMesh API Commands


Creating HyperMesh Marks - Interactive Mode

• 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

HyperMesh API Commands


Additional Operators

• Boolean operations between marks:


• *markintersection

• *marknointersection

• *appendmark: Add entities to an existing mark.

*createmark elements 1 50 51 52
*appendmark elements 1 "by adjacent"

• *clearmark: Purge a mark.

• *findmark: Find entities OR find attached entities (e.g. Elements attached to a rigid).

• *marktousermark: Replicates the mark as a user mark.

42
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

HyperMesh API Commands


Querying HyperMesh Marks

• 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

set ElemList [hm_getmark elems 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

HyperMesh API Commands


Useful Query Commands

• hm_entityinfo: Useful to check if an entity with a given name already exists.


hm_entityinfo exist component component_name

• 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

Commands Involving a Path


Overview

• Example of a command:
*feoutputwithdata "C:/../hmdesktop/templates/feoutput/optistruct/optistruct"
"D:/calcul/test.fem" 1 0 0 1 1

• Two types of paths to be distinguished:


• Installation path:

• "C:/../hmdesktop/templates/feoutput/optistruct/optistruct"

• User Input/Output file path:

• "D:/calcul/test.fem"

45
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Commands Involving a Path


Installation Path

• hm_info commands return different paths, linked to the installation:


• hm_info -appinfo ALTAIR_HOME - Altair Installation Directory

• hm_info -appinfo CURRENTWORKINGDIR - Actual Working Directory

• hm_info -appinfo SPECIFIEDPATH TEMPLATES_DIR - Current Template Directory

• 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

Commands Involving a Path


User Input/Output Path

• 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

Basic HyperMesh Input Widgets


hm_getstring

• hm_getstring passes a string value entered by the user:


hm_getstring ?option? ?message?

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

Basic HyperMesh Input Widgets


hm_getint - hm_getfloat

• hm_getint and hm_getfloat commands pass values by the user.


• hm_getint returns a user input integer value.

• hm_getfloat returns a user input floating point value.

• Both these commands have the same options as the hm_getstring command.

set force [hm_getfloat "Force" "Enter force value"]

49
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Using TCL to Control the HyperMesh Session


Limitations

• 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

Questions & Answers

4. How many concurrent selection marks does


HyperMesh officially support per entity type?
a) 1
b) 2
c) 3

51
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Questions & Answers

5. Which command prompts the user to select


entities interactively in the GUI?
a) *createmarkpanel
b) *createmark
c) *markintersection

52
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Questions & Answers

6. Which command allows user to interactively


input an integer value?
a) hm_getfloat
b) hm_getstring
c) hm_getint

53
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Exercise 2A - Using the Command Window

File Name and Location:


..\02-HyperMesh-Automation\Chapter-2\c_channel-tcl_vector.hm

HyperMesh commands used:


Exercise Objectives: • *createmark
• The purpose of this Exercise is to become familiar with using the • hm_info
Command Window for developing in Tcl. • hm_getmark

• 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 2B - Creating a Load Collector

File Name and Location:


No model file required.

HyperMesh commands used:


Exercise Objectives: • *collectorcreateonly
• The purpose of this exercise is to become familiar with the general process of
creating HyperMesh Tcl scripts.
• Define the task to be automated:
1. Create a Load Collector named Forces. A card image does not need to be specified for
the collector.
2. Extract commands from the command file and add them to your Tcl file.

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

Exercise 2C - Translating Elements

File Name and Location:


..\02-HyperMesh-Automation\Chapter-2\c_channel-tcl_vector.hm

HyperMesh commands used:


Exercise Objectives: • *createmarkpanel
• Give the users the option of selecting which elements to translate. • *translatemark
• Allow user to specify the translation magnitude using hm_getfloat command. • hm_getfloat
• You can test the macro using the file c_channel-tcl_vector.hm.
Tcl/Tk commands used:
• none
Exercise Hints:
• Creating a macro will not always be as simple as cutting and pasting commands from the command.tcl file (macros
being too restrictive).
• To generalize the macros so that they can be used on multiple models, the *createmark can be replaced with the
*createmarkpanel command that allows users to interactively select the entities.

56
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Exercise 2D - Creating Forces with User Specified Magnitude

File Name and Location:


..\02-HyperMesh-Automation\Chapter-2\c_channel-tcl_vector.hm

HyperMesh commands used:


Exercise Objectives: • *createmarkpanel
• The script will automate creating forces with a user defined magnitude. • *clearmark
• hm_getfloat
• Define the task to be automated:
1. Create a load collector named forces. Tcl/Tk commands used:
2. Request the user to select the nodes on which to apply a force. • set
3. Request the user to specify the magnitude of the forces to be created.
4. Create the forces and organize them into the 'forces' collector.

• You can test the macro using the file c_channel-tcl_vector.hm.

57
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Exercise 2E - Organizing and Translating Elements

File Name and Location:


..\02-HyperMesh-Automation\Chapter-2\c_channel-tcl_vector.hm

HyperMesh commands used:


Exercise Objectives:
• hm_getstring *collectorcreateonly
• Define the task to be automated:
• *createmarkpanel *movemark
1. Create a component collector with a user specified name.
• *clearmark *createvector
2. Select elements and move those elements into the new
component. • hm_getfloat *translatemark
3. Translate the elements in the new component by a user
specified distance in the z-direction.
• You can test the macro using the file Tcl/Tk commands used:
c_channel-tcl_vector.hm. • set

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

Session 2 - HyperMesh Automation


VIRTUAL

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

HM API to Enhance Script Performance


Impact Factors

• Two main factors impact the performance of HyperMesh scripts:

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.

2. Speed of the execution of HyperMesh Tcl API commands.

• 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

HM API to Enhance Script Performance


Preferences

• Via GUI: File menu > Preferences > HyperMesh > Performance

• Programmatically via Tcl API commands:


*setoption <option>=<value>

hm_getoption option

61
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

HM API to Enhance Script Performance


Commands

*setoption entity_highlighting <option>


• Enable/Disable entity highlighting
*setoption block_redraw <option> Option:
• Enable/Disable graphics update 0 – Off
1 – On
*setoption block_messages <option>
• Enable/Disable the display of info messages
*setoption block_error_messages <option>
• Enable/Disable the display of error messages
*setoption command_file_state <option>
• Enable/Disable the writing to the command file
hm_blockbrowserupdate <option>
• Enable/Disable the browser update

62
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Questions & Answers

7. How can you make your script run faster?


a) Use an efficient structure of your code.
b) Perform operations in bulk instead of per entity.
c) Disable unnecessary functionalities.

63
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Questions & Answers

8. Which Preferences category is the most relevant


from the perspective of script execution speed?
a) Application
b) Graphics
c) Performance

64
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Questions & Answers

9. What is the generic command allowing to


programmatically change Preferences settings?
a) *setpreferences
b) hm_setoption
c) *setoption

65
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Exercise 2F - Speed Up Your Script

File Name and Location:


..\02-HyperMesh-Automation\Chapter-3\

HyperMesh commands used:


Exercise Objectives: • *setoption
• Open the baseline.tcl script in a text editor and review the code. Looking at • hm_blockbrowserupdate
the code, can you interpret what the script does?
• Open the file Exercise_2F.hm and run the baseline script. Observe the
Tcl/Tk commands used:
elapsed time reported in the Tcl Console. Can you think of any ways to speed up
the execution? • clock
• Re-open the file Exercise_2F.hm and run the modified script • set
Exercise_2F.tcl from the folder. This script uses specific commands to • puts
speed-up the execution time. Observe the reported elapsed time. Has the
performance improved?
• Compare the two scripts side by side to understand the changes.

66
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Session 2 - Intro to HyperWorks Automation - HyperMesh Client


VIRTUAL

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

HyperMesh Entity Data Names and Attributes


Overview

• Every HyperMesh Entity has two types of data:

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

HyperMesh Entity Data Names and Attributes


What are Data Names?

• 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:

• HyperWorks Reference Guides > HyperMesh > Data Names

69
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

HyperMesh Entity Data Names and Attributes


How to access Data Names?

• Use hm_getvalue command which:


• Queries Data Names and Attributes on Entities.

• Returns the value of any type of Data Name or Attribute on an Entity.

• Also returns the value at a specific index for Array type of Data Names and Attributes.

hm_getvalue entity_type <select_type>=<selection> dataname=<data name or attribute


name/ID> ?row=<row_index>? ?column=<column_index>?

70
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

HyperMesh Entity Data Names and Attributes


hm_getvalue - Example

• Set the x component of a force with ID 12 to the variable force_x:

set force_x [hm_getvalue loads id=12 dataname=comp1]

• Some Data Names available for force loads:

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

HyperMesh Entity Data Names and Attributes


hm_getvalue - Example

• 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

HyperMesh Entity Data Names and Attributes


Pointers

• Several of the Data Names in the two tables are defined as pointers.

• A pointer is used to directly access Data Name of another entity.


• For example, the collector and node Data Names for force loads are 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.

• The additional Data Names are separated by a period/dot (.).

73
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

HyperMesh Entity Data Names and Attributes


Pointers - Examples

• The following are a few examples on how a pointer is used.


• To retrieve the node ID that load 12 is applied to :

set node_id [hm_getvalue loads id=12 dataname=node.id]

• To retrieve the y coordinate of the node that load 12 is applied to:

set node_id [hm_getvalue loads id=12 dataname=node.y]

• To retrieve the load collector name that contains load 12:

set ld_col [hm_getvalue loads id=12 dataname=collector.name]

74
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

HyperMesh Entity Data Names and Attributes


Pointers - Examples

• 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:

• set matID [hm_getvalue comps id=12 dataname=materialid]

• 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]

• Alternatively, the component collector has a material pointer Data 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:

• set matName [hm_getvalue comps id=12 dataname=material.name]

75
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Setting Data Names and Attributes


What are Solver Templates?

• Solver Templates define every solver specific attribute including Data Names, Attribute IDs,
Card Image formats, and the format of the Data upon Export.

• The *defineattribute command is used to define


attribute data names and IDs in a template file.

• 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

Setting Data Names and Attributes


Types of Attributes defined in Solver Templates

• 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.

• There are also a number of hm_attribute commands to query entity attributes.

77
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Setting Data Names and Attributes


Solver Attributes and Card Images

• 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

• An excerpt is shown below for several of the card image fields:


*defineattribute(E,1,real,none)

*defineattribute(G,2,real,none)

*defineattribute(Nu,3,real,none)

*defineattribute(Rho,4,real,none)

Note: The first argument in the *defineattribute command is the solver


Data Name. The second is the Attribute ID and the third is the Attribute Type.
78
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Setting Data Names and Attributes


Solver Attributes and Card Images

• Additionally, there are card image definitions that define how the card editor is generated inside of
HyperMesh for each attribute.

• For OptiStruct, these card images are defined in: <altair_home>/templates/feoutput/optistruct

• An excerpt of the OptiStruct MAT1 card image is shown below:


*menustring("MAT1 ")
*menufield(ID,integer,id,8)
*menufield(E,real,$E,8)
*menudefaultvalue(" ")
*menuinitialvalue(210000.0)
*menurestrictedvalue(>,0.0)

79
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Setting Data Names and Attributes


Solver Attributes and Card Images

• *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

Setting Data Names and Attributes


Search Data Names Strings

• Solver data names strings can be accessed by sourcing entity_attribute_table.tcl, and


selecting the entity.
<install_dir>/hwdesktop/demos/hm/examples/scripts/
entity_attribute_table.tcl

Example: Create a material (MAT1 card image) with default values


of Young’s Modulus, Density and Poisson’s Ratio.
• Source the script from File > Load > Script (*.tcl, *.tbc).

• Choose the material and click Apply.

• Table with Data Name Strings, Attributes IDs, Data Types and Value shown.

• Use hm_getvalue command and query the same attributes


and store in a variable.

81
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Setting Data Names and Attributes


Assigning Data to Solver Attributes

• 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

*setvalue mats id=1 cardimage="MAT1"

*setvalue mats id=1 STATUS=1 1=123

*setvalue mats id=1 STATUS=1 2=345

*setvalue mats id=1 STATUS=1 3=0.4

*setvalue mats id=1 STATUS=1 4=5e-009

82
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Setting Data Names and Attributes


*setvalue Command

• Creating or updating solver attribute of an existing solver card is done using *setvalue
command:
*setvalue mats id=2 STATUS=1 1=210000
• Where:

• mats is the type of entity that owns the attribute.

• 2 is the ID of the entity.

• STATUS=1 sets the attribute ON

• 1 is the identifier of the attribute.

• 210000 is the value of the attribute.

• 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

Setting Data Names and Attributes


Creating a Reusable and Modular Procedure

• 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 advantage of doing this is:


• Only need to pass the material name, color and the values for the material properties and the procedure will
create the material accordingly.

• 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.

• The hm_info command is used to find the appropriate template to load.


84
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Setting Data Names and Attributes


Procedure - Example

proc mat_create { name E Nu Rho } {

if {[hm_entityinfo exist mats $name -byname] == 1} {


hm_errormessage "Material $name already exists"
return;
} else {
*createentity mats cardimage=MAT1 name=$name
*createmark materials 2 "$name";
*setvalue mats name=$name cardimage="MAT1"
*setvalue mats name=$name STATUS=1 E=$E
*setvalue mats name=$name STATUS=1 Nu=$Nu
*setvalue mats name=$name STATUS=1 Rho=$Rho
return;
}
}

85
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Setting Data Names and Attributes


Use Procedure to Updating Solver Attributes

• 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.

proc mat_update { mat_id E Nu Rho } {


if {[hm_entityinfo exist mats $mat_id -byid] == 0} {
hm_errormessage "Material $mat_id does not exist"
return;
} else {
*setvalue mats id=$mat_id cardimage="MAT1"
*setvalue mats id=$mat_id STATUS=1 1=$E
*setvalue mats id=$mat_id STATUS=1 3=$Nu
*setvalue mats id=$mat_id STATUS=1 4=$Rho
return;
}
}
86
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Querying Data Names and Attributes


hm_attributelist Command

• The complete list of attributes for an entity can be retrieved using hm_attributelist command.

hm_attributelist material 1 name

MAT1 COMMENT_OPTION E G Nu Rho MAT1_A MAT1_TREF MAT1_GE MAT1_ST MAT1_SC

MAT1_SS MATS1 MATT1 MAT4_OPT MAT5_OPT MATFAT_OPT EXPL_MAT_OPT

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

Querying Data Names and Attributes


hm_getvalue Command

• Solver Data Names are accessed using hm_getvalue command.

• Example: Extract the value of E from a material with ID 11:


hm_getvalue mats id=11 dataname=E

Or

hm_getvalue mats id=11 dataname=1

88
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Querying Data Names and Attributes


Using Matrix Browser

• Matrix Browser allows users to extract information from the model


in an interactive way.

• Post ribbon > Query group >

• Once entities (nodes, elements, loads etc.) have been selected,


user has access to their Data Names, and can even ask for child
data names in case of a pointer.

89
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Querying Data Names and Attributes


Using Matrix Browser

• 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.

2. Select materials in the Entities block.

3. Click Query and choose the material in the graphics window.

90
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Querying Data Names and Attributes


Using Matrix Browser

• Example (continued): Query a material (MAT1 card image)


4
and its values of Young’s Modulus, Density and Poisson’s
Ratio.
4. A column is added to the table area with label materials and
populated with the IDs of the selected materials.

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.

Hint: As an extra activity, you can use hm_getvalue command


and query the same attributes in the Tcl Console.

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?

• hmcustom.tcl can be located in a number of different places.

• 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:

• Windows: Change the "Start-in" directory of the shortcut to HyperWorks.

• Linux: Set the Environment Variable as part of the startup script.

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.

• Typical use cases involve:


• Setting default element configurations.

• Prescribing certain preference values (e.g., geometry clean-up tolerance).

• 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

Questions & Answers

10.Using the hm_getvalue command, what entity


information can you query?
a) Only entity data names
b) Only entity solver attributes
c) Both entity data names and solver attributes

95
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Questions & Answers

11.Which command would you use to change the


value of an entity data name or solver attribute?
a) *valueset
b) *setentityvalue
c) *setvalue

96
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Questions & Answers

12.What is the name of the tool allowing you to


query entity data interactively?
a) Entity Browser
b) Matrix Browser
c) TableView

97
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Exercise 2G - Computing the Vector Sum of Forces

File Name and Location:


..\02-HyperMesh-Automation\Chapter-4\c_channel-tcl_vector.hm

Exercise Objectives: HyperMesh commands used:


• The purpose of this example is to become familiar with creating • *clearmark *createmarkpanel
HyperMesh Tcl scripts to retrieve data on HyperMesh entities • hm_getvalue hm_getmark
(nodes, elements, loads, etc.).
• hm_usermessage hm_errormessage
• Define the task to be automated:
1. Request the user to select forces.
2. If the user does not select loads, display a message stating Tcl/Tk commands used:
"No loads selected".
• brackets [ ]
3. Retrieve the X, Y, and Z component information from the
user-selected forces. • expr foreach
4. Sum the X, Y, and Z components. • if set
5. Display the resulting X, Y, and Z components. • return llength
• Test the macro using the file c_channel-tcl_vector.hm.
98
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Exercise 2H - Extracting Element Node Lists

File Name and Location:


..\02-HyperMesh-Automation\Chapter-4\c_channel-tcl_vector.hm

Exercise Objectives: HyperMesh commands used:


• Using the file c_channel-tcl_vector.hm, for each element in the • *createmark
HyperMesh model, build a list with the following content: • hm_getvalue
ELEMID {NODE1 NODE2 …}
• hm_getmark
• These lists should then be included in a list of lists:
{{ELEMID1 {NODE1 NODE2 …} {ELEMID2 {NODE1 NODE2…}…
Thus, generating a record of the element information. It is not necessary to report Tcl/Tk commands used:
this information to the user. • for foreach
Exercise Hints: • list lappend
• The majority of this assignment will be about discovering where to find • set incr
information about commands and how to apply the information you find.
• if elseif
Be patient and use the resources available to you, including the
Altair HyperWorks Online Help. • else
99
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Exercise 2I - Translating Components

File Name and Location:


..\02-HyperMesh-Automation\Chapter-4\c_channel-tcl_vector.hm

Exercise Objectives: HyperMesh commands used:


• Create a HyperMesh Tcl script to automate the • *createmarkpanel hm_getfloat
following task: • hm_getmark hm_getvalue
1. Request the user to select a component to be translated.
• *createvector *translatemark
2. Request the user to select a HyperMesh defined vector
along which the component is to be translated. • *clearmark
3. Get the x comp, y comp and z comp of the selected
vector from the HyperMesh Database.
Tcl/Tk commands used:
4. Request the user to enter translation distance.
• set
5. Use all of the above information to translate the selected
component.
• Test the macro using the file
c_channel-tcl_vector.hm

100
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Exercise 2J - Constructing 3D Elements from 2D Elements

File Name and Location:


..\02-HyperMesh-Automation\Chapter-4\c_channel-tcl_vector.hm

Exercise Objectives: HyperMesh commands used:


• Create a HyperMesh Tcl script to automate the following task: • *createmarkpanel *createmark
1. Create a node at the centroid of the element. • *createvector *translatemark
2. Translate the node in the positive direction of the element normal by • *createnode *createelement
an amount equal to the shortest diagonal of a quad element and the
shortest side of a tria element. • *collectorcreate *currentcollector
3. Create either a tetra element or a pyramid element using the original • hm_getmark hm_getvalue
element node list and the new node created by the script.
• hm_entityinfo
• Test the file using HyperMesh file c_channel-tcl_vector.hm.

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 2K - Creating Elemental Systems

File Name and Location:


..\02-HyperMesh-Automation\Chapter-4\c_channel-tcl_vector.hm

Exercise Objectives: HyperMesh commands used:


• Create a HyperMesh Tcl script to automate the following task: • *createmarkpanel *createnode
1. Request the user to select elements on which to create a system. • *clearmark *hm_getvalue
2. Get the centroidal coordinates of each element. • hm_getmark *system
3. Create a node at each of these centroidal locations. • hm_entityinfo
4. Create systems using these nodes as origin nodes and elemental node1
and node2 as orientation nodes.
Tcl/Tk commands used:
• Test the file using HyperMesh file c_channel-tcl_vector.hm.
• set for foreach eval
• lindex llength
Exercise Hints:
• The majority of this assignment will be about discovering where to find information about commands and how to apply the
information you find. Be patient and use the resources available to you, including the Altair Hyperworks Online Help.
102
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Exercise 2L - Extracting Material Data

File Name and Location:


No model file required.

Exercise Objectives: HyperMesh commands used:


• The purpose of this exercise is to become familiar with creating HyperMesh • hm_getvalue
Tcl scripts which automate extracting data from HyperMesh card images
(i.e. entity solver attributes).
• Define the task to be automated: Tcl/Tk commands used:
1. Create an OptiStruct MAT1 material of ID 1 in HyperMesh Database. • set return
2. Extract from its card image its values for the parameters Young’s modulus (E), • proc tk_messageBox
shear modulus (G), Poisson’s ratio (Nu), and density (Rho).
3. Display the values for the parameters.

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 2M - Defining Material Data

File Name and Location:


No model file required.

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

Exercise 2N - Defining/Updating Multiple Materials

File Name and Location:


No model file required.

Exercise Objectives: HyperMesh commands used:


• The purpose of this exercise is to illustrate how to define/update materials. • *setvalue
• Define the task to be automated: • *createmark
1. Automate defining three OptiStruct MAT1 materials with values for the parameters • *createentity
Young’s modulus (E), shear modulus (G), Poisson’s ratio (Nu), and density (Rho).
• hm_getmark
2. If the materials exist in HyperMesh, simply update the values, otherwise create a
new material before setting the parameters.
3. The three materials are: Tcl/Tk commands used:
NAME E G NU RHO • set proc
Aluminum 0.70E+05 0.26E+05 0.33 2.70E-09 • foreach
Steel 2.10E+05 0.81E+05 0.30 7.85E-09
Titanium 1.15E+05 0.44E+05 0.32 4.50E-09

105
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Exercise 2O - Creating a PSHELL Property

File Name and Location:


No model file required.

Exercise Objectives: HyperMesh commands used:


• Generate a procedure to create a property collector with a • hm_errormessage *createmark
PSHELL Card Image in the OptiStruct template. • *setvalue hm_getmark
• Ask the user to supply a Thickness value. • hm_getfloat *createntity
• Try to incorporate checks into the procedure to avoid errors.
• For example, if a property with that name already exists,
what happens? Tcl/Tk commands used:
• set if

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

Exercise 2P - Scaling Material Properties

File Name and Location:


No model file required.

HyperMesh commands used:


Exercise Objectives: • *createmark *setvalue
• Use your script from Exercise 2N to generate material entities in a • *hm_allentitiesinfo
new model. • *hm_getvalue
• Generate a procedure to scale the values of the Young’s
modulus, shear modulus and density in each of the materials
that exist in your model. Tcl/Tk commands used:
• Scale the Young’s modulus and shear modulus by a factor of • proc lindex set
100 and the density by a factor of 10. • expr foreach
• Do not scale the value of Poisson’s ratio.

107
MORE TO EXPLORE
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Following Slides / Exercises:

Suggested usage for GTT sessions

Add the More to Explore section.


It includes few more details.

108
MORE TO EXPLORE
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Exercise 2Q (Optional) - Automate Model Setup

File Name and Location:


..\02-HyperMesh-Automation\Chapter-4\

Exercise Objectives: HyperMesh commands used:


1. Interactively create a 100x100mm mesh. • *createmarkpanel

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

Session 2 - Intro to HyperWorks Automation - HyperMesh Client


VIRTUAL

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

Extensions - Migrating to New Interface

How can I create custom pulldown menus in


the new interface?
→ Use Extensions!

How can I create custom toolbars?


→ Use Extensions!

Is it possible to create custom ribbons


and icons?
→ Use Extensions!

111
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Extensions
Overview

• Programs integrated with HyperWorks to


enhance or extend user experience.
• Extensions allow user to customize the user
interface by adding extra menus, ribbons and
linking them to custom functionalities

• Framework concept available to any


Unity-based application.

• Support for all HyperWorks Clients.

• Add a new Extension from:


• File > Extension Manager > Add Extension.

• Navigate to your working directory and select the


Extension folder.
112
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Extensions
2022.1 Highlights

Multi-Client Support Extension Manager Custom Toolbars


• All HyperWorks Clients are supported. • Common across all applications • Custom toolbars can be defined
using Extensions. together with custom ribbon pages
• One extension can include custom and pulldown menus.
content for multiple clients. • Detailed view providing more
information and links to extension
location or documentation.

113
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Extensions
Extension Manager

• Multiple extensions can be loaded at the same time.


• Once registered via Extension Manager and loaded, the extensions are automatically loaded on
subsequent application launches.

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.

• Init.tcl can be used as alternative to hmcustom.tcl.

• 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

<action tag="MyAction" … command="context:


command="scontext:2DMeshRebuild"
MyCustomCtx"
command="tcl: *createnode 0 0 20/>
/>
0 0 0" />

<action tag="MyAction" … command="tcl: source C:/MyScripts/script1.tcl" />

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.

• The profile section defines which client the


custom content is for (HyperMesh,
HyperView etc.)
• Other keywords such as resources,
ribbonxml, tclscript, toolbars etc. are
optional depending on whether an extension
contains such features.

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

Develop and Deploy your Custom Solutions Faster

Altair Community - Develop and Deploy Your


Custom Solutions Faster

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

• Guidebar definition • itcl class definition


• Selector • Methods
• Action buttons • Business logic
• … • …
• Microdialog • Registration of the context
• … and the class
125
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

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…

Tcl Command Description

ctx Interaction with active context

ctx::manager Context management (enter, exit, register)

ctx::selection Interaction with active context selector

ctx::ui Control of the context UI

hm_pushpanel "rebuild mesh" ctx::manager enter 2DMeshRebuild


126
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

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.

• Example: Renumber Context

127
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Context Automation
Step 2

• Enter the context.


ctx::manager enter <context_tag>

• The print method from the previous slide


gives us the context tag, so we have all
necessary information to automate entering the
context.

128
VIRTUAL
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Context Automation
Step 3

• Assuming the context requires entity selection, define it:


• First, get the selection name by entering it and running the following command:

ctx::selection active

• Note: You can also see the selection name in the context XML DOM.

• Second, add entities to the context selection:

ctx::selection add <selection_name> <method>

• Methods: displayed, all, byid <list_of_ids>

• 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.

ctx GetOption renumber_minmaxinfoflag


>>> 1

ctx SetOption renumber_minmaxinfoflag 0


ctx GetOption renumber_minmaxinfoflag
>>> 0

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

• After the action execution, we will exit the context:


ctx exit

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 enter RenumberByIds


set selName [ ctx::selection active ]

set listOfEnts [ hm_getexistingentitytypes ]

foreach ent $listOfEnts {


ctx::selection set $selName -type $ent
ctx::selection add $selName all
ctx SetOption renumber_minmaxinfoflag 0
ctx SetOption renumber_startid 150000
ctx Proceed
}

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 2R - Bring it all Together with Extensions

File Name and Location:


..\02-HyperMesh-Automation\Chapter-4\

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

Following Slides / Exercises:

Suggested usage for GTT sessions

Add the More to Explore section.


It includes few more details.

137
MORE TO EXPLORE
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Demo - Context APIs

File Name and Location:


..\02-HyperMesh-Automation\Demo\
context_apis.tcl and Tune_the_bracket.hm

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 2S (Optional) - Context Tcl API Commands

File Name and Location:


..\02-HyperMesh-Automation\Extension folder

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

Exercise 2S (Optional) - Context Tcl API Commands

Step 1: Load Extension


a) Open a new HyperMesh Client session.
b) File > Extension Manager > Add Extension. Navigate to your working directory with the Extension folder provided
and activate the extension.
c) Custom Tools and Custom Menu ribbons will appear in the interface with customized Toolbars.

140
MORE TO EXPLORE
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Exercise 2S (Optional) - Context Tcl API Commands

Step 2: Organize the Assembly


a) Custom Tools ribbon > Demo group > . The .hm file available inside ..\Extension\data\HM folder
will be loaded in the Graphical Interface.
b) Before proceeding with meshing operations, we need to organize solids into separate components.

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

Exercise 2S (Optional) - Context Tcl API Commands

Step 3: Surface Mesh a Component

a) Mesh ribbon > 2D Mesh group > >

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.

d) Before meshing, to adjust the element size through APIs, type:


ctx SetOption "CONTEXTS/hm/2DMeshCreation/elemsize" 0.001

e) Check the modification with: ctx GetOption "CONTEXTS/hm/2DMeshCreation/elemsize"

142
MORE TO EXPLORE
© Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.
Altair HyperWorks Customization and Automation, v2022.1

Exercise 2S (Optional) - Context Tcl API Commands

Step 3: Surface Mesh a Component


f) Get the name of the active selector:
set selname [ctx::selection active]

g) Select the component with ID 23:


ctx::selection add $selname "by comp id" 23

h) You can click the Mesh button or use the API command: ctx Proceed

i) Exit the tool with: ctx::manager exit

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

Questions & Answers

144
Your Feedback Matters
Training feedback survey

#ONLYFORWARD
THANK YOU
altair.com

#ONLYFORWARD
DISCOVER CONTINUOUSLY.
ADVANCE INFINITELY.
Visit altair.com to learn more.

#ONLYFORWARD

You might also like