当前位置:网站首页>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 !

边栏推荐
- el-input限制只能输入规定的数
- Two of C language programming!! Role of
- Early in the morning, pay Bora SMS to say that you won the "prize"? Dealing with server mining virus - kthreaddi
- The epidemic dividend disappeared, and the "home fitness" foam dissipated
- 疫情红利消失,「居家健身」泡沫消散
- c语言编程当中两个!!的作用
- A program for judging the result of cyclic input
- HM secondary development - data names and its use
- 500million users, four years earlier than wechat... This app, which has been in operation for 15 years, will be permanently discontinued
- Dynamic programming -- digital statistics DP
猜你喜欢

nowcode-学会删除链表中重复元素两题(详解)

解决电脑恶意广告弹窗的思路

Sort 4-heap sort and massive TOPK problem

Sort 1-insert sort and Hill sort

Stm32cube infrared remote control: input capture

I can only sell the company after the capital has been "cut off" for two years

Using pyqt to design gui in ABAQUS

排序1-插入排序与希尔排序

Introduction and implementation of queue (detailed explanation)

Configure HyperMesh secondary development environment on vs Code
随机推荐
Brief tutorial for soft exam system architecture designer | software debugging
ANSA二次开发 - 在PyCharm上搭建ANSA/META二次开发环境
视频号找到金钥匙,抖音模仿后来人
Baidu editor ueeditor, when editing too much content, the toolbar is not visible, which is not convenient for editing or uploading problems
Rosen's QT journey 101 models and views in QT quick
Sort 2 bubble sort and quick sort (recursive and non recursive explanation)
LwIP development | socket | DNS domain name resolution
Sdl2 concise tutorial (4): using SDL_ Image library importing pictures
MySQL view event status statements and modification methods
ANSA二次开发 - Apps和ANSA插件管理
Reentrant and non reentrant
魏建军骑宝马也追不上李书福
一小时内学会Abaqus脚本编程秘籍
Learn ABAQUS script programming script in an hour
"Weilai Cup" 2022 Niuke summer multi school training camp 3 h.hacker sam+ segment tree /dp/ divide and conquer (without the largest sub segment and of the inspection interval)
Roson的Qt之旅#101 Qt Quick中的模型和视图
Detectron2 installation and testing
Multiple commands produce ‘.../xxx.app/Assets.car‘问题
About standard IO buffers
php关于数据量大导出数据或者遍历数据导致内存溢出超时等问题