scoped_name#

Support.scoped_name(obj: Any, native_exceptions: bool = False) ContextManager#

Allow for the use of with to shorten APIs.

In the EnSight and PyEnsight APIs, the interfaces can become lengthy. This class makes it possible to shorten APIs for modules, classes, and namespaces. The native_exceptions keyword can be used to enable exceptions for EnSight native Python API. By default, an invalid native API call like ensight.part.select_begin(-9999) will return -1. If native_exceptions is True, a Python exception will be thrown. The scope of this operational change parallels the scoped_name() instance.

Parameters:
obj: Any

The object for which to generate a simplified namespace.

native_exceptions: bool

If True, then EnSight native Python API exceptions are enabled. The default is False.

Returns:
The passed object wrapped in a context manager that can be used as a
simplified namespace.

Examples

>>> sn = s.ensight.utils.support.scoped_name
>>> with sn(s.ensight.objs.core) as core, sn(s.ensight.objs.enums) as enums:
>>>     print(core.PARTS.find(True, enums.VISIBLE))
>>> sn = ensight.utils.support.scoped_name
>>> with sn(ensight.objs.core) as core, sn(ensight.objs.enums) as enums:
>>>     print(core.PARTS.find(True, enums.VISIBLE))
>>> sn = ensight.utils.support.scoped_name
>>> with sn(ensight.part, native_exceptions=True) as part:
>>>     part.select_begin(-9999)