Set Environment variables

sanket_patil
sanket_patil Altair Community Member
edited August 2021 in Community Q&A

Hello All,

I wanted to set environment variables in hypermesh using TCL command. Process i want to do is explained as below,

1) I have one file path {c:\xyz\ref_file.csv}

2) In hypermesh session, lets call this session as "session1". store file path mentioned in step 1) in environment variable using tcl command.

3) Use the value of environment variable in the session1.(currently i am not able to do this)

4) If i open another hypermesh session named as "session2", in session2 i can read value of environment variable which is set in "session1"

So, is there any way so that i can use environment variable in the same session in which i am setting it?

Please guide me to resolve the issue.

Thanks in advance.

Regards,

Sanket Patil

Answers

  • tdepa
    tdepa Altair Community Member
    edited August 2021

    You should be able to do this with regular tcl.

    # set environment variable
    registry set [join { HKEY_CURRENT_USER Environment } "\\"] "HW_ENV_TEST" "TEST123"
    registry broadcast "Environment"

    Then in other HW...

    # get environment variable
    set regVar "HW_ENV_TEST"
    set regPth [join { HKEY_CURRENT_USER Environment } "\\"]
    set regVal [registry get $regPth $regVar]
    puts "$regVar is $regVal"

    It seems to work fine from multiple HW sessions, or any other software for that matter. Having said that, I would recommend to my people not to use this approach in general. It is not portable to other platforms, there is probably some real risk to corrupt the registry if something goes wrong, Unless you clean up manually, this could leave a bunch of junk in the registry even if you uninstall HW. Maybe a simple config file would do the job?

    Please also don't take the code above as well-formed, just the briefest way to demonstrate the process. You'd really want to add a bunch of catches for all kinds of possible things that you could think of depending on the application.