WE ARE TOGETHER !

Thursday, November 12, 2020

HyperMesh Scripting Tcl/Tk Helpful For Beginners | Hypermesh Scripting 1

HyperMesh Scripting Tcl/Tk


HyperMesh Scripting | I want to highlight HyperMesh scripting with sharp examples. Before going to the depth, Initially, I will target basic questions which are usually generated in a beginner's mind. I hope, you will have a background in any programming language.


Hypermesh Tcl scripting 

What is a HyperMesh Macro? 

It is a scripted or command file used to automate a series of steps in HyperMesh.


But Why do we need it? 

To save time in repeated work.

 

What is Tcl/Tk? 

Tcl (Tool Command Language) is a scripting as well as a programming language.


It is invented by John Osterhout in 1989. It is easy to read, write & understand.


Tk (Tool kit) is a widget tool that is useful while creating of GUI (Graphics User Interface), in simple language, GUI means mobile application but here it is a computer application.


If you want to learn Tcl/Tk language, I will suggest the platform - Tutorialspoint


Below, I have given some initial hints which are helpful while scripting the scripting panel. 


This is an interpreted language. In HyperMesh scripting panel commands execute in line-by-line order same as the python programming scenario. If you notice well, After a run a single command it shows 1 or 0 entity it means,


1 show - command is executed.


0 shows - the command is not executed.


Unfortunately, there is no command to stop the script while running. I told you this basic because you might be facing issues like being trapped in an infinite loop. 

 

HyperMesh doesn't allow us to work with their entities like elements, nodes, sets, etc. there is a solution for this, and that is the concept available in HyperMesh scripting Mark.


Marks specify groups of entities that are transferred to the command processor. Marks can be created for entities like nodes & elements. Marks can create up to 2 times and it has their id. every time initially you have to need to call mark while scripting.


If you want to delete generated marks, you can use *clearmarkall or hm_markclear Elem 1 these commands as well as to maintain simplicity in the default scripting panel in hypermesh you can use clear command. 


If you observe well, you will find that hypermesh scripting code is not the same as Tcl scripting language so questions arise! What is that change?


Syntax of hypermesh scripting does not contain any parentheses and commas; they have been replaced with a blank space. Notice that while the parentheses and commas have been removed, each of the commands still begins with an asterisk (*) and that the command name hasn’t changed.


For example:

*setmeshlinecolor(6) = * setmeshlinecolor 6

*jpegfile() = *jpegfile

 

 

This scripting language is an interpreted language. It’s executed line by line you can compare it with python scripting. 

 

Hypemesh scripting panel

 

Basic Hyperscript Script No 1


Here, if you want to know all Component IDs in the deck you can try this script. At the initial stage, this type of script will help you to build a large logic & script. (Code is in green color. let’s execute it in the scripting panel.)

 

*createmark comp 1 all

set all_comp_id [hm_getmark comp 1]

puts $all_comp_id

 

 

Basic Hyperscript Script No 2

Here if want to know the number of nodes or elements on your screen you can execute this program, it will help you a lot with the understanding of how the program is executed in Hypermesh script.

 

*createmark elem 1 "displayed"

hm_marklength elem 1

 

or

 

*createmark node 1 "displayed"

hm_marklength node 1

 

Basic Hyperscript Script No 3

If you want to print the name as well as the component id you can try this program. Also in this program, you will get aware of how to use loops in hypermesh scripting.

 

*createmark comp 1 all

set comp_id [hm_getmark comp 1]

puts "id of all deck: $comp_id

 

foreach terms $comp_id  {

set name [hm_getvalue comp id =$terms dataname=name]

puts $name

}

 

Please check my other post I hope you will find it more interesting there. 

Thank you for your attention.


Conclusion:


I hope, you will get a basic idea of HyperMesh scripting & Tcl/Tk. In upcoming videos, I will come with more advanced scripts & I will teach how to generate buttons in the utility menu & attach a Tcl script to it with tool kit knowledge. Sorry for the English I am working on it. Thank you so much for your time.

#hypermesh scripting 

#hypermesh scripting for beginners.



No comments:

Post a Comment

Thank you !