Scripting Journey
The first script I remember writing was to create a set of nodes within a certain distance of a selected node. A simple concept, but since it was my first I was pretty proud when I finished. Looking back now, I am not even sure how much of the script I wrote because it has someone else’s name right in the comments of the code. So, I am pretty sure I took a script that accomplished something similar and made slight modifications. I am not saying this is bad. I think it is probably a great place to start and can save a bunch of time even when you are more experienced. The other thing I noticed about the script is that it contained 72 lines of code (including comments) and can be done with the following lines of code:
*createmarkpanel node 1 “Select center node”
set nodeCoords [hm_getvalue nodes id=[hm_getmark nodes 1] dataname=coordinates]
set radius [hm_getfloat “Radius of selection sphere” ]
hm_createmark nodes 2 "by sphere" "$nodeCoords $radius inside 1 1 0"
*createentity set type=1 ids=[hm_getmark nodes 2]
It also had a 7 in the title of the script, meaning it was my 7th version or attempt (wow). I only had to run the code above twice because I had one typo. I am guessing it probably took me longer to write the original code then it will to write this whole blog and I am the only one that ever used it, and I only used it at the time I wrote it and have not used it since. Again, you have to start somewhere, but it is interesting to look back and laugh a little.
Fast forward to my most recent script. First off, I was asked to do this script rather than just coming up with a script on my own. So, I knew it would actually be useful and used if it was done well. I was asked to help speed up a fatigue model setup workflow in OptiStruct. With some of the sticking points being the addition of hundreds of properties to cards (EL2PROP, FATDEF) one by one and having to use a separate module to calculate some material properties. When the script is run, the user selects materials to consider (those with a “NOT_INTERESTED” in the name are filtered out) then the following GUI comes up to get the rest of the user inputs.
When all these fields are filled out, the user hits “OK” and something that used to take hours is done in a few minutes.
Nothing really earth shattering here, but I got good feedback and was pretty proud of how it turned out. The link at the bottom of the blog contains the script and related model.
Feel free to share your scripting experiences in the comments or share your thoughts on the questions below. Thanks for reading.
What scripts have you found most helpful?
Do you usually write scripts for yourself or others?
For what have you written a script and then found out similar functionality is already available, and you just didn't know about it?
Fatigue Automation Script and Test Model