WE ARE TOGETHER !

Sunday, November 15, 2020

ANSA Scripting Examples For Beginners | Ansa Scripting 2

ANSA Scripting Examples For Beginners

Ansa scripting | Hello friends, once again I come up with some more basic ansa scripts which will be helpful for you to understand ansa scripting logic. I hope, you already go through my past post where I have mentioned their script. without wastage of time let's start. 


Basic ANSA script No. 4


If you want to highlight or delete the face which is under 5 mm area or as per your specified values of the area.

Might be this question has generated in your mind, but why? Why we should use this script?

Sometimes while we going through shell meshing or plastic meshing. first, we have to generate mid surface & due to complexity, it generates small faces. These faces are too tiny. human eyes unable to detect it or work with it properly. 

This work is tedious & time-consuming. This issue has frequently seen in complex plastic meshing. 

At the same, you can use the following script to resolve or save time & reduce complexity in the work panel temporarily.

The script is available in pink color :

import ansa 
from ansa import *

total_faces=base.CollectEntities(constants.LSDYNA, None, "FACE", False, True)

for each_face in total_faces:
area=base.GetFaceArea(each_face)
small_faces=[]
faces_area=[]
if area <10 :
faces_area.append(area)
small_faces.append(each_face)
print(small_faces)
base.DeleteFaces(small_faces)
# you can only highlight the faces which are under the 10 mm 

If you have any doubts or reverse questions, don't be hesitate to comment. I am a student & want your favor in the sense of some new ideas. 

Basic ANSA script No. 5


If you want to check which are the faces do not mesh & still have pending to mesh. for this, you can go through the following command. which is very helpful in especially plastic meshing or complex zone. 

print(mesh.UnmeshedMacros())

Conclusion:

I introduced an effective example of ansa scripting in geometry clean-up work. I hope you have a background in python programming & understand the importance of programming/scripting. In the upcoming post, I will use data science - python libraries to explore LSDYNA output files like glstat, nodout, matsum, etc.

Thank you for your attention. 

#ansa scripting
#ansa automation
#data science in finite element analysis




















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.



Thank you !