用Tcl实现Hypermesh逐个部件提取中面
Hypermesh本身的提取中面功能较为简单,通过选择所有提取中面的部件,按照选项提取中面后命名为一个新的分组"Middle Surface"。在部件分组较多的情况下,对部件重新组织就比较麻烦。
屈晓峰的《基于Tcl语言的HyperMesh平台二次开发范例》描述了用Tcl脚本实现提取中面的功能。受此文章启发,我在作者所给出的代码的基础上,编写了按照原来的分组关系逐个对部件抽取中面并根据指定规则命名的功能。
以下是我根据需要进行修改的代码。代码实现的功能是遍历所有部件,如果部件有实体,则提取中面,并按照用户输入的实体厚度重新命名为新的分组,否则不做操作并给出提醒信息。所输入的实体厚度仅作为新部件的命名使用。
*createmark comps 1 all
set mycomps [ hm_getmark comps 1 ]
*clearmark comps 1
set NumFail 0
set hmname [hm_info hmfilename]
set Errorlog [file join [file dirname $hmname] "error.log"]
set fid [open $Errorlog w]
puts $fid "The file is generated by Midsurface."
foreach Compid $mycomps {
set Compname [hm_getcollectorname comps $Compid]
hm_createmark solids 1 "by component" $Compname
set SolidIds [hm_getmark solids 1]
set NumSolids [llength $SolidIds]
puts "$Compname has $NumSolids solids "
if {$NumSolids < 1} {
incr NumFail
puts -nonewline $fid $NumFail
puts -nonewline $fid ". "
puts -nonewline $fid "\["
puts -nonewline $fid $Compname
puts -nonewline $fid "\] "
puts $fid ", Failure=No Solid in $Compname."
continue
}
*retainmarkselections 1
*setsurfacenormalsdisplaytype 1
*normalsoff
*midsurface_extract_10 solids 1 3 0 1 1 0 0 20 0 0 10 0 10 -2 undefined 0 0 1
*midsurface_remove_edit_bodies
*release_temp_fixed_vertices
*normalsoff
set suffix [hm_getfloat "Thickness of component $Compname:"]
set divchar "_"
set lenunit "mm"
set Newcompname $Compname$divchar$suffix$lenunit
if { [hm_entityinfo exist comps $Newcompname -byname] == 1 } {
hm_errormessage "Component name $Newcompname already exists."
puts $fid "Component name $Newcompname already exists."
return
}
*renamecollector components "Middle Surface" $Newcompname
*retainmarkselections 0
}
close $fid
hm_usermessage "Done."
Comments