15
Innovation Intelligence ® 1 Chapter 4: Using TCL to Control the HyperMesh Session

Innovation Intelligence ® 1 Chapter 4: Using TCL to Control the HyperMesh Session

Embed Size (px)

Citation preview

Page 1: Innovation Intelligence ® 1 Chapter 4: Using TCL to Control the HyperMesh Session

Innovation Intelligence®

1

Chapter 4: Using TCL to Control the

HyperMesh Session

Page 2: Innovation Intelligence ® 1 Chapter 4: Using TCL to Control the HyperMesh Session

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

2

Using Tcl to Control the HyperMesh Session - Overview

Topics Presented:• HyperMesh commands vs. Tcl Modify Commands• Tcl GUI Commands and Tcl Query Commands

• Basic HyperMesh Input Widgets• Common HyperMesh Tcl Commands

• Using the Command Window• Example: Using the Command Window• Process to Create a Tcl HyperMesh macro• Example: Automate Creating Forces with a User Specified

Magnitude

Page 3: Innovation Intelligence ® 1 Chapter 4: Using TCL to Control the HyperMesh Session

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

3

Using Tcl to Control the HyperMesh Session - Overview

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

• Using the previous example, 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.

Page 4: Innovation Intelligence ® 1 Chapter 4: Using TCL to Control the HyperMesh Session

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

4

• The HyperMesh commands which were presented in the previous chapter are also available through their Tcl Modify commands

• Notice that while the parentheses and commas have been removed, each of the commands still begin with an asterisk (*) and that the command name hasn’t changed.

• In addition to the syntax change, Tcl core commands can also be used.

HyperMesh commands vs. Tcl Modify Commands

Macro in userpage.mac file Tcl Script

*beginmacro("macroJpeg") Not used in Tcl

*setbackgroundcolor(255,255,255)*setbackgroundcolor 255 255 255

*setmeshlinecolor(6) *setmeshlinecolor 6

*jpegfile() *jpegfile

*setbackgroundcolor(0,0,0) *setbackgroundcolor 0 0 0

*setmeshlinecolor(0) *setmeshlinecolor 0

*endmacro() Not used in Tcl

Page 5: Innovation Intelligence ® 1 Chapter 4: Using TCL to Control the HyperMesh Session

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

5

Tcl GUI Commands and Tcl Query Commands

• HyperMesh Tcl GUI commands make changes/updates in the HyperMesh GUI

• HyperMesh Tcl Query Commands query the HyperMesh database for information.

• These commands have the prefix “hm_”.

• We will go over two basic HyperMesh input widgets and a table of common commands.

Page 6: Innovation Intelligence ® 1 Chapter 4: Using TCL to Control the HyperMesh Session

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

6

Basic HyperMesh Input Widgets

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

Page 7: Innovation Intelligence ® 1 Chapter 4: Using TCL to Control the HyperMesh Session

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

7

Basic HyperMesh Input Widgets

• hm_getint and hm_getfloat passes values entered 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”]

Page 8: Innovation Intelligence ® 1 Chapter 4: Using TCL to Control the HyperMesh Session

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

8

Common HyperMesh Tcl Commands

hm_answernext

Force an answer to the next *command hm_answernext "yes" *deletemodel

hm_blockmessages

Inform HyperMesh whether or not messages should be displayed in header message bar

hm_elemlistReturn list of element ids for passed component id

hm_entityinfoGet information about entities in current model

hm_entitylist

Get list of names or IDs of all entities of the requested type in current model

hm_entitymaxidReturn maximum ID in use for an entity type

hm_errormessageDisplay error message in header message bar

hm_getclosestnodeReturn ID of closest node to point x y z

hm_getentityvalueGet information for an entity using the HyperMesh template interface

hm_getfilenameGet filename from user using HyperMesh file panel

hm_getfloatGet floating point value from user using HyperMesh panel

hm_getintGet integer value from user using HyperMesh panel

hm_getmarkGet ids for passed entity type on passed mark mask

hm_getstringGet text string from user using HyperMesh panel

hm_infoGet general information about HyperMesh

hm_markclearClear IDs for entity type from passed mark mask

hm_nodelistGet list of node IDs for passed element

hm_nodevalue Get XYZ values for passed node ID

hm_usermessageDisplay message in HyperMesh header message bar

Page 9: Innovation Intelligence ® 1 Chapter 4: Using TCL to Control the HyperMesh Session

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

9

Using the Command Window

• An interactive Command Window is provided and can be access through the View menu.

• This launches the Tk Console (TkCon) which is an interactive console which comes with Tk.

• In the Command Window, users can evaluate any command that can be issued in Tcl or in HyperMesh through Tcl.

• Such as ls, pwd, and cd can be used within the Command Window.

Page 10: Innovation Intelligence ® 1 Chapter 4: Using TCL to Control the HyperMesh Session

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

10

Using the Command Window

• General Tcl and HyperMesh specific Tcl commands can also be entered.

• For example, let’s use the HyperMesh specific Tcl command hm_info with the following options:

hm_info –appinfo SPECIFIEDPATH TEMPLATES_DIR

• This returns the current template directory.

• Using the Command Window provides the automation tool developer an easy means 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

Page 11: Innovation Intelligence ® 1 Chapter 4: Using TCL to Control the HyperMesh Session

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

11

Example: Using the Command Window

• The purpose of this example is to become familiar with using the Command Window for developing in Tcl.

• HyperMesh Tcl and core Tcl commands will be used in the Command Window to determine the number of elements in a component collector for a pre-defined HyperMesh model.

• The following commands are used in this exercise:• Modified HyperMesh commands:

*createmark()• HyperMesh Tcl commands

hm_infohm_getmark

• Core Tcl commandslistllengthsetsource

Page 12: Innovation Intelligence ® 1 Chapter 4: Using TCL to Control the HyperMesh Session

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

12

Process to Create a Tcl HyperMesh macro

• This process is nearly identical to developing a HyperMesh Basic macro except:

• The HyperMesh commands must be converted to Tcl format • Tcl core commands are allowed to introduce control logic to the automation

tools.

• Define the task.• Delete the existing command.cmf file. This file is located in either the start-in

directory or the current working directory.• Perform the operations in HyperMesh that the script should run.• Extract the commands from the command.cmf.• Create a Tcl script by converting the commands to Tcl format and modifying

as necessary (this includes adding additional Tcl commands)• Create a new Utility menu macro that runs a Tcl script.• Add macro button using *createbutton that calls the macro created in Step

6 with the appropriate Tcl script filename.• Reload the current .mac file into HyperMesh to load the modified

userpage.mac.• Test the macro.

Page 13: Innovation Intelligence ® 1 Chapter 4: Using TCL to Control the HyperMesh Session

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

13

Example: Automate Creating Forces with a User Specified Magnitude

• In this example, we will go through the general process for creating HyperMesh Tcl scripts.

• The script will automate the creating of forces with a user defined magnitude.

• The following commands are used in this example:• Modified and added HyperMesh commands:

*createmark*clearmark

• HyperMesh Tcl commands:hm_getfloat

• Core Tcl commands:set

Page 14: Innovation Intelligence ® 1 Chapter 4: Using TCL to Control the HyperMesh Session

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

14

Practical Exercises

Exercise 4aDescription

Create a HyperMesh Tcl script to automate the following task• Create a component collector with a user specified name• Select elements and move those elements into the new component collector.• Translate the elements in the new component collector a user specified distance in the z

direction.

HyperMesh commands usedhm_getstring *collectorcreateonly*createmarkpanel *movemark*clearmark *createvector hm_getfloat *translatemark

TCL/TK commands usedset

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

Page 15: Innovation Intelligence ® 1 Chapter 4: Using TCL to Control the HyperMesh Session

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

15

Practical Exercises

Exercise 4bDescription

For each element in a HyperMesh model, build a list where the contents of the list are as follows

ELEMID {NODE1 NODE2 …} These lists should then be included in a list of lists:

{{ELEMID1 {NODE1 NODE2 …} {ELEMID2 {NODE1 NODE2 …} …

HyperMesh commands used*createmark hm_getmark

hm_nodelist

TCL/TK commands usedfor foreach list

lappend set incrif elseif else

HintsThe majority of this assignment will be 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 HyperWorks online help.