许可优化
许可优化
产品
产品
解决方案
解决方案
服务支持
服务支持
关于
关于
软件库
当前位置:服务支持 >  软件文章 >  HyperWorks集成桌面环境二次开发(四):脚本实例详解

HyperWorks集成桌面环境二次开发(四):脚本实例详解

阅读数 1
点赞 0
article_banner

实例 一  载入模型并查看模型应力


set proc_name "contour_stress"

hwi GetSessionHandle sess

 

if {[catch {

 hwi GetSessionHandle sess

 sess GetProjectHandle proj

 proj GetPageHandle page [proj GetActivePage]

 proj ReleaseHandle

 page GetWindowHandle win [page GetActiveWindow]

 win SetClientType "Animation"

 win GetClientHandle post

 win ReleaseHandle

 

 # Load model

 set model_id [post AddModel d:/samples/dyna/bumper_foam/d3plot"]

 post GetModelHandle mod $model_id

 mod SetResult "d:/samples/dyna/bumper_foam/d3plot"

 

 # Advance to first frame.

 page GetAnimatorHandle animator

 animator Next

 

 # Enable contour state and visibility

 mod GetResultCtrlHandle res

 mod ReleaseHandle

 res GetContourCtrlHandle contour_ctrl

 res ReleaseHandle

 contour_ctrl SetEnableState true

 post SetDisplayOptions "contour" true

 

 # Set result state

 contour_ctrl SetDataType "stress"

 contour_ctrl SetShellLayer "max"

 contour_ctrl SetDimensionEnabled shell true

 contour_ctrl SetDataComponent shell "P1"

 contour_ctrl SetDimensionEnabled solid true

 contour_ctrl SetDataComponent solid "P1"

 

 post Draw

 

 # Cleanup handles to avoid leaks and handle name collisions.

 contour_ctrl ReleaseHandle

 post ReleaseHandle

 page ReleaseHandle

 sess ReleaseHandle

         

} result]}

 # Error handling

 puts $logfile "----- Error occured running $proc_name -----"

 puts $logfile "[sess GetError]"

 puts $logfile "--------------------------------------------"

}   

 实例二  在当前窗口中为每条曲线添加时间轴向量
  
  

set proc_name "setTimeVector"

hwi GetSessionHandle sess

 

if {[catch {

 

 sess GetProjectHandle proj

 proj GetPageHandle page [proj GetActivePage]

 page GetWindowHandle win [page GetActiveWindow]

         

 if {[string match [win GetClientType] "Plot"]}

         win GetClientHandle plot

 

         set numcurves [plot GetNumberOfCurves]

         for {set i 1} {$i <= $numcurves} {incr i}

                 plot GetCurveHandle curve $i

                 curve GetVectorHandle curve_x x

                 curve GetVectorHandle curve_time time

                 if {![string length [curve_time GetValuesList]]}

                         set max_x [lindex [lsort -real [curve_x GetValuesList]] end]

                         curve_time SetType values

                         curve_time SetValues [join [curve_x GetValuesList] ,]

                         if {$max_x >= 1.00}

                                 set scale [expr [string length [expr int($max_x)]] * 10.00]

                                 curve_time SetScaleFactor [expr 1.00 / $scale]

                         }

                 }

                 plot Recalculate

                 plot Draw

                 

                 # Cleanup handles to avoid leaks and handle name collisions.

                 curve_time ReleaseHandle

                 curve_x ReleaseHandle

                 curve ReleaseHandle

         }

 } else

         puts $logfile "Invalid Window Type: requires a plot window."

 }

 

  # Cleanup handles        

 plot ReleaseHandle

 win ReleaseHandle

 page ReleaseHandle

 proj ReleaseHandle

 sess ReleaseHandle

 

} result]}

 # Error handling

 set msg "Error occured running $proc_name\n\n[sess GetError]"

 tk_messageBox -title "Error running script" -message $msg

}

    实例三 获取应力与位移的JEPG图像
  
  

set proc_name "jpeg_capture"

hwi GetSessionHandle sess

 

if {[catch {

 

 # Get a post object handle

 sess GetProjectHandle proj

 proj GetPageHandle page [proj GetActivePage]

 page GetWindowHandle win [page GetActiveWindow]

 win SetClientType "Animation"

 win GetClientHandle post

 

 # Load model

 set myfile "d:/samples/dyna/bumper_foam/d3plot"

 set model_id [post AddModel $myfile]

 post GetModelHandle mod $model_id

 mod SetResult $myfile

 

 # Advance to last frame.

 page GetAnimatorHandle animator

 animator SetAnimationMode "transient"

 animator SetCurrentStep [expr [animator GetNumberOfSteps]-1]

 

 # Enable contour state and visibility

 mod GetResultCtrlHandle res

 mod ReleaseHandle

 res GetContourCtrlHandle contour_ctrl

 res ReleaseHandle

 contour_ctrl SetEnableState true

 post SetDisplayOptions "contour" true

 post SetDisplayOptions "legend" true

 

 # Set to stress datatype

  set datatype "stress"

 contour_ctrl SetDataType $datatype

 contour_ctrl SetShellLayer "max"

 contour_ctrl SetDimensionEnabled shell true

 contour_ctrl SetDataComponent shell "P1"

 contour_ctrl SetDimensionEnabled solid true

 contour_ctrl SetDataComponent solid "P1"

 post Draw

 sess CaptureScreen "jpeg" "$tag-$datatype.jpg"

 

 # Set to displacement datatype

  set datatype "displacement"

 contour_ctrl SetDataType $datatype

 post Draw

 sess CaptureScreen "jpeg" "$tag-$datatype.jpg"

 

 # Cleanup handles to avoid leaks and handle name collisions.

 contour_ctrl ReleaseHandle

 post ReleaseHandle

 page ReleaseHandle

 sess ReleaseHandle

         

} result]}

 # Error handling

 set msg "Error occured running $proc_name\n\n[sess GetError]"

 tk_messageBox -title "Error running script" -message $msg

}

 


    参考HyperWorks Desktop 手册,12.0版本。
  
  
  
免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删


相关文章
技术文档
QR Code
微信扫一扫,欢迎咨询~
customer

online

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 board-phone 155-2731-8020
close1
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

姓名不为空

姓名不为空
手机不正确

手机不正确

手机不正确
公司不为空

公司不为空

公司不为空