I have been using ZOS-API Pythonnet to perform a ray trace and save the ray trace data as text files. The following program snippet worked perfectly fine up until a few months ago. Now, when I run the same code, it does the ray trace and saves the text file without changing any of the settings.
TheSystem = TheApplication.PrimarySystem;
X, Y = np.round(np.mgrid[(-1):(1):100j, (-1):(1):100j],3)
positions = np.vstack([X.ravel(), Y.ravel()])
Field_1 = Systemdata.Fields.GetField(1)
for i in range(max_rays):
The Px and Py =0 for all the rays in the text files. Does anyone know what the issue could be?
Best answer by MichaelHView original
Assuming your code doesn’t have a bug, what’s your Python and Pythonnet version? There have been issues recently with version of Pythonnet > 2.5.2. If you are in this case, can you install Pythonnet 2.5.2 and try again?
If the script is actually able to run to the end but you just don’t see anything change, then I think pythonnet is correct, however please take David’s advice and ensure you’re not using pythonnet 3.0.
You might not have copied the entire script, but I don’t see where you initialize the type of connection from the zosapi module (
zosapi.Interactive()). So assume you have the proper connection to OpticStudio in another part of the script, I think you might be failing around lines 3-4; the
LoadFileis looking for a full file path. The default LENS.ZMX file which is loaded in OpticStudio has 0 aperture size, so I always like to add the following code immediately after a
Also, unless it’s absolutely necessary, I would suggest simplifying how you generate your px/py values; there is no reason to use mgrid, vstack, revel, or transpose. Since the pythonic way is to keep it simple, I would simply use 2 for loops (you can do this with a simple range but numpy already has the ability to normalize the coordinates with linspace):