Please visit our partners

Environment Variables and NX

The configuration of NX can be affected by using environment variables. 
While most people probably know about the ugii_env.dat (Windows) or .ugii_env (Unix) file, that  is not the only way to set environment variables.
On MS Windows, there are at least 5 ways to set an ENV variable before or during an NX session:

1) "User" Level
2) "System" Level
3) Process Level
4) ENV Files
5) NXopen API program

"User" and "System" Level

Both options 1 and 2 use the "System" control panel.  The exact way to get to the ENV variables dialog depends of the specific version (and configuration) of Windows installed, but on my system it is:
            "Start" menu -> "Settings" -> "Control Panel".
            Open the "System" control panel
            Select the "Advanced" tab, then click on the "Environment Variables" button.
You get the following dialog:
            Figure 1
The dialog is divided into an upper and a lower half.  The upper half is for "user" level variables  (option 1 in the list above), the lower half for "system" variables (option 2). 
As the name suggests, "user" variables are user (account) specific.  If you set a user ENV variable, "OK" out, log off, and then someone else logs onto this computer, they do NOT see what you have set.
"System" variables are seen by all users who log onto this computer.

The nice thing about defining a variable here is that you only have to set it once. 
It stays set as you log off and on, reboot, etc.
Note setting a variable in the “System” level requires administrator privileges.

You don't have to set user and system level variables using this dialog.  The MS Windows Resource Kits include a utility ("Setx.exe") that allows you to set these variables using the command line or in a BAT file (If you don't have it, just search www.microsoft.com for "setx.exe"). 
Refer to the Setx documentation for specific arguments, but note including "-m" argument sets the ENV in the "System" level.  Leaving off the "-m" sets in the user level.

During installation (at least through NX4), NX automatically defines 3 ENV variables in the "System" level:
            UGII_BASE_DIR - This is the path (folder) where you installed NX
            UGII_ROOT_DIR - This is the "UGII" folder under UGII_BASE_DIR
            UGII_LICENSE_FILE - This points to the port and hostname(s) of the license server(s).

One minor disadvantage of setting a variable here is that if you are in a Teamcenter Engineering environment, you must exit both NX and Teamcenter, then re-start Teamcenter and NX, to have the new setting applied.

Process Level

You can also set an ENV variable at the level of an individual process.  Typically this is done in a BAT file (or other scripting language of your choice), e.g.:
            SET UGII_ENV_FILE=S:\NX_CONFIG\My_UGII_ENV.Dat
If you need to run NX in different configurations (e.g. test vs. development), having different BAT files (with different ENV variable settings) that start NX is a great way to get exactly the configuration you want.  I typically have 4 - 8 shortcuts on my desktop pointing to different BAT files to start NX in different versions and/or configurations.

Teamcenter uses several BAT files to start itself, and then to start NX in the Teamcenter environment.
There can be quite a few ENV variables defined in these BAT files, so check them out if you are having problems.

ENV Files

The bulk of ENV variables that NX uses are set in this file ("ugii_env.dat" for Windows, ".ugii_env" for Unix). 
The default location for this file is in UGII_ROOT_DIR.
Note some are commented out (you have to un-comment them to turn them on).
It is worth reviewing this file at least once to know what is in it.
Also, when you install new versions of NX, it is a good idea to compare this file between the versions to see what UGS has added/changed/removed.
Note you can set the ENV variable UGII_ENV_FILE to point to the one you want to use
(i.e. a shared one on a network drive).

NOTE: I will cover more ENV file issues in the next newsletter.

NXopen API program

You can set an ENV variable using the "legacy" API function UF_set_variable().
I do not believe this has been added to the common API (other than as a wrapped function).
This sets the ENV variable's value in the current session of NX – it does not set it in the “user” or “system” level.
Note that many variables are only read ONCE when NX starts, so setting them later MAY NOT effect the NX session. 
For instance, in NX4 f you set UGII_CAM_POST_DIR after NX starts, but before you open any part files, then the new setting is used.  Once you have opened a part and gone into Manufacturing, setting UGII_CAM_POST_DIR will not reset where posts are found.  However, if you go into Preferences -> Manufacturing -> Configuration tab, and re-select your configuration (e.g. "cam_general.dat"), it does appear to re-read this specific variable.

So if you want to use this method to set ENV variables, you need test each one to determine the behavior of NX when the variable is set after NX starts (but before any parts are opened), after parts are opened, after the module is set, etc.

If you want to use this function, you might want to find and read the following BBS newsgroup post in the UGSolutions database (http://uganswer.ugs.com):
 Newsgroup:nx.languages
 Subject:Re: UF_set_variable
 From:"Keith Hafen"
 Date:Thu, 8 May 2003 12:24:13 -0700

Who Wins?

As there are several places to set an ENV variable, it is important to understand WHICH one will be used if the same variable is set more than one place.  If you are ever confused as to which setting is in use during your NX session, you can find out by going to "Help" -> "NX Log File".  Scroll down a little and you will see a section listing most (but NOT ALL) ENV variable settings as NX started up:

 **************  Locked Unigraphics Configuration Variables  **************
    UGII_VERSION                     v4
    UGII_FULL_VERSION                v4.0.3.3

 **************        System Environment Variables          **************
    IMANLIBS                         C:\TCENG0~1\bin
    IMAN_ROOT                        C:\TCENG0~1
    UGII_ENV_FILE                    L:\UGNX4\Default_Sysfiles\moog_ugii_env.dat
<some deleted for brevity>

 Using ugii_env file L:\UGNX4\Default_Sysfiles\moog_ugii_env.dat
 ************** Unlocked Unigraphics Configuration Variables **************
    UGII_TMP_DIR                     C:\TEMP
    UGII_MONIKER                     1
    UGII_CAM_BASE_DIR                L:\UGNX4\moogcam\mach\
<some deleted for brevity>

Note this listing will NOT show variables set by an API program after NX has started.

In general, an ENV variable defined at a higher level in the following list over-rides any ones set lower down:
a) API program (with caveats mentioned in that section above, and only AFTER the API program is run).
b) Process Level
            As mentioned above, in a Teamcenter Engineering environment, some ENV variables may be set by the Teamcenter startup files.  If this is the case, they are MOSTLY set at this level of the heirarchy. 
            If multiple BAT files set the same ENV variable, the LAST one set is the one that is used.
c) "User" level
d) "System" level
e) ENV File
            Note if a variable is set multiple places in ENV files (and nowhere else), the FIRST setting is the only one used.

Other notes

 

Using ENV variables to set other variables

  1. Windows (operating system level)
    If you want to use an ENV variable in Windows, you enclose it in "%",

                        e.g. SET MY_USERNAME=%USERNAME%
              This is true in BAT files and in the "System" control panel.

  1. ENV File.  To use an ENV to set another on in the UGS ENV files, use "${}", e.g.:

                        UGII_CAM_POST_DIR=${UGII_CAM_RESOURCE_DIR}postprocessor\

Non-UGS ENVs that are used by NX

- TMP
            Note UGS uses TMP as the default location for many files.  From the UGII_ENV.DAT file:
            HOME=${TMP}

            As this defaults (in Windows) to "C:\Documents and Settings\<username>\Local Settings\Temp" (actually defined as “%USERPROFILE%>\Local Settings\Temp”), that is where many UGS files (syslogs, etc.) end up so you might want to consider cleaning this folder out periodically.

 


Please visit our partners