在有限元前处理流程中,将几何曲面归类到指定组件并分配属性是一项基础且重复的工作。本文将介绍一款自动化脚本,该脚本可根据用户选择的曲面,批量创建对应的组件(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 脚本采用“用户交互→批量处理→资源清理”的逻辑设计,具体流程分为三个关键步骤:
*createmarkpanel surfs 1
set surface_list [hm_getmark surfs 1] *createmarkpanel surfs 1命令弹出曲面选择面板,允许用户在HyperMesh图形界面中手动框选一个或多个曲面(surfs代表曲面实体类型,1为标记集编号)。hm_getmark surfs 1获取用户选中的所有曲面ID,存储在变量surface_list中,形成待处理的曲面列表。这部分是脚本的核心逻辑,通过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 # 计数器自增,确保下一个曲面的组件和属性名称唯一
} cardimage=PSHELL类型的属性,PSHELL是壳单元常用的属性卡片,适用于板壳类模型。*setvalue命令为属性关联材料(materialid={mats 1}表示关联ID为1的材料),并设置状态为激活(STATUS=1)。propertyid绑定,确保组件中的曲面使用指定属性进行有限元分析。 *clearmark surfs 1 脚本最后通过*clearmark surfs 1清除曲面标记集1的内容,避免临时标记占用资源,确保HyperMesh环境整洁。
materialid={mats 1}),运行前需确保模型中已存在ID为1的材料,或根据实际需求修改材料ID。*createmarkpanel面板中需选择曲面,否则脚本可能无法 正常执行。cardimage=PSHELL替换为对应卡片名称;若需调整属性厚度参数,可修改*setvalue props后的参数值(如95=1可根据分析需求调整)。