Question

Export volume detector data Zemax?


 

Hello Forum,

I got a volume detector with 100 x/y-planes in the z direction (#z-pixels). See screenshot below.

When running NSC ray tracing I want to save all of them to individual text files 1;2;3;4;5…. 100

automatically if possible.

Any suggestions of using a macro would be appreciated.

 

Thank you Klaus

 


3 replies

Userlevel 7
Badge +2

@klaus

 

This should do what you want:

# Detector number
detector_object_id = 2

# Number of z-slices
number_of_z_slices = NPAR(1, detector_object_id, 6)

# Path to the settings file of the Detector Viewer
# can be obtained by pressing Save button in the settings of the Detector Viewer
# the settings file is in the same folder as the lens file
settings_file$ = "C:\Users\{your_username}\Documents\Zemax\Samples\lens.CFG"

# Change format for $STR() function (zero-padded six digits integer)
FORMAT "%#06i" LIT

# Loop over the z-slices
FOR zz, 1, number_of_z_slices, 1
    # Modify setting to use a different z-slice
    MODIFYSETTINGS settings_file$, DVW_ZPLANE, zz
    
    # Construct filename with the z-slice index
    filename$ = "E:\" + $STR(zz) + ".txt"
    
    # Save Detector Viewer as a text file using the modified settings
    GETTEXTFILE filename$, "Dvr", settings_file$
NEXT

Note that you will need to update the path to the Detector Viewer settings file (*.CFG). To create this file in the first place, you must open the settings of a Detector Viewer and press the Save button in the bottom-right corner.

This will create a file in the same folder of your lens, with the same file name and the .CFG extension. The rest of the code should be self-explanatory. Please let me know otherwise.

PS: I am assuming a raytrace was run a this point, otherwise, you need to perform a raytrace as well before getting the detector data.

Take care,

 

David

Hello David - thank you for your speedy reply.

 

The macro works very well! Thank you so much for your help.

 

Warm regards, Klaus

Userlevel 7
Badge +2

@klaus 

 

No worries, please consider accepting my answer if it has solved your problem. Take care,

 

David

Reply