Funny incompatibility of Cubit 2021.5 with previous versions

If your old professionally written Python scripts like:

def func():

if __name__ == '__console__':

do not work in the 2021.5, the reason is: special Python variable __name__ historically (from cubit 11 to 2021.4) equal to ‘__console__’, now has standard value ‘__main__’. So if you want to keep your scripts compatible with the previous versions of Cubit/Trelis you have to use:

if __name__ in ['__console__', '__main__']:

I am not sure, do we need to ask developers to return old value back or not…

@AndyU I’m not seeing anywhere in the code where we explicitly set __name__ and I don’t see any documentation that guarantees the value __console__. I think this is unintentional, undocumented behavior and should not be relied on. If you’re using the value __console__ as a way to detect if the script is being run from Cubit or not, you can instead write a function that attempts to import the Cubit module, like this:

def isCubit():
        import cubit
        return True
    except ImportError:
        return False


C:\Program Files\Trelis 17.1\bin\python2\Lib\
C:\Program Files\Trelis 17.1\bin\python3\Lib\

If change value of the locals[‘doc’] in the line 34 of the from None to something else, restart 17.1 and print(locals()) this modified value will be seen in the output.

The same files exist in 2021.5 directory structure, but if modify in 2021.5 - modification will not be printed by print(locals()). Probably file is not used now…

No, I use this guard (instead of standard ‘main’) to allow usage of my scripts as main executables and/or as imported modules:

# file a:
__all__ = ['make_geometry']
import cubit

def make_geometry():

if __name__ == '__console__'

# file main:
import a
import b   # similar to

if __name__ == '__console__'

P.S. It is interesting, that exists in Python distribution and mentioned in manuals. Why ‘console’ is used here?

Correct, comes with the Python distribution. The python2 and python3 folders on Windows are direct copies of the Python redistributable folders, so any behavior of is used unmodified by Cubit. I’m not sure why __name__ changed, but we can’t guarantee the behavior of Python internals since we don’t directly control them. All Cubit does (apart from some initialization code that sets things like PYTHONHOME) is link against the Python shared library python38.dll.


If remove from Trelis 17.1 distribution (say from bin/python3/lib and start Trelis with

>trelis.exe -pythonversion 3

it will crashes at start, because code is imported in structure/ module, which is probably called from clarogui.dll and clarofw.dll.

Simultaneously, it is safe to delete from Coreform Cubit 2021.5 distribution just because file structure/ is absent, that is code module is not used now for interactive console emulation and __name__ is not redefined.

P.S. Workaround: old value of the __name__ variable in 2021.5 can be restored by modified wrapper script from Cubit User Documentation -> Controlling the Application -> gui -> Command Line Workspace:

with open('', encoding='utf8') as f:
    code = compile(, '', 'exec')
glob = globals().copy()
glob['__name__'] = '__console__'
exec(code, glob)