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