zospy.api.codecs.OpticStudioInterfaceEncoder#
- class zospy.api.codecs.OpticStudioInterfaceEncoder#
Bases:
RawProxyEncoder
Automatic downcasting of generic interfaces to specific interfaces.
Some parts of the ZOS-API return a generic interface where a specific implementation is needed. For example, the settings object for an analysis can be accessed using ZOSAPI.Analysis.IA_.GetSettings, but the returned object does not give access to analysis-specific settings. In order to access these settings, the specific implementation needs to be used. Python.NET makes this implementation available under the __implementation__ attribute. This encoder automatically downcasts certain objects to their specific implementation.
More information about this problem is available on the OpticStudio forum <https://community.zemax.com/zos-api-12/pythonnet-3-x-is-fixed-3945?tid=3945&fid=12>.
Only a limited number of interfaces is automatically downcast. These are documented at https://zospy.readthedocs.io/codecs. It is possible to register additional interfaces with OpticStudioInterfaceEncoder.register_interfaces. This should ideally be done before loading the ZOS-API with zospy.zpcore.ZOS, and in any case before the interface is used for the first time.
Methods
CanEncode
(clr_type)Check if clr_type should be encoded.
TryEncode
(obj)Try to downcast obj to its implementation.
__call__
(*args, **kwargs)Call self as a function.
register_interfaces
(new_interfaces)Register new interfaces for automatic downcasting.
- CanEncode(clr_type) bool #
Check if clr_type should be encoded.
An object can be encoded if it is an interface and its full name is present in OpticStudioInterfaceEncoder._interfaces.
- TryEncode(obj)#
Try to downcast obj to its implementation.
- classmethod register_interfaces(new_interfaces: list[str] | str) None #
Register new interfaces for automatic downcasting.
Interfaces should be registered before initializing the ZOS-API.
- Parameters:
- new_interfaceslist[str] | str
Full interface name or list of full interface names to register.
Examples
>>> import zospy.api.codecs as codecs >>> codecs.OpticStudioInterfaceEncoder.register_interfaces("ZOSAPI.Editors.NCE.ISourceColorSettings")