CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   ANSA (https://www.cfd-online.com/Forums/ansa/)
-   -   ansa model browser script (https://www.cfd-online.com/Forums/ansa/232301-ansa-model-browser-script.html)

hobing December 8, 2020 19:45

ansa model browser script
 
hi.

example
model browser open > 'A' part , 'B' part , ..... 'Z' part

1. I want to see each part in order according to a certain time.
How do I create a script?

please help me

thank you!

greg.cfd December 16, 2020 11:14

Hi, what do you mean by "according to a certain time."?

hobing December 20, 2020 23:20

sorry, I didn't explain it right

all i want to say is if i can see each part by name
i'm practicing my ANSA script
next script is example

import os.path
from os.path import expanduser
import ansa
from ansa import base
from ansa import utils
import time

home = expanduser("./path")
abs_filename_1 = os.path.join(home, 'image1.png')

def main():
t=time.time()
base.Open("./path/file_name.ansa")
base.SetViewButton({"SHADOW": "on", "VIEWMODE": "PID", "GRIDs": "off", "PERIMs": "off", "PERIM_POINTs": "off"})
set_view = base.SetViewAngles(f_key="F10")
status = utils.SnapShot(abs_filename_1, image_format='PNG', transparent=True, text_axes=False)
if status == 0:
print('Image saved in ' + abs_filename_1)



main()


this script can only be taken as a whole, but i want to take a snapshot by part

greg.cfd December 21, 2020 09:40

You need to collect all parts and then loop over them using a for loop. To collect entities in ANSA you can use base.CollectEntities().
Then use base.Or() to isolate each part on the screen:



Code:

import os.path
from os.path import expanduser
import ansa
from ansa import base
from ansa import utils
import time

home = expanduser("./path")
abs_filename_1 = os.path.join(home, 'image1.png')

def main():
    t=time.time()
    base.Open("./path/file_name.ansa")
    base.SetViewButton({"SHADOW": "on", "VIEWMODE": "PID", "GRIDs":"off", "PERIMs": "off", "PERIM_POINTs": "off"})
    all_parts = base.CollectEntities(constants.OPENFOAM, None, 'ANSAPART')
    for part in all_parts:
        base.Or(part)
        set_view = base.SetViewAngles(f_key="F10")
        status = utils.SnapShot(abs_filename_1, image_format='PNG', t    ransparent=True, text_axes=False)
        if status == 0:
            print('Image saved in ' + abs_filename_1)



main()


hobing December 22, 2020 01:59

wow.. thank you !

Is it possible for each Properties ID or properties NAME I designated, not by part?

greg.cfd December 23, 2020 07:09

Yes you can collect all PIDs using:


pids = base.CollectEntities(constants.OPENFOAM, None, 'SHELL_PROPERTY')


and then:


for pid in pids:
base.Or(pid)
...
...


All these are basic ANSA-entity and python interactions and you can find more info under:
Help Menu>Documentation Index>Scripting>Guides>ANSA & META Python API

hobing December 23, 2020 19:44

I'm doing it little by little, and it really helps a lot. Thanks for letting me know. You're a genius!!!!

I'm sorry, but can I ask you one more question?
what does base.Or mean??

greg.cfd December 24, 2020 03:54

You're wellcome. base.Or() is the script equivalent of the OR focus command in GUI. It isolates entities on the screen (keeps them visible while hiding everything else).

You can see what each script function does in its help text in the script editor. Search for the function in the search list and double click on it to get the help text.


All times are GMT -4. The time now is 01:57.