CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   ANSA (https://www.cfd-online.com/Forums/ansa/)
-   -   Compress PID - Python script (https://www.cfd-online.com/Forums/ansa/206900-compress-pid-python-script.html)

stefat September 18, 2018 03:51

Compress PID - Python script
 
Hey Guys!
I would like to ask for a help.
I need a Python script to Compress all the PIDs with same thickness in a model. Always keep the lower PID-ID and put all the Entities from the other properties to the one is kept.


I have found a easy way to compress Materials with the same name and/or same values, but coudnt find this feature for PIDs.
Mostly we are working with NASTRAN or LS-DYNA.
I hope someone can help me with it.
Thanks in advance!

Mrt23 September 18, 2018 07:13

i don't know how to do this by scripting.
but you can show only elements/entities/etc with the same thickness. then select all shown entities/elements/etc->modify->PID->set some
and compress=)
easy=)

Mrt23 September 18, 2018 07:17

but be carfully, because you will have problems with hiding/showing some entities if you keep only 1 PID... but if you doesn't work with huge assembles it isn't a issue to you=)

stefat September 18, 2018 07:26

Hi!
Thanks for the reply.


This is actually what we are doing, but i need a script to do it with a single click.
Btw i'm working on the script, but i'm not so good with python so i'm kinda suffering to write it.


Sometimes our single-part models have several PIDs with the same tickness and if we have like 30 different thicknesses, then making the compression manualy (like you assumed) takes time.
I just need a script for this to do it in secounds instead or minutes.

Mrt23 September 18, 2018 07:35

it takes secund, you are quite right-it is ot 1 click.
but ANSA is good in hide/show possibilities!
in data manager sort by thickness->show only and do that i write =) it takes 10-15 seconds if you have a 100 pids with the same thickness=)
but if you want to scripting...) it will be great.)

greg.cfd October 15, 2018 10:58

Hi,


You can try something like:


Code:

# PYTHON script import os
 import ansa
 from ansa import *
 

 def main():
    deck = constants.NASTRAN
    shell_props = base.CollectEntities(deck, None, 'PSHELL')
    props_with_same_thickness = {}
    for prop in shell_props:
        vals = base.GetEntityCardValues(deck, prop, ['T'])
        prop_thickness = vals['T']
        props_with_same_thickness.setdefault(prop_thickness, [])
        props_with_same_thickness[prop_thickness].append(prop._id)
   
    for key, values in props_with_same_thickness.items():
        if len(values) >= 2:
            print('Merging PIDs with thickness: ', key)
            print('-------------------------------------------')
            min_id = min(values)
            min_pid = base.GetEntity(deck, 'PSHELL', min_id)
            for x in values:
                if x != min_id:
                    current_pid = base.GetEntity(deck, 'PSHELL', x)
                    shells = base.CollectEntities(deck, current_pid, 'SHELL', recursive = True)
                    print('Assigning SHELLS of PID: ', x, ' to PID: ', min_id)
                    for shell in shells:
                        base.SetEntityCardValues(deck, shell, {'PID':min_id})
            print('-------------------------------------------')
   
    base.Compress({'Properties':1})
 

 

 if __name__ == '__main__':
    main()

Best regards,
Greg

stefat October 16, 2018 05:00

Thank You very mutch!


It's working like a charm!


:)


All times are GMT -4. The time now is 05:15.