HyperMesh二次開發實例

HyperMesh二次開發

使用Tcl/Tk進行二次開發的過程很簡單:在Hypermesh的默認工作路徑下有一個文件Command.cmf,這個文件記錄了每個操作的動作。在打開Hypermesh之前,刪除這個文件。啟動Hypermesh,這個文件會被重新生成。執行一個需要重復操作的動作周期,Command.cmf就記錄了操作過程。編輯這個文件,將其中的括號和逗號全部用空格替代,將文本另存為以tcl為后綴的文件。

 
腳本實例一

以下是一個將Hypermesh網格按照component分組逐個輸出為nastran格式的腳本,輸出文件名為component名字,因此需要注意不要有特殊符號。代碼中的tmpl和savedir變量根據實際進行修改。
set lst_comp [hm_entitylist comps name] 
set tmpl "[hm_info -appinfo SPECIFIEDPATH TEMPLATES_DIR]/feoutput/nastran/general" 
set savedir "D:/work/Temp/Hm" 
*displaynone 
foreach comp_name $lst_comp { 
    *displaycollectorwithfilter components "on" $comp_name 1 0  
    *retainmarkselections 0  
    *entityhighlighting 1  
    *createstringarray 0  
    *feoutputwithdata $tmpl $savedir/$comp_name.bdf 0 0 0 1 0  
    *displaycollectorwithfilter components "off" $comp_name 1 0  
} 
*displayall

 
腳本實例二

Hypermesh本身的提取中面功能較為簡單,通過選擇所有提取中面的部件,按照選項提取中面后命名為一個新的分組"Middle Surface"。在部件分組較多的情況下,對部件重新組織就比較麻煩。
以下代碼實現的功能是遍歷所有部件,如果部件有實體,則提取中面,并按照用戶輸入的實體厚度重新命名為新的分組,否則不做操作并給出提醒信息。所輸入的實體厚度僅作為新部件的命名使用。
*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."

微信關注【有限元微刊】,獲得更多神技~

welcomeToIfem.png


登錄后免費查看全文
立即登錄
App下載
技術鄰APP
工程師必備
  • 項目客服
  • 培訓客服
  • 平臺客服

TOP

4
1
7