当前位置:网站首页>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 ):
CollectEntities This method is used to collect entities , It returns a list of collected entities .
GetEntityCardValues This method is used from the following figure “Card” Get on the pid、mid And so on .
Its return value is a dictionary .
- 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.
SetEntityCardValues Set or change ”Card” The value of the parameter in .
CheckAndFixGeometry Check and automatically clean geometry , He returns a dictionary containing error information or None.
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 !

边栏推荐
- 百度编辑器ueditor,编辑内容过多时,工具栏不可见,不方便编辑或上传问题
- Ansa secondary development - Introduction to interface development tools
- LwIP development | socket | DNS domain name resolution
- A program for judging the result of cyclic input
- 微软100题-天天做-第11题
- 微信公众号获取素材列表
- 疫情红利消失,「居家健身」泡沫消散
- IT远程运维是什么意思?远程运维软件哪个好?
- 微软100题-天天做-第16题
- mysql 查看事件状态语句和修改办法
猜你喜欢

ANSA二次开发 - Apps和ANSA插件管理

栈的介绍与实现(详解)

Use js direct OSS to store files in Alibaba cloud and solve the limitation of large file upload server

Paging query in applet

QT打包

ANSA二次开发 - Visual Studio Code上搭建ANSA二次开发环境

Several methods of HyperMesh running script files

Ansa secondary development - Introduction to interface development tools

Early in the morning, pay Bora SMS to say that you won the "prize"? Dealing with server mining virus - kthreaddi

HM二次开发 - Data Names及其使用
随机推荐
LwIP development | socket | TCP | client
ANSA二次开发 - Apps和ANSA插件管理
1. Simple command line connection to database
LeetCode每日一练 —— 剑指Offer 56 数组中数字出现的次数
Dynamic programming -- digital statistics DP
Geodetic coordinate system to Martian coordinate system
leetcode 题目
500million users, four years earlier than wechat... This app, which has been in operation for 15 years, will be permanently discontinued
遭MQ连连干翻后的醒悟!含恨码出这份MQ手册助力秋招之旅
HM二次开发 - Data Names及其使用
flashfxp 530 User cannot log in. ftp
el-input限制只能输入规定的数
Stm32cube infrared remote control: input capture
Reentrant and non reentrant
Rosen's QT journey 102 listmodel
ANSA二次开发 - 在PyCharm上搭建ANSA/META二次开发环境
SDL2 简明教程(四):用 SDL_IMAGE 库导入图片
CoDeSys realizes bubble sorting
关于web对接针式打印机问题,Lodop使用
I'll show you a little chat! Summary of single merchant function modules