Script Use Cases
Examples of script uses cases.
Use Case 1
Load a model and apply a stress
                contour.
        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 "--------------------------------------------"
}Use Case 2
Set time vector for each curve in the current plot
                window.
        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
}Use Case 3
Capture JPEG images for both stress and displacement
                datatypes.
        set t [expr rand()];
set proc_name "jpeg_capture"
hwi GetSessionHandle sess$t
# Get a post object handle
sess$t GetProjectHandle proj$t
proj$t GetPageHandle page$t [proj$t GetActivePage]
page$t GetWindowHandle win$t [page$t GetActiveWindow]
win$t SetClientType "Animation"
win$t GetClientHandle client$t
# Load model
set myfile "[ sess$t GetSystemVariable ALTAIR_HOME ]/demos/mv_hv_hg/animation/dyna/bumper/d3plot"
set model_id [client$t AddModel $myfile]
client$t GetModelHandle mod$t $model_id
mod$t SetResult $myfile
# Advance to last frame.
page$t GetAnimatorHandle animator$t
animator$t SetAnimationMode "transient"
animator$t SetCurrentStep [expr [animator$t GetNumberOfSteps]-1]
# Enable contour state and visibility
mod$t GetResultCtrlHandle res$t
mod$t ReleaseHandle
res$t GetContourCtrlHandle contour_ctrl$t
res$t ReleaseHandle
contour_ctrl$t SetEnableState true
client$t SetDisplayOptions "contour" true
client$t SetDisplayOptions "legend" true
# Set to stress datatype
set datatype "stress"
contour_ctrl$t SetDataType $datatype
contour_ctrl$t SetShellLayer "max"
contour_ctrl$t SetDimensionEnabled shell true
contour_ctrl$t SetDataComponent shell "P1"
contour_ctrl$t SetDimensionEnabled solid true
contour_ctrl$t SetDataComponent solid "P1"
client$t Draw
sess$t CaptureScreen "jpeg" "$datatype.jpg"
# Set to displacement datatype
set datatype "displacement"
contour_ctrl$t SetDataType $datatype
client$t Draw
sess$t CaptureScreen "jpeg" "$datatype.jpg"
# Cleanup handles to avoid leaks and handle name collisions.
contour_ctrl$t ReleaseHandle
client$t ReleaseHandle
page$t ReleaseHandle
sess$t ReleaseHandle