当前位置:网站首页>Ansa secondary development - two methods of drawing the middle surface

Ansa secondary development - two methods of drawing the middle surface

2022-07-28 16:34:00 CaeCoder


  ANSA It is a very powerful and fast pre-processing software , Anyone who has used it knows ,ANSA In geometric cleanup 、 The model simplification function is particularly prominent . More Than This ,ANSA It also provides a python Language secondary development interface , It greatly meets the needs of users . The basic idea behind scripting language is to automate many repetitive and cumbersome procedures with minimal user interaction , that ANSA The interface provided meets this requirement . It is believed that users who have drawn shell grids are familiar with this function , However, it is also a manual and repetitive work , Now we will introduce two uses ANSA Secondary development to extract the middle surface .

( One ) Use Skin Command the middle face .

First of all, let's introduce what we need API( Below API Are based on ansa.base library ):

  1. CollectEntities This method is used to collect entities , It returns a list of collected entities .

  2. GetEntityCardValues This method is used from the following figure “Card” Get on the pid、mid And so on .

 Insert picture description here    Its return value is a dictionary .

  1. CollectNewModelEntities Collect newly created or imported model entities . It returns an object , You have to use report() Method returns a list to collect entities . The sample code is as follows :

   The sample 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))

Be careful : There must be del collector.

  1. SetEntityCardValues Set or change ”Card” The value of the parameter in .

  2. CheckAndFixGeometry Check and automatically clean geometry , He returns a dictionary containing error information or None.

  3. Besides, there are Or(),All(),ZoomAll(),Compress(‘’) And so on .

   Now let's introduce the program logic :

   Our program is for an assembly , So there will be many Part, So you must use a loop to take out each one in turn Part To operate . First collect all entities , And then use For Loop through each Part To operate . First use Or() And ZoomAll() Show a single entity , And then use CheckAndFixGeometry Perform automatic geometric cleanup , If there are no mistakes , Then go to the next step ( If there is an error, it indicates that it cannot be cleaned automatically , It needs to be cleaned by hand ). Next, you need to collect entities ‘FACE’, If the collected entity is not empty , Then we will collect ’FACE’ Conduct Skin Middle face . Next, according to “PSHELL” To collect new entity objects .“PSHELL” That is, as shown in the figure below ‘Card’

   And then execute report() Method to get a new entity list . If the length of this list is not zero , Then through the GetEntityCardValues Method to get new PID Information , And then through SetEntityCardValues Method to set attribute information . Finally using All() and ZoomAll() Show all entities , Reuse Compress() Just compress .

   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('')

( Two ) Use Casting Middle face .

   There's not much to talk about here , Method logic is basically not much different , Do you understand API You can view the help documentation . Go straight to 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
Date of publication : 2017-07-17


   Scan the QR code below to follow my wechat official account - CAE Second development of software Lab, Read more about !

CAE Second development of software Lab
原网站

版权声明
本文为[CaeCoder]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/209/202207281523121100.html