problem for setting system aperture
je-ro-me opened this issue · 6 comments
I work with a Zemax file provided by a customer (so unfortunately, I cannot share it). It's a simple refractive telescope with 6 lenses.
My problem is: I cannot change the position of the system aperture STOP with PyZDDE.
I can do it manually in Zemax, it works well and there's nothing special.
If I use the following code:
`import pyzdde.zdde as pyz
filename = "C:\Zemax Model\Instrument_telescope.zmx"
link = pyz.createLink()
link.zLoadFile(filename)
link.zPushLens()
number of surfaces
print link.zGetNumSurf()
changing STOP position
print link.zGetSystemAper()
link.zSetSystemAper(aType=3,stopSurf=3,aperVal=20.)
print link.zGetSystemAper()
link.zPushLens()
print link.zGetSystemAper()
link.close()`
I get the following results:
19
systemAper(apertureType=3, stopSurf=1, value=39.8)
systemAper(apertureType=3, stopSurf=3, value=20.0)
systemAper(apertureType=3, stopSurf=1, value=39.8)
Press any key to continue . . .
Did I forget something ? Or could it be a bug ?
I checked with two other files (the Zemax sample Double Gauss 5 degrees, and another telescope from a different customer) and did not get this problem. This is an issue for me as I am writing a code that must be used with any optical system.
Thanks for the help
Jerome
Some more information :
with the above code, the semi-diameter of surf 3 is set to 20 in Zemax when calling link.zPushLens(). The same function link.zPushLens() sets the system STOP back to surface 1.
Hi @je-ro-me,
Honestly I don't know what's going on. It seems very strange because there is NO reason AFAIK why the system aperture would change automatically by calling zPushLens()
. This function just "moves" the current lens in the DDE server to running Zemax application's LDE. Also, as you have experimented yourself with two other files, the behavior seems consistent with our expectation. Can also print the system data (zGetSystem()
before calling zPushLens()
to see if the stop surface is 3? Also, are you absolutely sure that there are no other calls such as zGetRefresh()
or zGetUpdate()
, in between? I don't have a zemax usb key with me right now (I will probably have one tomorrow). If you have not resolved the issue by then, I will test out some scenarios tomorrow. Keep me posted.
Hi @indranilsinharoy
Thanks very much for your reply!
I could resolve the problem partly as follows: I re-create the same optical file from scratch and got a second Zemax file that looks identical (could not see a difference in the lens specifications, achieved performances, system parameters, etc..). And with this file the call of link.zSetSystemAper() works well.
So I solve the problem for my needs, but could not understand the issue which I don't really like.
I wonder if I missed some parameter when making this second file, or if there may be something with the file I was using (e.g. I think it was created with an older Zemax version) ?
In any case, using the old (problematic) file:
- I confirm I don't make any call to zGetRefresh() or zGetUpdate()
- if I use zGetSystem() before trying to set the aperture, after trying to set the aperture=before calling zPushLens(), and after calling zPushLens() I get the following in the Console window:
systemAper(apertureType=3, stopSurf=1, value=39.8)
systemData(numSurf=20, unitCode=0, stopSurf=1, nonAxialFlag=1, rayAimingType=2,
adjustIndex=1, temp=20.0, pressure=1, globalRefSurf=2)systemAper(apertureType=3, stopSurf=3, value=20.0)
systemData(numSurf=20, unitCode=0, stopSurf=3, nonAxialFlag=1, rayAimingType=2,
adjustIndex=1, temp=20.0, pressure=1, globalRefSurf=2)systemAper(apertureType=3, stopSurf=1, value=39.8)
systemData(numSurf=20, unitCode=0, stopSurf=1, nonAxialFlag=1, rayAimingType=2,
adjustIndex=1, temp=20.0, pressure=1, globalRefSurf=2)
Press any key to continue . . .
Hi @je-ro-me,
I really don't have any idea why this is happening. This is not an expected behavior, and in my few years of using PyZDDE, I have never faced such an issue. Also, this type of cases are hard to debug without the lens file. However, I am almost certain that the problem is not due to PyZDDE.
As far as ensuring that you have created the new design without missing any parameters, I would start with the following:
- Most of the zmx files are basically text files (unless they are encrypted I guess) so I would first try to use any file compare tool to find the differences in the .zmx file
- I would suggest that you ask in the Zemax forums if there are any formal method for comparing two zemax files.
Hi @indranilsinharoy
I think I found where the problem comes from!
As you suggested, I tried to track all differences between the two files.
- first, I used the file comparator from Zemax, but it doesn't show any difference
- when opening the .zmx files with a text editor I noticed few small differences.
In particular I spotted some lines at the end of the old file (the one that creates the problem) that are not in the new file.
The end of the new Zemax file:
BLNK
TOL TOFF 0 0 0 0 0 0 0 0
MNUM 1 1
MOFF 0 1 "" 0 0 0 1 1 0 0.0 "" 0
The end of the old Zemax file (for which link.zSetSystemAper() doesn't work):
CONF 1 0 0 0 0 0 0 0 0 0
BLNK
TOL TOFF 0 0 0 0 0 0 0 0
MNUM 1 1
WAVE 1 1 6.770000000000E-001 0 0 0 1 1 1.000000000000E+000 0.000000000000E+000 0 "" 0
MOFF 0 1 "" 0 0 0 1 1 0 0.0 "" 0
YFIE 1 1 0.000000000000E+000 0 0 0 1 1 1.000000000000E+000 0.000000000000E+000 0 "" 0
YFIE 2 1 0.000000000000E+000 0 0 0 1 1 1.000000000000E+000 0.000000000000E+000 0 "" 0
MOFF 0 1 "" 0 0 0 1 1 0 0.0 "" 0
XFIE 1 1 0.000000000000E+000 0 0 0 1 1 1.000000000000E+000 0.000000000000E+000 0 "" 0
XFIE 2 1 1.000000000000E-001 0 0 0 1 1 1.000000000000E+000 0.000000000000E+000 0 "" 0
STPS 0 1 1.000000000000E+000 0 0 0 1 1 1.000000000000E+000 0.000000000000E+000 0 "" 0
APER 0 1 3.980000000000E+001 0 0 0 1 1 1.000000000000E+000 0.000000000000E+000 0 "" 0
MOFF 0 1 "" 0 0 0 1 1 0 0.0 "" 0
MOFF 0 1 "" 0 0 0 1 1 0 0.0 "" 0
MOFF 0 1 "" 0 0 0 1 1 0 0.0 "" 0
If I delete the two lines that start with "STPS" (for stop system? seems to indicate that the system stop is at surface 1) and "APER" (seems to set the system aperture size), then the call to link.zSetSystemAper() works well!
Interestingly, if I delete only the line with "STPS" then the call to link.zSetSystemAper() can change the stop position to surface 3, but not its size.
So it seems that PyZDDE cannot modify the system stop position and size if they are indicated by extra lines at the end of the .zmx file.
That's interesting. However, I don't know exactly what settings in lens design (adds the two lines in the end) and prevents modification of the aperture settings via an external interface. I will keep your findings in mind in future. Thanks. I'm glad that you were able to resolve the problem.
Also, since it is not really a PyZDDE issue, I am going to close it.