🎉Community Raffle - Win $25

An exclusive raffle opportunity for active members like you! Complete your profile, answer questions and get your first accepted badge to enter the raffle.
Join and Win

How to integrate Simlab python script(shell mesh creation) and hyper mesh TCL script(solid mesh creation)? how to combine both operations using OML-Python bridge & OML-TCL bridge?

User: "Vaddi Vijay Kumar"
Altair Community Member
Updated by Vaddi Vijay Kumar

Find more posts tagged with

Sort by:
1 - 1 of 11
    User: "AlessioLibrandi"
    Altair Employee
    Updated by AlessioLibrandi

    Please have a look at this article that may help you further.

    Greetings, Alessio Librandi

    ___________________________________

     

    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