Tools#

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 - Run HWC from Python#

The example shows how HWC commands can be executed from Python using the evalHWC() method. The executed commands clean the session, load model and result files, and set up the session by modifying the page layout and copying the windows.

 1import os
 2import hw
 3
 4scriptDir = os.path.abspath(os.path.dirname(__file__))
 5modelFile = os.path.join(scriptDir, "aerobox", "aerobox.fem")
 6resultFile = os.path.join(scriptDir, "aerobox", "aerobox-LC1-2.op2")
 7
 8hw.evalHWC("delete session")
 9hw.evalHWC("hwd page current activewindow=1")
10hw.evalHWC("hwd window type=HyperView")
11hw.evalHWC("delete session")
12hw.evalHWC("hwd window type = HyperView")
13hw.evalHWC("open animation  modelandresult " + modelFile + " " + resultFile)
14hw.evalHWC("view fit allframes = true")
15hw.evalHWC("hwd page current layout = 9")
16hw.evalHWC("hwd window copy")
17hw.evalHWC("hwd window paste window = 2")
18hw.evalHWC("hwd page current activewindow = 3")
19hw.evalHWC("hwd window paste")
20hw.evalHWC("hwd page current activewindow = 4")
21hw.evalHWC("hwd window paste")
22hw.evalHWC("hwd page copy")
23hw.evalHWC("hwd page add title = Untitled")
24hw.evalHWC("hwd page paste")
25hw.evalHWC("hwd page overlay page = 2")
../../_images/image_HV_Python_evalHWC.PNG

Figure 1. Recording of copying/overlaying windows and pages

Example 02 - Export H3D into HTML#

First, the example goes through the standard steps (setting up the window, loading the model/result files, and contouring the results). Next, it sets the animation frame and positions the model using HWC command.

This is followed by the main action - the creation of the ExportModelH3DinHTML object, setting up its attributes and calling the export() method to generated the HTML file containing the H3D results. Lastly, open_new_tab() method from the webbrowser module is used to open the HTML file in the default browser.

 1import hw
 2import hw.hv as hv
 3import os
 4import webbrowser
 5
 6ALTAIR_HOME = os.path.abspath(os.environ['ALTAIR_HOME'])
 7modelFile   = os.path.join(ALTAIR_HOME,'demos','mv_hv_hg','animation','dyna','bumper','bumper_deck.key')
 8resultFile  = os.path.join(ALTAIR_HOME,'demos','mv_hv_hg','animation','dyna','bumper','d3plot')
 9htmlFile    = os.path.normpath(os.path.join(os.getcwd(),'H3D_to_HTML.html'))
10
11ses = hw.Session()
12ses.new()
13win=ses.get(hw.Window)
14win.type = 'animation'
15win.addModelAndResult(modelFile, result=resultFile)
16
17# Set scalar, vector and tensor results
18res = ses.get(hv.Result)
19resScalar = hv.ResultDefinitionScalar(dataType='Stress',
20                  dataComponent='vonMises',
21                  layer='Max')
22res.plot(resScalar)
23
24# Set time step
25animTool=hw.AnimationTool()
26animTool.currentFrame=res.getSimulationIds()[-2]
27
28# Set View
29hw.evalHWC('view orientation back')
30
31print('Run ExportModelH3DinHTML() ...')
32expModH3DtoHTML=hv.ExportModelH3DinHTML()
33expModH3DtoHTML.file=htmlFile
34expModH3DtoHTML.page=1
35expModH3DtoHTML.winodw=1
36expModH3DtoHTML.compressOutput=True
37expModH3DtoHTML.compressionLoss=0.01
38expModH3DtoHTML.animation=True
39expModH3DtoHTML.includeSets=True
40expModH3DtoHTML.includeMaskedElements=True
41expModH3DtoHTML.results=True
42expModH3DtoHTML.viewAttributes=True
43expModH3DtoHTML.export()
44print('Export to "{}" successfully finished!'.format(expModH3DtoHTML.file))
45
46webbrowser.open_new_tab(expModH3DtoHTML.file)
../../_images/image_HV_H3D_HTML_3D_Export.PNG

Figure 2. Web-Browser View on H3D in HTML 3D Export