CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Mesh Generation & Pre-Processing Software > ANSA

Compress PID - Python script

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree4Likes
  • 4 Post By greg.cfd

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 18, 2018, 04:51
Post Compress PID - Python script
  #1
New Member
 
Tibor Stefanovics
Join Date: Aug 2018
Posts: 6
Rep Power: 6
stefat is on a distinguished road
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!
stefat is offline   Reply With Quote

Old   September 18, 2018, 08:13
Default
  #2
Member
 
Join Date: Mar 2018
Posts: 56
Rep Power: 6
Mrt23 is on a distinguished road
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 is offline   Reply With Quote

Old   September 18, 2018, 08:17
Default
  #3
Member
 
Join Date: Mar 2018
Posts: 56
Rep Power: 6
Mrt23 is on a distinguished road
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=)
Mrt23 is offline   Reply With Quote

Old   September 18, 2018, 08:26
Post
  #4
New Member
 
Tibor Stefanovics
Join Date: Aug 2018
Posts: 6
Rep Power: 6
stefat is on a distinguished road
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.
stefat is offline   Reply With Quote

Old   September 18, 2018, 08:35
Default
  #5
Member
 
Join Date: Mar 2018
Posts: 56
Rep Power: 6
Mrt23 is on a distinguished road
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.)
Mrt23 is offline   Reply With Quote

Old   October 15, 2018, 11:58
Default
  #6
New Member
 
Join Date: May 2014
Posts: 21
Rep Power: 10
greg.cfd is on a distinguished road
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
greg.cfd is offline   Reply With Quote

Old   October 16, 2018, 06:00
Thumbs up
  #7
New Member
 
Tibor Stefanovics
Join Date: Aug 2018
Posts: 6
Rep Power: 6
stefat is on a distinguished road
Thank You very mutch!


It's working like a charm!


stefat is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[OpenFOAM] Using python script for automatic post processing of openFoam vPaquet ParaView 12 December 16, 2021 04:30
python script to create geometry for salome, and then mesh 6863523 Mesh Generation & Pre-Processing 4 March 18, 2017 10:00
[General] Transfer variables into python script from bash-shell cfdFreshman ParaView 0 December 3, 2015 04:33
[General] Python script: Auto-scale color scale julien.decharentenay ParaView 2 December 9, 2013 06:39
CentFOAM Python Script Installation: Error socon009 OpenFOAM Installation 2 May 26, 2012 10:36


All times are GMT -4. The time now is 20:30.