File

These tools replace the open lens, read its identity, and save it.

New lens

Create a new lens and return its identity.

new_lens(ctx: Context, discard_changes: bool = False) → dict[str, str | bool]

Replace the lens open in the OpticStudio window with a new lens and return its identity.

A lens with unsaved changes stays open unless discard_changes is true. The new lens has not been saved.

Parameters:

discard_changes – True discards unsaved changes. False refuses when the open lens needs to be saved.

Returns:

The lens identity after the new lens is created. The fields are the same as those returned by get_lens_metadata().

Return type:

dict[str, str | bool]

Raises:

ValueError – The lens has unsaved changes and discard_changes is false, or OpticStudio cannot create the lens.

Lens file

Save the open lens and return its identity.

get_lens_metadata(ctx: Context) → dict[str, str | bool]

Return identity details for the lens open in the OpticStudio window.

Returns:

  • file – Full path of the lens file. Empty when the lens has not been saved.

  • name – System name.

  • title – Lens title from System Explorer Title/Notes.

  • author – Author from System Explorer Title/Notes.

  • notes – Notes from System Explorer Title/Notes.

  • mode – Sequential or NonSequential.

  • needs_save – True when the window has unsaved changes.

  • is_project_directory – True when the lens is stored as a project directory rather than a single file.

Return type:

dict[str, str | bool]

save_lens(ctx: Context, path: str | None = None) → dict[str, str | bool]

Save the lens open in the OpticStudio window and return its identity.

Omit path to save the current file. Pass a full path to save the lens as a new file. The window then uses that file. An existing file at that path is replaced. A lens that has never been saved needs a path.

Parameters:

path – Full path of the new lens file, such as a .zmx or .zos file. None saves the current file.

Returns:

The lens identity after the save. The fields are the same as those returned by get_lens_metadata().

Return type:

dict[str, str | bool]

Raises:

ValueError – The lens has no current file, path is not a full path, or OpticStudio cannot save.