How can you write slope cross-section analysis text results to a file?
Hi,
I would like to write a macro that runs the surface slope analysis and outputs the “Text” tab results (X-Coord, Y-Coord, and Slope) to a file. I was thinking of using GetTextFile, but I don’t see a string code for surface slope cross section (or slope either). What’s the best way to do this?
Thank you,
-Jen
Page 1 / 1
@JenR
If you didn’t find the String Code, this means its probably not implemented. By chance, the Analyze..Surface..Slope and Slope Cross Section analyses are available in the ZOSAPI, and you could achieve the same as GetTextFile with this Python code snippet:
I’m not affiliated in any way with the website above, but I read the book when I transitioned from MATLAB to Python. Then, its good to be aware about the community-driven ZOSPy: https://pypi.org/project/zospy/, which really facilitate the ZOSAPI integration in Python.
That being said, I know not everyone has the bandwidth or willingness to learn a new programing language. If that’s your case, I created a User-Defined Operand (UDOC02.exe), that will run a Surface Slope and save its text output in your ...Documents/Zemax/Samples/ folder under the name surface_slope.txt.
This is the code of the User-Defined operand for your reference (this is already compiled in UDOC02.exe, you don’t need to care about this part):
Will run the Surface Slope analysis and create the text file.
You could also insert this operand when required with ZPL.
To install the User-Defined Operand, just download the ZIP attached to my answer, extract its ZAR archive, and open it in OpticStudio (it will automatically extract UDOC02.exe and place it in the correct folder).
Note that its an inefficient roundabout way of achieving what you want.
Take care,
David
Hi David,
Thank you! I was able to get the user-defined operand to run, but is there any way to choose which surface the calculation is done on? Also, I am really looking for the slope cross-section (3 columns of data: X-coordinate, Y-coordinate, slope), not the slope map of the whole surface.
-Jen
Hi Jen,
All of this is possible. I’ve made UDOC03.exe for the cross-section slope and it uses the column Hx for the Surface number. This is the modified code:
Thank you once again! Sorry to keep going back and forth, but now the computation is only done on surface 2 even if I have a different number in the Hx column. I though the surface could be changed based on the value of Hx?