Launching tcl scripts with arguments from python

User: "Alaam"
Altair Community Member

I am coding an automation process using python as a main script. I would like to call up a .tcl script from python. I know I can use hw.evalTcl() to launch tcl scripts, but I need to give my tcl script input arguments, so I am running it using

subprocess.run( [tclshell_exe, my_tcl_script.tcl, py_arg1, py_arg2], capture_output=True, text=True )

tclshell_exe points to the tclsh85.exe located in the Altair Hyperworks directory.

Standard tcl commands such as "puts" work fine, while HM sepcific functions return errors. Note that no command output is shown in the Hypermesh Tcl command window.

Is using subprocess the optimal way for the tcl script call up?

I imagine a workaround would be to start with a .tcl script as the main script, where I call up python scripts and other tcl scripts, avoiding the argument assignment issue. The idea is to eventually have the whole script in python, and currently some tcl commands are not optimal to run in python.

Find more posts tagged with

Sort by:
1 - 1 of 11
    User: "Michal Stefuca"
    Altair Employee
    Accepted Answer

    Hi @Alaam

    Subprocess will spin-off a completely independent instance of the Tcl interpreter which will not be aware of the HyperMesh session and its APIs.

    Since Tcl's source does not support passing arguments to the script, probably the easiest way would be to restructure your code in a way that you can pass the arguments to a top-level function which then calls the rest of our code (see screenshot below).

    image.png

    Hope this helps.

    Thanks,
    Michal Stefuca

    Automation & Customization