Skip to main content

I’m writing a script to do a lot of automation and has a lot of inputs for different configurations.  I’m trying to combine multiple .ZBF, each with a different field position.  This means I need to use ZBFRESAMPLE to shift the images to match their offsets compared to the on-axis field.  This is quite handy since I can use physical units to shift the image rather than try and figure out how many pixels I need to shift by.

The only other option I can think of is to have the API run a macro, however, I think I would need to have the ability to have the API input variables into a macro which I don’t think is possible.

Does anyone know if it’s possible to call just one ZPL function in API or do I need to figure out how to mix API and ZPL?

How can I call a ZPL macro from ZOS API? | Zemax Community


Hi @Alex.Tripsas,

 

I feel like one could rewrite a ZBFRESAMPLE function for the ZOS-API. It could be a nice addition to ZOSPy. Without knowing the exact implementation of ZBFRESAMPLE there might be small differences, but it’ll be more efficient than having ZOS-API call for a ZPL macro.

The ZBF file format is documented in the Help File, but I copy it for reference:

 

Zemax Beam File (ZBF) Binary Format

The ZBF binary file format is defined as follows. All integers are 4 bytes, all doubles are 8 bytes.

1 integer: The format version number, currently 1.1 integer: The number of x samples (nx).1 integer: The number of y samples (ny).1 integer: The "is polarized" flag; 0 for unpolarized, 1 for polarized.1 integer: Units, 0 for mm, 1 for cm, 2 for in, 3 for meters. 4 integers: Currently unused, may be any value.1 double: The x direction spacing between points.1 double: The y direction spacing between points.1 double: The z position relative to the pilot beam waist, x direction.1 double: The Rayleigh distance for the pilot beam, x direction.1 double: The waist in lens units of the pilot beam, x direction.1 double: The z position relative to the pilot beam waist, y direction.1 double: The Rayleigh distance for the pilot beam, y direction.1 double: The waist in lens units of the pilot beam, y direction.1 double: The wavelength in lens units of the beam in the current medium.1 double: The index of refraction in the current medium.1 double: The receiver efficiency. Zero if fiber coupling is not computed.1 double: The system efficiency. Zero if fiber coupling is not computed.8 doubles: Currently unused, may be any value.2*nx*ny double: Ex values.If polarized, 2*nx*ny Ey values follow the Ex values.

The Ex and Ey values are defined such that the Ex*Ex + Ey*Ey is in units of watts.

Zemax Beam File (ZBF) text format

The ZBF text file format is defined as follows. The first line must be the single character “A”, followed by the other data values specified.

A: indicates a text file.

version: The format version number, currently 1.

nx: The number of x samples.

ny: The number of y samples.

ispol: The "is polarized" flag; 0 for unpolarized, 1 for polarized.

units: 0 for mm, 1 for cm, 2 for in, 3 for meters.

unused 1: Currently unused, may be any value.

unused 2: Currently unused, may be any value.

unused 3: Currently unused, may be any value.

unused 4: Currently unused, may be any value.

dx: The x direction spacing between points.

dy: The y direction spacing between points.

zx: The z position relative to the pilot beam waist, x direction.

Rx: The Rayleigh distance for the pilot beam, x direction.

wx: The waist in lens units of the pilot beam, x direction.

zy: The z position relative to the pilot beam waist, y direction.

Ry: The Rayleigh distance for the pilot beam, y direction.

wy: The waist in lens units of the pilot beam, y direction.

lambda: The wavelength in lens units of the beam in the current medium.

index: The index of refraction in the current medium.

re: The receiver efficiency. Zero if fiber coupling is not computed.

se: The system efficiency. Zero if fiber coupling is not computed.

unused 1: Currently unused, may be any value.

unused 2: Currently unused, may be any value.

unused 3: Currently unused, may be any value.

unused 4: Currently unused, may be any value.

unused 5: Currently unused, may be any value.

unused 6: Currently unused, may be any value.

unused 7: Currently unused, may be any value.

unused 8: Currently unused, may be any value.

Ex real value for point 1

Ex imaginary value for point 1

Ex real value for point 2

Ex imaginary value for point 2

etc... for 2*nx*ny Ex values.

If polarized, followed by 2*nx*ny Ey values.

The Ex and Ey values are defined such that the Ex*Ex + Ey*Ey is in units of watts.

 

I don’t have the bandwidth to work on that now, but if I get a chance I’ll give it a go. Let me know if you try yourself in the meantime.

Take care,

 

David


I would be nice if there would be a more direct way of running a ZPL macro, as by adding an additional surface you change the setup a bit, which feels a bit tricky… (for us the main application would be to save the pictures OpticStudio generates, e.g. of the system, a feature which is not available through the API (as far as I know)


I would be nice if there would be a more direct way of running a ZPL macro, as by adding an additional surface you change the setup a bit, which feels a bit tricky… (for us the main application would be to save the pictures OpticStudio generates, e.g. of the system, a feature which is not available through the API (as far as I know)

Depending on the picture that should be doable in the API.  The way I’ve done it for analyses is to take the raw text data that will generate the same image.  But I don’t think that works for saving images like a 3-D layout.


Hi @Alex.Tripsas,

 

I feel like one could rewrite a ZBFRESAMPLE function for the ZOS-API. It could be a nice addition to ZOSPy. Without knowing the exact implementation of ZBFRESAMPLE there might be small differences, but it’ll be more efficient than having ZOS-API call for a ZPL macro.

The ZBF file format is documented in the Help File, but I copy it for reference:

 

Zemax Beam File (ZBF) Binary Format

The ZBF binary file format is defined as follows. All integers are 4 bytes, all doubles are 8 bytes.

1 integer: The format version number, currently 1.1 integer: The number of x samples (nx).1 integer: The number of y samples (ny).1 integer: The "is polarized" flag; 0 for unpolarized, 1 for polarized.1 integer: Units, 0 for mm, 1 for cm, 2 for in, 3 for meters. 4 integers: Currently unused, may be any value.1 double: The x direction spacing between points.1 double: The y direction spacing between points.1 double: The z position relative to the pilot beam waist, x direction.1 double: The Rayleigh distance for the pilot beam, x direction.1 double: The waist in lens units of the pilot beam, x direction.1 double: The z position relative to the pilot beam waist, y direction.1 double: The Rayleigh distance for the pilot beam, y direction.1 double: The waist in lens units of the pilot beam, y direction.1 double: The wavelength in lens units of the beam in the current medium.1 double: The index of refraction in the current medium.1 double: The receiver efficiency. Zero if fiber coupling is not computed.1 double: The system efficiency. Zero if fiber coupling is not computed.8 doubles: Currently unused, may be any value.2*nx*ny double: Ex values.If polarized, 2*nx*ny Ey values follow the Ex values.

The Ex and Ey values are defined such that the Ex*Ex + Ey*Ey is in units of watts.

Zemax Beam File (ZBF) text format

The ZBF text file format is defined as follows. The first line must be the single character “A”, followed by the other data values specified.

A: indicates a text file.

version: The format version number, currently 1.

nx: The number of x samples.

ny: The number of y samples.

ispol: The "is polarized" flag; 0 for unpolarized, 1 for polarized.

units: 0 for mm, 1 for cm, 2 for in, 3 for meters.

unused 1: Currently unused, may be any value.

unused 2: Currently unused, may be any value.

unused 3: Currently unused, may be any value.

unused 4: Currently unused, may be any value.

dx: The x direction spacing between points.

dy: The y direction spacing between points.

zx: The z position relative to the pilot beam waist, x direction.

Rx: The Rayleigh distance for the pilot beam, x direction.

wx: The waist in lens units of the pilot beam, x direction.

zy: The z position relative to the pilot beam waist, y direction.

Ry: The Rayleigh distance for the pilot beam, y direction.

wy: The waist in lens units of the pilot beam, y direction.

lambda: The wavelength in lens units of the beam in the current medium.

index: The index of refraction in the current medium.

re: The receiver efficiency. Zero if fiber coupling is not computed.

se: The system efficiency. Zero if fiber coupling is not computed.

unused 1: Currently unused, may be any value.

unused 2: Currently unused, may be any value.

unused 3: Currently unused, may be any value.

unused 4: Currently unused, may be any value.

unused 5: Currently unused, may be any value.

unused 6: Currently unused, may be any value.

unused 7: Currently unused, may be any value.

unused 8: Currently unused, may be any value.

Ex real value for point 1

Ex imaginary value for point 1

Ex real value for point 2

Ex imaginary value for point 2

etc... for 2*nx*ny Ex values.

If polarized, followed by 2*nx*ny Ey values.

The Ex and Ey values are defined such that the Ex*Ex + Ey*Ey is in units of watts.

 

I don’t have the bandwidth to work on that now, but if I get a chance I’ll give it a go. Let me know if you try yourself in the meantime.

Take care,

 

David

I think this is probably the best approach.  I’d like to avoid the ZPL entirely if I can.  Luckily I have the bandwidth to do this but was hoping for a quicker solution!


Reply