ANSA自动附属性

2024年4月22日
此代码为烂尾代码,只对shell单元进行了处理,并且处理补全,相信对初学者能起到一定的引导作用
脑图如下:
在这里插入图片描述
代码如下:
#2024/

PYTHON script

import ansa
import re
from ansa import base
from ansa import constants

#SET script
def create_set(name):
my_set = base.CreateEntity(constants.LSDYNA, ‘SET’, {‘Name’: name})
n = 1
while not my_set:
my_set = base.CreateEntity(constants.LSDYNA, ‘SET’, {‘Name’: name + str(n)})
n += 1
return my_set
def main():
#create already_set
already_redefine_set = create_set(‘already_redefine_set’)
#define ‘mm’
section_mm = ‘mm’
#define lsdyna section keyword
entity_sets = [‘SECTION_SHELL’, ‘SECTION_SOLID’, ‘SECTION_BEAM_ELFORM_1’, ‘SECTION_BEAM_ELFORM_2’, ‘SECTION_BEAM_ELFORM_9’]
section_sets = [‘DYNA_SECTION_SHELL’,‘DYNA_SECTION_SOLID’,‘DYNA_SECTION_BEAM_ELFORM_1’,‘DYNA_SECTION_BEAM_ELFORM_2’,‘DYNA_SECTION_BEAM_ELFORM_6’,‘DYNA_SECTION_BEAM_ELFORM_9’,‘DYNA_SECTION_DISCRETE’,‘DYNA_SECTION_SEATBELT’]
#pickup property to redefine section
preselected = []
print(“please pick up section_shell”)
preselected.append(base.PickEntities(constants.LSDYNA, entity_sets[0]))
print(“please pick up section_solid”)
preselected.append(base.PickEntities(constants.LSDYNA, entity_sets[1]))
print(“please pick up section_beam_elform_1”)
preselected.append(base.PickEntities(constants.LSDYNA, entity_sets[2]))
print(“please pick up section_beam_elform_2”)
preselected.append(base.PickEntities(constants.LSDYNA, entity_sets[3]))
print(“please pick up section_beam_elform_9”)
preselected.append(base.PickEntities(constants.LSDYNA, entity_sets[4]))
ready_to_redefine_set = create_set(“ready_to_redefine_set”)
x = 4
while x > -1:
base.AddToSet(ready_to_redefine_set, preselected[x])
x = x -1
#collect sction
precollection = []
precollection.append(base.CollectEntities(constants.LSDYNA, None, section_sets[0]))
print(‘shell_section is collected’)
precollection.append(base.CollectEntities(constants.LSDYNA, None, section_sets[1]))
print(‘solid_section is collected’)
precollection.append(base.CollectEntities(constants.LSDYNA, None, section_sets[2]))
print(‘elform_1_section is collected’)
precollection.append(base.CollectEntities(constants.LSDYNA, None, section_sets[3]))
print(‘elform_2_section is collected’)
precollection.append(base.CollectEntities(constants.LSDYNA, None, section_sets[4]))
print(‘elform_6_section is collected’)
precollection.append(base.CollectEntities(constants.LSDYNA, None, section_sets[4]))
print(‘elform_9_section is collected’)

#difine section shell
for prop in preselected[0]:
    val = base.GetEntityCardValues(constants.LSDYNA, prop, ('Name',))
    prop_name = val.get('Name')
    mm_index = prop_name.find(section_mm)
    result = prop_name[:mm_index].split('_')[-1]
    length = len(result[result.find('p'):])
    new_result = result.replace('p', '.')
    if length == 2:
        new_result = new_result + '0'
    #find section for new_result 
    for section in precollection[0]:
        sect = base.GetEntityCardValues(constants.LSDYNA, section, ('Name',))
        sect_name = sect.get('Name')
        if sect_name.find('type16') > -1:
           if sect_name.find(new_result) > -1:
                pid = base.GetEntityCardValues(constants.LSDYNA, section, ('SECID',))
                print(pid)
                num = pid['SECID']
                base.SetEntityCardValues(constants.LSDYNA, prop, {'SECID': pid['SECID']})
                print('section already repalce',pid)
                base.AddToSet(already_redefine_set, prop)

for section in precollection[0]:

print(‘section name is %s,id is %d’,section)

#redifne 

if name == ‘main’:
main()

  • 8
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值