Examples#

Some examples require external input files. Before you start, please follow the link in the Example Scripts section to download the zip file with model and result files.

Example 01 - Capturing Images#

Creating screenshots using CaptureImageTool class#
 1import hw
 2
 3sess = hw.Session()
 4win_list = sess.getWindows()
 5
 6capture = hw.CaptureImageTool()
 7capture.type = 'jpg'
 8capture.width = 1200
 9capture.height = 800
10
11for i, win in enumerate(win_list):
12    sess.setActive(hw.Window,window=win)
13    capture.file=f"C:/Temp/screenshot_{i+1}"
14    capture.capture()

Example 02 - Capturing Videos#

Export all possible video formats from HyperView#
 1import hw
 2import hw.hv as hv
 3import os
 4
 5from pathlib import Path
 6from shutil import rmtree
 7
 8ALTAIR_HOME = os.path.abspath(os.environ["ALTAIR_HOME"])
 9modelFile = os.path.join(
10    ALTAIR_HOME,
11    "demos",
12    "mv_hv_hg",
13    "animation",
14    "dyna",
15    "bumper",
16    "bumper_deck.key",
17)
18resultFile = os.path.join(
19    ALTAIR_HOME, "demos", "mv_hv_hg", "animation", "dyna", "bumper", "d3plot"
20)
21scriptDir = os.path.normpath(os.path.abspath(os.path.dirname(__file__)))
22exportDir = os.path.normpath(os.path.join(scriptDir, "Export"))
23
24for path in Path(exportDir).glob("**/*"):
25    if path.is_file():
26        path.unlink()
27    elif path.is_dir():
28        rmtree(path)
29
30ses = hw.Session()
31ses.new()
32page = ses.get(hw.Page)
33win = ses.get(hw.Window)
34
35win.type = "animation"
36
37win.addModelAndResult(modelFile, result=resultFile)
38res = ses.get(hv.Result)
39resScalar = hv.ResultDefinitionScalar(dataType="Displacement", dataComponent="Mag")
40res.plot(resScalar)
41
42hw.evalHWC(
43"view projection orthographic | \
44view matrix -0.021537 0.988942 0.146732 \
45                0.000000 0.872753 0.090190 \
46                -0.479758 0.000000 -0.487686 \
47                0.117728 -0.865045 0.000000 \
48                -99.918198 345.190369 584.070618 1.000000 | \
49view clippingregion -284.806213 129.713852 528.670959 \
50                864.158752 -722.333801 601.748169"
51)
52
53model = ses.get(hv.Model)
54
55animTool = hw.AnimationTool()
56animTool.currentFrame = 26
57win.draw()
58
59cvt1 = hw.CaptureVideoTool()
60cvt1.dimension = "pixels"
61cvt1.width = 3000
62cvt1.height = 2000
63
64typeList1 = ["avi", "amf", "gif"]
65for t in typeList1:
66    cvt1.type = t
67    videoFile = os.path.join(exportDir, "exportVideoTest." + t)
68    print('Video file of type "' + t + '" = ' + videoFile)
69    cvt1.file = videoFile
70    cvt1.capture()
71
72cvt2 = hw.CaptureVideoTool()
73cvt2.top = 0.1
74cvt2.left = 0.3
75cvt2.bottom = 0.9
76cvt2.right = 0.7
77
78typeList2 = ["jpeg", "png", "bmp"]
79for t in typeList2:
80    print("Type = " + t)
81    cvt2.type = t
82    tmpExportDir = os.path.join(exportDir, t)
83    os.mkdir(os.path.join(exportDir, t))
84    videoFile = os.path.join(tmpExportDir, "exportVideoTest." + t)
85    print('Video file of type "' + t + '" = ' + videoFile)
86    cvt2.file = videoFile
87    cvt2.capture()
../../_images/image_HV_CaptureVideoTool.PNG

Figure 1. Export all possible video formats from HyperView