Showing posts with label ansa scripts examples. Show all posts
Showing posts with label ansa scripts examples. Show all posts

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











. 









Sunday, January 10, 2016

ANSA Scripting Examples For Beginners | Ansa Scripting 1

ANSA Scripting Basics

Here, my intention to focus on the basics of ANSA scripting. So, let’s start, before going to ANSA scripting, I hope, you have a background in python programming especially it’s subdomain object-oriented programming & functional programming. I am expected at least you have beginner level knowledge in programming. 

Computer aided engineering ansa scripting
Source: Unsplash

Here I don’t want to share the basics of python programming, it’s free & available everywhere. Without a wastage of time, let’s start.


  • ANSA scripting totally depends upon python programming & beta solutions developed their own libraries which are useful for while ANSA scripting. 
  • If you want to build your personal GUI you can do it as you wish with the Tkinter widget tool available default inbuilt in ANSA. (GUI means small application or window the same as a mobile application.

  • Sometimes, a question arises in a beginner's mind, what is this Tkinter? Don’t worry, in common language, its tool kit available for python by which you can develop your own application or software.

  • Most of the details like how to open a scripting window in ANSA, how to execute a code, or basic tool knowledge is available on YouTube please go through it. Here I can’t share any photos & Videos of any software because it might be created copyright issues for me, unfortunately after that I unable to continue all this stuff.

  • Yes, I will share some basic script, please execute it on your ANSA platform. It will help you a lot to understand & build logic behind the ANSA scripting, after that, you will able to build a script for your own problem statements.
Ansa python scripting
Source: Unsplash

Basic ANSA script No. 1

If you want to print or see the all PID in lsdyna deck. You can go through this basic script & I know it’s not a big deal to see all PID in ANSA. Initially, this type of scripts plays an important role to build logic in complex scenarios.

Code available in green color & copy & execute it on ANSA scripting window.

 

import ansa

from ansa import *

rushi=base.CollectEntities(constants.LSDYNA, None, "__PROPERTIES__", )

print(len(rushi))

for i in rushi:

                print(i._name)

               

Here ansa is a python library developed by beta solutions. base.CollectEntities is function in library & constants.LSDYNA shows you are using the LSDYANA deck.

 

Basic ANSA script No. 2

If you have lots of PID & want to see the name of the exact PID you can go through this script. Here default PID is 25, you can check the title of it easily.

 

import ansa

from ansa import *

def main():

 name_of_part= base.GetEntity(constants.LSDYNA, "__PROPERTIES__", 25,)

 print(name_of_part._name)

main()

if __name__ == '__main__':

                main()

 

In the search panel of the Ansa script if you search any function and double click on it you will get a help option at the base it helps a lot while scripting in ANSA.

 
Basic ANSA script No. 3

If you want to print all PID & name In front of it you can go through this script. I am increasing the complexity level step by step I hope you will understand.

 

import ansa

from ansa import *

id_collector=[]

name_collector=[]

def main():

                part_name=base.CollectEntities(constants.LSDYNA, None, "__PROPERTIES__", False, True)

                for i in part_name:

                    id_collector.append(i._id)

                    name_collector.append(i._name)

                    pass

main()

zip_list=list(zip(id_collector, name_collector))

for points in zip_list:      

    print(points)

if __name__ == '__main__':

                main()

 

Here I use a zip function to add to the list together & if you search on google about the details of the zip function you will get it easily, so I will not go in-depth of python terms do its own place. & if __name__ == '__main__':  this code is useful to call main function & to stop looping.

 

ANSA scripting
Source: Unsplash 

Conclusion

I hope you will get the basic idea about ANSA scripting, in an upcoming post, I will use real examples that will be useful while meshing work as well as deck preparation work. Also, I will share how can we use python & its different libraries in finite element analysis & design. Thank you. Excuse me for English grammar I already start working on it. 


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


 

 

 

 

Thank you !

Search This Blog

Contact Form

Name

Email *

Message *