Find out how you can save time and energy using the Zemax Programming Language!
- 136 Topics
- 365 Replies
Reding data from .dat-file into ZPL macro
Hi,I would like to read several numeric data as well as text data from a .dat-file into a zpl macro to use some of them for further use.For example, the .dat file has 5 rows and 3 lines, divided by Tabs, e.g.:Pos1 3.7 4.2 6.2 8.7Pos2 9.0 7.5 2.8 5.6Pos3 0.5 1.8 4.6 4.3Is it possible to use the READ command for reading the complete .dat-file and to select afterwards some special data for further optimization?Or would it be possible to read only some special data from the .dat-file for further use, e.g. (Row2, Line 2 = 9.0) and (Row3, Line 3 =1.8)? Best regardsRalf
Quickfocus in ZPL
Hi, I’m a bit confused that when I run the quickfocus command in ZPL, Zemax doesn’t always give me the same value, somehow I had to run my macro twice to get to the correct back focal length (my macro also changed wavelength and field setting). Is it normal to have this? Also, what would be a solution to fix this in the macro? I tried having quickfocus command twice inside the macro but it doesn’t help. Thank you very much.[Mod note: moved to more appropriate forum for ZPL related discussions.]
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
ZPL get FICL
Dear Experts,I am trying to read FICL in ZPL. Being new to ZPL I have simply tried this: vec1(1) = 1vec1(2) = 1vec1(3)=1vec1(4)=1vec1(5)=0vec1(6)=0.0366vec1(7)=0vec1(8)=0vec1(9)=0vec1(10)=0vec1(11)=0vec1(12)=0vec1(13)=0vec1(14)=0vec1(15)=0vec1(16)=0vec1(17)=0vec1(18)=0vec1(19)=1f=FICL(1)PRINT "FICL=",f, However, this returns always zero. I could not find any example or any more detailed explanation of ZPL FICL. Are there also several values returned by FICL, like SYSTEM and RECEIVER Efficiency? Can I set the specific configuration to return FICL?Many thanks for some explanation or a hint to an example file.Markus
Get TiltX or Y using ZPL Macro
Hi! I just started using the ZPL and what I would like to do is to create a solve based on a very simple geometrical relation. But, for doing this, I need to get the Tilt Y of a rectangular object (I am in NS mode).The only think I found is the numeric function NPAR, which it seems to me it only acquires parameters.What would be the right way to do it?Thank you!!!
Rounding numeric values when creating a ZPL macro
Good afternoon.I have a question about working with numeric variables when writing an ZPL macro. Is it possible to round the values assigned to variables with the required accuracy? I'm looking for functions similar to (FLOOR.MATH) and (CEILING.MATH) in Microsoft Excel. I understand that i can create a loop that allows me to sequentially compare the value of interest with i and i+1 value. I would like to create an ZPLM operand using rounding, so it seems to me that this way will slow down the optimization, especially with a high degree of rounding accuracy.As an example, we can discuss the case where the value 24.432 needs to be rounded up to 24.0 or 24.5.
A question about create automatically optimization wizard table by ZPL
HiI'm trying coding a ZPL script to create an automatic optimization wizard table.My target optimization wizard table was show as below picture. Here is producing optimization wizard table by running my ZPL script.Unfortunately, they have three differences by comparing the two created optimization wizard tables and making numbers on the above pictures. Here is a list of the parameter value for differences. This is show the partial screenshot of my ZPL script, the code also attached to set Merit Function.zip. What kind the command settings/paraments were missing in this ZPL script? That can be fixed for the three differences.
Ray intensity sequential mode Apodization
Hello,How can I obtain the intensity of single rays (either using ZPL or API) when the apodization is part of a user-defined surface?I used the “us_filt1.dll” example provided with the Zemax distribution and set G>0. The APOI(x,0) operand returns 1.0 for all positions of the pupil (0<x<1), despite the apodization applied in the dll. Thanks!
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?
Saving an image from Geometric Bitmap Image Analysis for different configuration
Hello, I would like to use a macro to save images from Geometric Bitmap Image Analysis for different configuration.I wrote this macro in ZPL to save the images obtained for different configurations but it doesn’t work:! Read the # of configsNCONFIG = NCON()!Read pathsettingfiles$ = "...\Zemax\Configs\IMB.CFG"! Execute for each configFOR i, 1, NCONFIG, 1 ! Set config SETCONFIG i img_file$ = $STR(i) + ".png" MODIFYSETTINGS settingfiles$, GBM_OUTPUT, img_file$ OPENANALYSISWINDOW "IBM" PAUSE THREADS NEXTPRINT "DONE!"The configuration changes and the Geometric Bitmap Image Analysis window opens up and displays the right image but nothing is saved. Moreover, the output file name keeps the initial name and it isn’t modifying for each configuration. Do you have any idea to save those images ? (the folder path doesn’t matter) I also wrote another ZPL macro which works and saves the image of the opened window following the different configuration but it still not really what
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,
GETPSF General Error
I have a macro calling GETPSF for various thicknesses to the focal plane, and I am getting np = -3, 'General Error' returned when I use Gaussian apodization. I have checked that the FFT PSF is calcualting without error for the same thicknesses as are in my macro. What else can cause a 'General Error' in response to a call to GETPSF?
POLDEFINE use case in ZPL
Hello, I am trying to run a polarization analysis on a system and am using different polarization states as input. I have created a macro that does this by first using 'POLDEFINE' to define a polarization state, and then using the CODA function to get the information I need. I then use the 'POLDEFINE' function again to describe a new polarization state, and the use the CODA function again. Though, this is unfortunately not working. For some reason, all data sets are the exact same. I am curious how the POLDEFINE is actually working. Are the CODA and POLDEFINE functions possibly decoupled? And if so how do I go about changing the system input polarization using the zpl?
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
Can I create a new text file for output inside of ZPL macro
I would like to create a new text file from inside of a ZPL macro for saving data while the macro runs. I see the OPEN command, but it requires the file to already be created. I do not see any keyword for creating the new file. Is there a way to create new files from inside of a running Macro? Thanks Chris Buchholz
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.
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.