愿与您一同,用代码提升效率!

import hmimport hm.entities as ent# 测试脚本运行时间用 timeitimport timeitdef performance(model, switch):if switch == True: hm.setoption(# 控制图形界面是否刷新# Controls the graphics redraw# 0 Allows redraw# 1 Blocks redraw block_redraw=1,# 是否写出command# The state of writing to the command file.# 0 - Disable writing to the command file# 1 - Enable writing to the command file command_file_state=0,# 是否预高亮选择的entity# The mode for pre-highlighting selected entities.# 0 - Do not pre-highlight. This may improve script performance.# 1 - Pre-highlight entity_highlighting=0, )# Controls the update of the browsers in HyperMesh client# 0 – Unblocks the browser updates and populates the buffered data into the browser.# 1 – Blocks the browser updates and starts buffering the data. model.hm_blockbrowserupdate(mode=1)else: hm.setoption( block_redraw=0, command_file_state=1, entity_highlighting=1, ) model.hm_blockbrowserupdate(mode=0)def split_solid(): model = hm.Model()# 为需要分组的solid 新建collection solidcol = hm.CollectionByInteractiveSelection(model, ent.Solid)#使用for循环,遍历每一个solid,并创建一个component,以solid ID 命名component#然后将solid移动中对应的component中 performance(model, True)for solid in solidcol:#创建component comp = ent.Component(model)#重命名component comp.name = f"solid_{solid.id}"# Organize (move) the solid to the new component# 老版本hypermesh中的Shift+F11功能# 为solid 新建一个collection filterBen = hm.FilterByEnumeration(ent.Solid, list([solid.id])) solid_col = hm.Collection(model, filterBen)# organize solid 到对应conponent (Shift+F11) model.movemark(collection=solid_col, name=f"solid_{solid.id}") performance(model, False)split_solid()split_solid_time = timeit.timeit(split_solid,number=1)print(f"split solid time is {split_solid_time:.8f}s")# 1.60715560s💡提示
文中代码来自HyperMesh帮组文档,基于帮组文档有微调。
往期文章
CAE仿真 网格评价中的雅可比为什么是0-1?及参数单元是什么
HyperMesh Python二次开发 选择实体对象(Entity Selection)collection基础用法
HyperMesh Python二次开发-自动修改Component名字
10分钟快速了解HyperMesh Python 二次开发(附源码-创建一个4节点shell单元)