Skip to main content

Hi!

I am trying to use "Insert Lens" function (from File tab) in a ZPL macro. Has anyone seen a keyword for it in ZPL?

Thanks!

Maria

Hi Maria,

There is no equivalent in the ZPL but you can use the ZOS-API to accomplish this.  You can use the built-in function from the Lens Catalog tool under the Libraries tab (TheSystem.Tools.OpenLensCatalogs()), but this will only allow you to insert a lens from a ZMF vendor catalog.  If you want insert a custom ZMX/ZOS file, you can create 2 IOpticalSystem using the same connection and then use TheSystem.LDE.CopySurfacesFrom() to copy the surfaces from one optical system to the other.  Below is Python code to achieve this second suggestion: 

import zosapi, os

# connect to OpticStudio

zos = zosapi.App()

# create a second system

zos.TheSystem2 = zos.TheApplication.CreateNewSystem(zos.ZOSAPI.SystemType.Sequential);

# load the files: TheSystem will be the main file and TheSystem2 will be the file you want to insert

zos.TheSystem.LoadFile(os.path.join(zos.TheApplication.SamplesDir, r'Sequential\Objectives\Double Gauss 28 degree field.zmx'), False)

zos.TheSystem2.LoadFile(os.path.join(zos.TheApplication.SamplesDir, r'Sequential\Objectives\Doublet.zmx'), False)

# copy the surfaces into the main system

zos.TheSystem.LDE.CopySurfacesFrom(zos.TheSystem2.LDE, 1, zos.TheSystem2.LDE.NumberOfSurfaces - 2, 1)

# save system & verify

zos.TheSystem.SaveAs(os.path.join(zos.TheApplication.ZemaxDataDir, 'insertlens.zmx'))


As a follow-up (too early in the morning, brain wasn't working), you can use the LOADLENS keyword with the appendflag indicating which surface you want to insert the new file at in the LDE.


Thank you, Michael!


Reply