Run a HyperMesh script (*.tcl) from SimLab Using a Python File and using batch commands.


When a user tries to run the HyperMesh script from SimLab, the 'ALTAIR_HOME' env will be changed and it will conflict with the HyperMesh installation path.

The conflict can be avoided using the below methods.


1. Using the following Python code 

CODE:

#import subprocess module is used for accessing the system commands

import subprocess ,os

#To avoid the conflict between the SimLab and HyperMesh installation path store the ‘ALTAIR_HOME’ env in a python variable and clear the env.

Altair_Home = os.environ["ALTAIR_HOME"]

os.environ["ALTAIR_HOME"]=''

#Store the tcl script path and HyperMesh installation path in a python variable.

TCLScript = "./HM_Script.tcl"

hmBatchLoc = "./../hwdesktop/hm/bin/win64/hmbatch.exe"

#To start HyperMesh and execute the tcl script in batch mode use the below codes

Arg= hmBatchLoc+ " -tcl " + TCLScript

subprocess.call(Arg)

#After executing the tcl script restore back the ‘ALTAIR_HOME’ env

os.environ["ALTAIR_HOME"] = Altair_Home

 

SAMPLE SCRIPT:

import subprocess,os

Altair_Home = os.environ["ALTAIR_HOME"]

os.environ["ALTAIR_HOME"]=''

TCLScript = ""C:/Users/Documents/HyperMesh_Scripts/HM_Script.tcl"

hmBatchLoc = "C:/Program Files/Altair/HM_2021.2/hwdesktop/hm/bin/win64/hmbatch.exe"

Arg= hmBatchLoc+ " -tcl " + TCLScript

subprocess.call(Arg)

os.environ["ALTAIR_HOME"] = Altair_Home

  

2. Using the following batch script 

Use 'setlocal' and 'endlocal' batch commands as below to avoid this conflict.

 

BATCH SCRIPT:

REM To get the script file to be executed in SimLab

set script_name=D:\\Script\\simlab.py

REM To get the SimLab.bat location

set simlab_bat=D:\\Altair\\SimLab_2022.1\\SimLab.bat

REM To get the ALTAIR_HOME path and launch HyperMesh

set ALTAIR_HOME=D:\\Altair\\Hw_2021

set hmbatch=%ALTAIR_HOME%\\hwdesktop\\hm\\bin\\win64\\hmbatch.exe

REM To localize the changes made to the variable 'ALTAIR_HOME'

setlocal

REM Launching SimLab.bat and executing the python script.

call %simlab_bat% -auto %script_name% -nographics 

REM To revert back the changes made to the variable.

endlocal

REM Launching HyperMesh and executing the tcl script.

start %hmbatch% -nocommand -h -tcl %script_path%\HM_Script.tcl