Solved

How to do a NEW LENS from ZPL?

  • 12 March 2022
  • 5 replies
  • 197 views

Userlevel 5
Badge +3

Is there a way to start a clean new lens file from within ZPL?  Some of my macros need a clean LENS.ZMX file to start out with.

Thanks, Mike

icon

Best answer by Jeff.Wilde 12 March 2022, 20:07

View original

5 replies

Userlevel 7
Badge +3

You could try manually creating a new file and saving it, say as LENS.ZMX, in the default directory.  Then, in your ZPL code use LOADLENS to load it in place of the existing model.

LOADLENS "LENS.ZMX", 0, 1
UPDATE ALL

 

Userlevel 5
Badge +3

Hi Jeff and thanks, I know that method works.  What I was hoping for was a way to create a new clean LENS.ZMX file from within a macro.  Sometimes my LENS.ZMX files aren’t clean new starts, but instead have a lens already in them, which screws up the macro.

Some way to get there using a command line call from ZPL?  I’m not experienced with doing that but I can learn!

Mike

Userlevel 7
Badge +3

Hi Mike,

Ok, I see.  Yes, the LENS.ZMX naming convention is used by default, and it may contain a model from a previous session.  Instead, just create a new blank file and give it a unique name, say LENS_CLEAN.ZMX.  Then you should be able to consistently load this file and get a clean start.  In the attached pdf file, I put together a sequence of screenshots that demonstrate the process.  Let me know if I’m still missing something about your question…

Regards,

Jeff

Userlevel 5
Badge +3

Thanks Jeff, good idea to create a unique file name to be used with the macro.

DIFFERENT QUESTION AND APPROACH: I found “NewLens” down in Extensions.

NewLens
This item erases the current lens. The “minimum” lens that remains is identical to the lens in
the Lens Data Editor when “File, New” is selected. No prompt to save the existing lens is
given.

I also found ‘New’ in the ZOS-API.NET section:

New’: Create a new (default) Lens Data File (Lens.ZMX)
ThePrimarySystem.New(saveIfNeeded: false);

Are you familiar with using these calls?  

Can someone write me the code to call either of these from within ZPL?  I want to learn how to do new things in ZOS.  Thanks, Mike

 

Userlevel 7
Badge +3

Hi Mike,

As we all know, ZPL is the original built-in scripting language.  It’s reasonably powerful and fairly easy to use.  In the past, it was also possible to programmatically manipulate models using a third-party language that supported DDE extensions (like C or Matlab).  However, DDE extensions are now depricated, having been replaced by ZOS-API which is extremely versatile, providing methods for implementing almost any operation that can be done manually inside the GUI.   

ZOS-API is based on object-oriented programing and allows scripts to be written in a third-party language.  So, if you want to learn ZOS-API, the first step is to pick your language of choice (options include: C++, C#, Matlab, Python or Mathematica).  There are several example scripts provided in the ZOS-API Syntax Help documentation.  For your case, to get started, you can take a look at Example 01 (New File and QuickFoucs).

 

So, in a nutshell, ZPL and ZOS-API are two separate methods for scripting.  Not sure why you would want to try and mix them.  If you have a lot of ZPL macros already written, and need to tweak them, I think it’s probably best to look for pure ZPL solutions (as opposed to trying to mix ZPL with ZOS-API, which I’ve never seen done before, but perhaps it is possible). 

However, ZOS-API is by far the more powerful of the two scripting approaches (allowing a user to do things that simply aren’t possible with ZPL), but be forewarned that the learning curve for ZOS-API is a bit steep.  I had to work through several examples on many separate occasions to really get the hang of it.  I primarily use Matlab for this purpose, and find that OpticStudio under Matlab control (via the “Interactive Extension” mode of operation) can be quite useful.

Regards,

Jeff

 

Reply