Find out how you can save time and energy using the Zemax Programming Language!
- 136 Topics
- 369 Replies
ZPL Nuances & Best Practices
Hey Community,I’m starting this thread as a place to document some of the “pitfalls” of the ZPL language. The ZPL is extremely powerful but since OpticStudio is trying to create a new language, the parsing is sometimes problematic.Variable NamesYou can actually assign a value to a number (the ZPL treats the number as a variable name). So while OpticStudio won’t throw an error, you should be very careful when picking variable names:PRINT 1 + 2 # answer is 31 = 2PRINT 1 + 2 # answer is 4FOR LoopsThere is always round-off when dealing with decimals and this becomes especially true when trying to use a decimal step size in a FOR loop. Rather than using decimals as either the start, end or step size, you should keep these as integers and convert to decimals inside the FOR loop:RecommendedFOR i = 0, 10, 1 px = i / 10NEXT Not RecommendedFOR i = 0, 1, 0.1 px = iNEXTSpeed Up CalculationsAll calculations via the ZPL force an update to both the GUI and the core code. Pushing data to t
Ignore errors in ZPL
Is there a way to ignore errors while running a ZPL, and keep it running? I have a ZPL that opens files and some files come up with the following error. Zemax Error Message Cannot determine object coordinates! OK I select OK and the ZPL can continue running. But since I am running through many files this comes up often and doesn't continue until I select OK. Is there a way to ignore these errors and allow a ZPL to continue running? Without having to select OK each time? Thank you,
Some questions about when used the macro commnad SYSP to convert the field type
such as fist type i used the filed tpye is real image heightbut i want to convert the type to angle through the macro commandSYSP 100,0however it convert result is the field type is angle but the field datas is not changelike the filed data in No. 12 is 3.4mm in real image heightbut after convert the filed data in No. 12 is 3.4° in anglei want to get the results are similar ,the field datas follws the field type
Print statements in ZPL are suppressed during the script is running
Dear support team, it seems that a 'Print' statement in ZPL is suppressed during the script is running. Then at the end of the script all print statements are executed at once. I guess, this is a kind of optimisation? However, I am running large scripts and I would like to see the progress in the command window . So I would like the print statement to react directly when it is called. Is this possible? Thank you, Christof.
GETTEXTFILE writes empty file randomly
I am running Zemax OpticStudio 19.4 SP2 on Windows 10. When I run the following line in a loop in a macro, randomly, some of the files are empty. The non-empty files are correct. GETTEXTFILE OUTPUT_PSF_FILE$, Hps, CFG_FILENAME$, 1 Please help! Thanks, Qiang
NSC Polygon Object: where is prism_array.zpl macro?
I found a NSC polygon object 'prism_array.pob' that does ALMOST what I want (put a linear array of microprisms on a 'slab' of material), but I would like to generate (micro-)prisms having different angles, spacing, scale, and different thickness 'slabs.' Editing the .POB file shows that it starts as follows with the comment that it was created by a ZPL macro 'prism_array.zpl': '! This polygon object was created by the prism_array.zpl macro ! V 1 82.50000000 50.00000000 0 V 2 82.50000000 -50.00000000 0 V 3 -82.50000000 -50.00000000 0 V 4 -82.50000000 50.00000000 0 R 1 2 3 4 0 0 V 5 82.50000000 50.00000000 10.00000000 ...' But I can't find the prism_array.zpl macro to edit it, see what can be varied, or to use it to generate new prism array .POBs. Can anybody provide a copy of prism_array.zpl, or point me to where to find it? I have the latest OpticStudio release 20.2 (Professional, perpetual), and can't find
How to use the GETTEXTFILE function with an NSC detector
Is there a way to to use the GETTEXTFILE function with an NSC detector? I’m running into the same issue, and couldn’t figure it out from the help page of the function. I’m currently using SAVEWINDOW from a detector window opened to the text tab and getting the same message.[Mod note: moved the post to a new forum thread.]
"GetNSCPosition" is not recoganize in ZPL
I applied a solve on position z by 'SOLVETYPE'. Then I need to refer to the result of solve, i.e. the position os z. I am trying to using 'GETNSCPOSITION'. According to the EXTENSION DATA ITEMS, this should return the object position and angle and material. However, the viewer shows 'Unknown symbol GETNSCPOSITION.' The similar command 'SETNSCPOSITION' works fine. But not the GETNSCPOSITION. It seems in the editor, it does not recoganize it as a legal command Can anyone help something is wrong? Thanks.
how to force an analysis window to read a changed/modified config file
I have a lens file open, with some analysis windows open. Using ZPL, I want to loop through and change the .CFG file (this is for a detector window in non-sequential.). I haven't done it yet, but I think this will change the settings: ModifySettings (filename,DVW_FILTER, ‘new_filter_string”, ‘DVR’) , or something like that, once I get the quotes straightened out. However, my question is: How do I force the open analysis window to update with the new .cfg file? In ZPL Macro, there does not seem to be any command like: LoadNewConfig(Filename, WindowNumber). I know I might be able to open a new analysis window, but for reasons of being able to see what is going on, I'll save that for Option B. thanks for your time. John
Geometric ESF vs FFT ESF
In otpicstudion I am using, there are two way to get edge spread function. One is gemetric ESF, and the other is FFT ESF. I guess that FFT ESF are based on FFT, but don't know how the geometric ESF is calculated. Is it based on raytrace method rather than wave property of light?
CodeV to opticsStudioConverter-ZPL latest file! Version: 2.06.4 ! August 28, 2019
Need to convert from codeV to Zemax. Can you please provide the latest CodeV to opticsStudioConverter.ZPL macro. The current file is working properly. Following error 0098 SCC C6 0 No mapping for command SCC 0098 Nothing to convert ! Version: 2.06.4 ! August 28, 2019 ! NOTE: This Macro constructs Zemax OS Optical system using Code V seq file 1333 PIK SCO S14 Z2 C8 SCO S14 Z1 C8 1.00162632102796 No mapping for command PIK 1333 Nothing to convert 1334 PIK SCO S14 Z2 C9 SCO S14 Z1 C9 1.00162632102796 No mapping for command PIK 1334 Nothing to convert 1335 PIK SCO S14 Z2 C10 SCO S14 Z1 C10 1.00162632102796 No mapping for command PIK 1335 Nothing to convert 1336 PIK SCO S14 Z2 C11 SCO S14 Z1 C11 1.00162632102796 No mapping for command PIK 1336 Nothing to convert 1337 PIK SCO S14 Z2 C12 SCO S14 Z1
How to detect by source location?
I am using non-sequential mode. And I want to detect by automatically moving the location of the source by 1mm. How to write zpl file? I want to figure out the number of hits by point source location. Ex) point source location(0,0,0) >> clear & trace >> point source location(1mm,0,0) >> clear & trace >> point source location(2mm,0,0) >> clear & trace >> point source location(3mm,0,0) >> clear & trace ...
Legend problem-macro plots
Dear Zemax team, Could you please help me put the legends showing the color of each line right next to the regarding legend or is there a way to do this with labels? As you can see, the labels do not show the colored line near them. So, it is hard to distinguish which one belongs to which data line. Next graph below is from an article on your webpage about diffractive optics macro and it does not have this problem. Attached in my macro. At the end of my macro , you can see how I call all the plots in a SUB routine. Your urgent help on this would be appreciated! No problem with legends or labels in the knowledge base article plot about diffractive optics below;
psf data values in um apart
when i use getpsf in zpl, the result mentioned that there are np data points, and spaced by micrometers apart. what does it mean? Is it the average position between the psf data points? also, the data spacing reduces as pupil sampling increases. do you have some references for me to better understand this results.
NSDE Data# not working as expected
Can you confirm the Data# field of NSDE is not working as expected, both in ZPL and MF? Help reference: The Optimize Tab (non-sequential ui mode) > Automatic Optimization Group (optimize tab, non-sequential) > Merit Function Editor (optimize tab, non-sequential) > NSC Operands I expect the following to work in fully non sequential mode: ! Detector color object reference det = 4 TotalFlux = NSDE(1,det,0,0,0,0) MaxIrradiance = NSDE(1,det,-1,0,1,0) But actually, the following work for me, i.e. return the correct quantity: TotalFlux = NSDE(1,det,0,0,1,0) MaxIrradiance = NSDE(1,det,-1,0,2,0) Therefore, if this is confirmed, the Data# reported in the table of the Help is wrong and should be incremented by 1. Thank you
Getting the Clear Aperture values from the surface names using a ZPL macro
Hello! I am new to ZPL Programming. I currently have the task to extract clear aperture values from Zemax (not according to surface number but the surface names ) using a ZPL macro. I am currently struggling to find the right command. It would be great if someone could help. Kind Regards,Santhoshi
Feature Request: Add Data 40 to NSRA to report the Face Number
The NSRA operand is very powerful since you can get almost all ray data about a given segment without saving a ZRD. However, access to which face a segment hit is impossible without saving a ZRD to disk and then parsing the ZRD; the ZOS-API single & batch ray trace for non-sequential mode piggyback on the old DDE structs which are limited to 18 data values, which is why the IRayTraceNSCSourceData is limited to 18 outputs (and Face Data is not one of those outputs).This severely limits ray/object analysis in non-sequential mode. The quickest solution to programmatically access Face Data would be to simply add Data 40 to the NSRA operand so you can test which face a segment hit and then get the needed information by using the other Data values.
Already have an account? Login
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.