首页/文章/ 详情

曲面分组与属性自动化创建脚本解析

9月前浏览701


在有限元前处理流程中,将几何曲面归类到指定组件并分配属性是一项基础且重复的工作。本文将介绍一款自动化脚本,该脚本可根据用户选择的曲面,批量创建对应的组件(Component)和属性(Property),并完成属性与组件的关联,显著提升模型组织效率。

脚本核心功能与代码展示

该脚本的核心功能是:通过用户选择的曲面列表,为每个曲面自动创建独立的组件、PSHELL类型属性,并将曲面移动到对应组件中,同时完成属性与组件的绑定。以下是完整脚本代码:

  #created by Blaise Cole
#From user selection, this will create 1 component and 1 property and organize that surface into said component

#Ask user to select the elements
*createmarkpanel surfs 1                
set surface_list [hm_getmark surfs 1]


#For each surface in the surflist, we pass that ID and make a component and property (PSHELL), and assign the property to the component
set counter 1
foreach s $surface_list {
    set property_id [expr {$counter}]
    *createentity comps includeid=0 name="Panel$counter"
    *clearmark components 1
    *createmark surfaces 1$s
    *movemark surfaces 1"Panel$counter"
    *clearmark surfaces 1
    *createentity props cardimage=PSHELL includeid=0 name="$counter"
    *setvalue comps name="Panel$counter" propertyid=$property_id
    *setvalue props id=$property_id materialid={mats 1}
    *setvalue props id=$property_id STATUS=195=1
    incr counter
}
*clearmark surfs 1

脚本执行流程详解

脚本采用“用户交互→批量处理→资源清理”的逻辑设计,具体流程分为三个关键步骤:

1. 用户选择曲面

  *createmarkpanel surfs 1                
set surface_list [hm_getmark surfs 1]
  • • 第一行通过*createmarkpanel surfs 1命令弹出曲面选择面板,允许用户在HyperMesh图形界面中手动框选一个或多个曲面(surfs代表曲面实体类型,1为标记集编号)。
  • • 第二行通过hm_getmark surfs 1获取用户选中的所有曲面ID,存储在变量surface_list中,形成待处理的曲面列表。

2. 批量创建组件与属性并关联

这部分是脚本的核心逻辑,通过foreach循环遍历surface_list中的每个曲面,为其执行“创建组件→移动曲面→创建属性→关联属性”的完整流程:

  set counter 1  # 初始化计数器,用于命名组件和属性
foreach s $surface_list {  # 遍历每个选中的曲面(s为当前曲面ID)
    set property_id [expr {$counter}]  # 将计数器值作为属性ID
    
    # 创建组件:名称为"Panel+计数器"(如Panel1、Panel2)
    *createentity comps includeid=0 name="Panel$counter"
    
    # 将当前曲面移动到新创建的组件中
    *clearmark components 1  # 清除组件标记集1的历史数据
    *createmark surfaces 1$s  # 将当前曲面标记到曲面标记集1
    *movemark surfaces 1"Panel$counter"  # 将标记的曲面移动到"Panel$counter"组件
    
    # 清除曲面标记集1,为下一次循环做准备
    *clearmark surfaces 1
    
    # 创建PSHELL类型属性:名称为计数器值(如1、2)
    *createentity props cardimage=PSHELL includeid=0 name="$counter"
    
    # 将属性分配给对应的组件
    *setvalue comps name="Panel$counter" propertyid=$property_id
    
    # 配置属性参数:关联材料ID为1的材料,设置状态为激活
    *setvalue props id=$property_id materialid={mats 1}
    *setvalue props id=$property_id STATUS=195=1  # STATUS=1表示属性激活,95=1为特定参数配置
    
    incr counter  # 计数器自增,确保下一个曲面的组件和属性名称唯一
}

关键操作说明:

  • • 组件命名规则:采用“Panel+数字”格式(如Panel1、Panel2),确保每个组件名称唯一,便于模型管理。
  • • 属性类型:创建cardimage=PSHELL类型的属性,PSHELL是壳单元常用的属性卡片,适用于板壳类模型。
  • • 属性配置:通过*setvalue命令为属性关联材料(materialid={mats 1}表示关联ID为1的材料),并设置状态为激活(STATUS=1)。
  • • 关联逻辑:组件与属性通过propertyid绑定,确保组件中的曲面使用指定属性进行有限元分析。

3. 清理临时标记

  *clearmark surfs 1

脚本最后通过*clearmark surfs 1清除曲面标记集1的内容,避免临时标记占用资源,确保HyperMesh环境整洁。

脚本优势与适用场景

核心优势

  • • 自动化批量处理:替代手动为每个曲面创建组件、属性并关联的重复操作,尤其适合包含大量曲面的模型。
  • • 命名规范统一:组件和属性按计数器自动命名,避免人工命名的混乱,便于后续模型检索与管理。

使用说明与注意事项

  1. 1. 运行环境:需在HyperMesh中执行,支持曲面操作。
  2. 2. 材料准备:脚本默认关联ID为1的材料(materialid={mats 1}),运行前需确保模型中已存在ID为1的材料,或根据实际需求修改材料ID。
  3. 3. 选择注意事项:用户在*createmarkpanel面板中需选择曲面,否则脚本可能无法 正常执行。
  4. 4. 参数调整:若需修改属性类型,可将cardimage=PSHELL替换为对应卡片名称;若需调整属性厚度参数,可修改*setvalue props后的参数值(如95=1可根据分析需求调整)。


来源:TodayCAEer
HyperMesh材料曲面
著作权归作者所有,欢迎分享,未经许可,不得转载
首次发布时间:2025-12-19
最近编辑:9月前
TodayCAEer
本科 签名征集中
获赞 87粉丝 197文章 781课程 2
点赞
收藏
作者推荐
未登录
还没有评论
课程
培训
服务
行家
VIP会员 学习计划 福利任务
下载APP
联系我们
帮助与反馈