Skip to main content
Solved

Use "Insert Lens" in ZPL macro?


Maria
Forum|alt.badge.img+1

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

Best answer by MichaelH

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.

View original
Did this topic help you find an answer to your question?

3 replies

MichaelH
Ansys Staff
Forum|alt.badge.img+2
  • Ansys Staff
  • 342 replies
  • May 3, 2022

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'))


MichaelH
Ansys Staff
Forum|alt.badge.img+2
  • Ansys Staff
  • 342 replies
  • Answer
  • May 3, 2022

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.


Maria
Forum|alt.badge.img+1
  • Author
  • Monochrome
  • 5 replies
  • May 6, 2022

Thank you, Michael!


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings