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.
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.
Source: Unsplash |
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.
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.
No comments:
Post a Comment