namespace eval ::matGUISample {
variable rmax
variable rmin
variable lmax
variable lmin
variable areamax
variable areamin
variable surfbooleantolerance
}
proc ::matGUISample::CreateGUI {} {
variable rmax
variable rmin
variable lmax
variable lmin
variable areamax
variable areamin
variable surfbooleantolerance
#窗口主界面初始化
destroy .mainTopLevel
set win .mainTopLevel
toplevel $win -padx 20 -pady 15
# 面缝合容差
set e1_lbl [label $win.e1 -text “面缝合容差” -width 50]
set e1_ent [entry $win.e1ent -textvariable surfbooleantolerance -width 20 ]
# 移动实体按钮-将所有体移动至名为Original_Geom的组件中,并删除空组件
set crt_btn1 [button $win.bbtn1 -text “开始移动体” -width 20 -command { ::matGUISample::CreateMat1 }]
# 抽中面创建属性按钮
set crt_btn2 [button $win.bbtn2 -text “开始抽中面” -width 20 -command { ::matGUISample::CreateMat2 }]
# 面缝合按钮
set crt_btn3 [button $win.bbtn3 -text “开始面缝合” -width 20 -command { ::matGUISample::CreateMat3 $surfbooleantolerance }]
grid $crt_btn1 -row 1 -column 0 -padx 1 -pady 1
grid $crt_btn2 -row 2 -column 0 -padx 1 -pady 1
grid $e1_lbl -row 1 -column 1 -padx 1 -pady 1
grid $e1_ent -row 2 -column 1 -padx 1 -pady 1
grid $crt_btn3 -row 3 -column 0 -padx 1 -pady 1
}
###################################################################################################### 分组子程序
proc ::matGUISample::CreateMat1 { } {
*clearmark comps 1
*clearmark solids 1
*createmarkpanel solids 1
*createentity comps cardimage=HM_COMP includeid=[expr (1000000000000000000)] name=Original_Geom
*movemark solids 1 Original_Geom
# 删除空组件
*createmark comps 1 all
set compID [hm_getmark comps 1]
set comp_number [ llength $compID]
for {set i 0} {$i<$comp_number} {incr i 1} {
set temp_comp1 [lindex $compID $i]
hm_createmark solids 1 “by component id” “$temp_comp1”
set temp_comp2 [ llength [hm_getmark solids 1]]
if {$temp_comp2==0} {
*createmark components 1 $temp_comp1
*deletemark components 1
}
}
*clearmark comps 1
*clearmark solids 1
}
######################################################################################################
###################################################################################################### 抽中面子程序
proc ::matGUISample::CreateMat2 { } {
*clearmark comps 1
*clearmark solids 1
*createmarkpanel solids 1
set solid_id [hm_getmark solids 1]
set solid_number [ llength $solid_id]
for {set i 0} {$i<$solid_number} {incr i 1} {
set j [expr ([hm_entitymaxid components]+1)]
*createentity comps cardimage=HM_COMP includeid=[expr ($j)] name=Surf_$i
*createmark solids 1 [lindex $solid_id $i]
*midsurface_extract_10 solids 1 3 0 1 1 9 0 20 0 0 10 0 10 -2 undefined 0 0 0
#获取最大id的point-即检测新生成面(中面)上的point,用来获取板材厚度
set maxpoint [hm_entitymaxid points]
set surfthickval [hm_getsurfacethicknessvalues points $maxpoint]
set thickness [lindex [lindex $surfthickval 0] 1]
#创建厚度属性
set temp_name0 “surf”
set temp_name1 “T”
set temp_name2 “_”
set temp_name3 [append temp_name0 $i $temp_name2$temp_name1 $thickness ]
set k [expr ([hm_entitymaxid props]+1)]
*createentity props cardimage=”SECTYPE” includeid=$k name=$temp_name3 usingxmldata=Ansys.xml
#更新属性
*setvalue props id=$k STATUS=2 2902=”SHELL”
*startnotehistorystate {Attached attributes to property “surf_T_$thickness”}
*setvalue props id=$k STATUS=2 2731=”MID”
*setvalue props id=$k STATUS=2 2903=0
*setvalue props id=$k STATUS=2 2911=0
*setvalue props id=$k STATUS=2 2912=0
*setvalue props id=$k STATUS=2 2913=0
*setvalue props id=$k STATUS=2 2914=0
*setvalue props id=$k STATUS=2 2915=1
*setvalue props id=$k STATUS=2 2916=1
*setvalue props id=$k STATUS=2 2917=1
*endnotehistorystate {Attached attributes to property “surf_T_$thickness”}
*mergehistorystate “” “”
*startnotehistorystate {Modified PLIES of property}
*endnotehistorystate {Modified PLIES of property}
*startnotehistorystate {Modified PLIES of property}
*setvalue props id=$k STATUS=2 2903=1
*endnotehistorystate {Modified PLIES of property}
*startnotehistorystate {Attached attributes to property “surf_T_$thickness”}
*setvalue props id=$k STATUS=2 2904={0}
*setvalue props id=$k STATUS=2 2905={mats 0}
*setvalue props id=$k STATUS=2 2906={0}
*setvalue props id=$k STATUS=2 2907={3}
*endnotehistorystate {Attached attributes to property “surf_T_$thickness”}
*mergehistorystate “” “”
*startnotehistorystate {Modified TK of property}
*setvalue props id=$k STATUS=2 2904=$thickness
*endnotehistorystate {Modified TK of property}
#更新中面所在组件名称及属性
*setvalue comps id=$j propertyid={props $k}
*setvalue comps id=$j name=$temp_name3
}
}
###################################################################################################### 面缝合子程序
proc ::matGUISample::CreateMat3 { surfbooleantolerance } {
set tolerance $surfbooleantolerance;
*createmarkpanel lines 1
*createmarkpanel surfs 1
set surfsid [hm_getmark surfs 1]
set linesid [hm_getmark lines 1]
set surfnumber [ llength $surfsid]
set linenumber [ llength $linesid]
for {set i 0} {$i<$linenumber } {incr i 1} {
for {set j 0} {$j<$surfnumber } {incr j 1} {
#*createmark lines 1 [lindex $linesid i]
#*createmark surfs 1 [lindex $surfsid j]
set temp_distance1 [hm_getclosestpointsbetweenlinesurface [lindex $linesid $i] [lindex $surfsid $j]]
set temp_distance2 [lindex $temp_distance1 6]
set temp_surfid1 [hm_createmark surfs 1 “by lines” [lindex $linesid $i]]
set temp_surfid2 [hm_getmark surfs 1]
*createmark lines 1 [lindex $linesid $i]
if {$temp_distance2<$tolerance } {
*createmark surfaces 1 [lindex $surfsid $j] $temp_surfid2
*createmark lines 2
*connect_surfaces_11 1 1 3 2 0 15 30 1 0 2 30 3 0
#由于缝合后面id号变化,更新面id表和数量
set element_to_remove [lindex $surfsid $j]
# 使用循环和lsearch命令移除所有匹配的元素
while {[lsearch $surfsid $element_to_remove] >= 0} {
set index [lsearch $surfsid $element_to_remove]
set surfsid [lreplace $surfsid $index $index]
set surfnumber [ llength $surfsid]
}
#将j值置为最大跳出本次循环执行下一个循环
set j $surfnumber
}
}
}
}
::matGUISample::CreateGUI
-
扫码下载安卓APP
-
微信扫一扫关注我们
微信扫一扫打开小程序
手Q扫一扫打开小程序
-
返回顶部
发表评论