ANSA is a very powerful and fast pre-processing software. As everyone who has used it knows, ANSA is particularly outstanding in geometric cleaning and model simplification. Moreover, ANSA also provides a secondary development interface based on python language, which greatly meets the needs of users. The basic idea behind the scripting language is to automate many repetitive and cumbersome programs with minimal user interaction, so the interface provided by ANSA meets this demand. It is believed that users who have drawn the shell mesh are familiar with the function of drawing the middle surface. However, it is also a manual and repetitive work. Next, we will introduce two methods of drawing the middle surface using ANSA secondary development.
(1) Use the Skin command to center the face.
First, let's introduce the required APIs (the following APIs are based on ansa.base Library):
-
CollectEntities is used to collect entities. It returns a list of collected entities.
-
GetEntityCardValues is used to obtain the values of pid, mid and other parameters from the "Card" shown in the figure below.
its return value is a dictionary.
- CollectNewModelEntities collects newly created or imported model entities. It returns an object and must use the report() method to return a list to collect entities. The example code is as follows:
the example code is as follows:
import ansa from ansa importbase def main(): collector = base.CollectNewModelEntities() n = base.CreateEntity(ansa.constants.ABAQUS, 'NODE') new_entities = collector.report() del collector print(len(new_entities))
Note: there must be del collector here
-
SetEntityCardValues sets or changes the value of the parameter in "Card".
-
CheckAndFixGeometry checks and automatically cleans up the geometry. It returns a dictionary or None containing error information.
-
In addition, there are auxiliary methods such as Or(),All(),ZoomAll(),Compress(').
the following describes the program logic:
our program is For an assembly, so there will be many parts, so we must use a cycle to take out each Part in turn For operation. First collect all entities, and then use the For loop to operate on each Part in turn. First use Or() and ZoomAll() to display a single entity, and then use CheckAndFixGeometry For automatic geometric cleaning. If there is no error, proceed to the next step (if there is an error, it indicates that automatic cleaning cannot be performed and manual cleaning is required). Next, we need to collect the entity 'FACE'. If the collected entity is not empty, we will Skin the collected 'FACE' to draw the middle FACE. Next, collect new entity objects according to "PSHELL". "PSHELL" is the "Card" as shown in the figure below
then execute the report() method to get the new entity list. If the length of this list is not zero, get new PID information through GetEntityCardValues method, and then set property information through SetEntityCardValues method. Finally, use All() and ZoomAll() to display all entities, and then use Compress() to compress them.
the complete code is as follows:
import ansa from ansa importbase from ansa importconstants def Test(): all_parts =base.CollectEntities(constants.NASTRAN, None, "ANSAPART") print(len(all_parts)) i=0 for part in all_parts: base.Or(part) n=base.ZoomAll() vals_1 = ('Name', 'PID') part_info =base.GetEntityCardValues(constants.NASTRAN, part, vals_1) options=['CRACKS','OVERLAPS','NEEDLEFACES','COLLAPSED CONS', 'UNCHECKED FACES'] fix=[1,1,1,1,1] ret=base.CheckAndFixGeometry(part,options,fix,True,True) if ret==None: faces=base.CollectEntities(constants.NASTRAN,part,'FACE') if len(faces) != 0: collector =base.CollectNewModelEntities(constants.NASTRAN, 'PSHELL') num_shell_deions=base.Skin(apply_thickness=True,new_pid=True,offset_type=2,ok_to_offset=True,max_thickness=5.0,delete=True,entities= faces) new_entities =collector.report() print(len(new_entities)) if len(new_entities) != 0: vals_2 =('Name', 'PID' ,'T') new_pid_info=base.GetEntityCardValues(constants.NASTRAN,new_entities[0], vals_2) vals_3={'Name':"S"+part_info[vals_1[0]]+"_"+str(new_pid_info[vals_2[2]]),} base.SetEntityCardValues(constants.NASTRAN,new_entities[0], vals_3) del collector print("num . "+str(i)+" :"+new_entities[0]._name) i += 1 base.All() m=base.ZoomAll() base.Compress('')
(2) Use Casting to center the face.
I won't talk about it here. The method logic is basically not much different. If you don't know the API, you can view the help document. Directly on the code.
import ansa from ansa import base from ansa import constants def mid_Casting(): all_pshell =base.CollectEntities(constants.NASTRAN, None, "PSHELL") print(len(all_pshell)) i = 0 for pshell inall_pshell: print("pshell_name: "+pshell._name) if pshell._name[0] != "S": collectorPshell = base.CollectNewModelEntities(constants.NASTRAN,'PSHELL') collectorShell = base.CollectNewModelEntities(constants.NASTRAN,"SHELL") all_faces = base.CollectEntities(constants.NASTRAN,pshell,"FACE") result = base.MidSurfAuto(faces = all_faces, thick=5., length=1, elem_type=3, join_distance=0.5, paste_triple_len=0.5, exact_middle=True, handle_as_single_solid=False, part="use_current") base.DeleteEntity(pshell, True) new_Pshell = collectorPshell.report() print("The new pshell's length is : ", len(new_Pshell)) print("The new Pshell's name is :",new_Pshell[0]._name) new_Shell = collectorShell.report() print("The new Shell's number is :", len(new_Shell)) AnsaPartReference = base.GetEntity(constants.NASTRAN,"SHELL",new_Shell[0]._id ) print("The AnsaPartReference's id is :", AnsaPartReference) CurrentPart = base.GetEntityPart(AnsaPartReference) CurrentPartName = base.GetEntityCardValues(constants.NASTRAN, CurrentPart,("Name",)) print("The CurrentPartName is :",CurrentPartName["Name"]) base.SetEntityCardValues(constants.NASTRAN, new_Pshell[0],{"Name": "C"+CurrentPartName["Name"]}) del collectorPshell del collectorShell i+=1
Reprinted from: https://www.sohu.com/a/157864134_744423
Original author: finite element Online
Published on: July 17, 2017
Scan the bottom two dimensional code, pay attention to my WeChat official account - CAE software two development Lab, read more wonderful content!