Question

Filter String in Macro


  • Single Emitter
  • 0 replies

I am rather new in the field of creating Macro. 

I am trying in a Macro to introduce a Ray tracing. I need to select the ray that I want to display. This function is done with Filter String is the normal use of Zemax. I could i use a filter string in the macro. Is there something special to carry. 


2 replies

Userlevel 7
Badge +2

@Sami 

 

As far as I know, the Filter String isn’t a setting that you can modify in ZPL. Depending on what you want to achieve, you could create a Source Ray to mimic the ray you are interested in and display this source only. Alternatively, the ZOS-API should let you edit the Filter String. This feature is described in Example 10 in all four supported languages (C++, C#, MATLAB, and Python):

# Open Detector Viewer, view previously saved .zrd file
DetectorView = TheSystem.Analyses.New_DetectorViewer()
DetectorView_Settings = DetectorView.GetSettings()
DetectorView_Settings.RayDatabaseFilename = "e10_API_Raytrace.ZRD"
DetectorView_Settings.ShowAs = ZOSAPI.Analysis.DetectorViewerShowAsTypes.FalseColor
DetectorView_Settings.Filter = "X_HIT(2, 4)" # Detector will only display rays which hit object 2 exactly 4 times
DetectorView.ApplyAndWaitForCompletion() # Apply Settings to Detector Viewer

This is the Python version.

I hope this helps and take care,

 

David

@David.Nguyen 

Hallo David.

Referring the following section in User Manual, it should be possible to run a ray trace with a string filter option.

“ 10.2.14.95. NSTR
Initiates a Non-sequential trace with ability to save data to a ZRD file.
Syntax:
NSTR surf, source, split, scatter, usepolar, ignore_errors, random_seed, save,
savefilename, filter, zrd_format
Discussion:
Surf is an integer value that indicates the number of the Non-sequential surface. If the program mode is set to Non-Sequential, use 1. Source refers to the object number of the desired source. If source is zero, all sources will be traced. If Split is non-zero, then splitting is on, otherwise, ray splitting is off. If Scatter is non-zero, then scattering is on, otherwise scattering is off. If Usepolar is non-zero then polarization will be used, otherwise polarization is off. If splitting is on polarization is automatically selected. If ignore_errors is non-zero, then errors will be ignored, otherwise ray errors will terminate the non-sequential trace and macro execution and an error will be reported.
If random_seed is zero, then the random number generator will be seeded with a random value, and every call to NSTR will produce different random rays. If random_seed is any integer other than zero, then the random number generator will be seeded with the specified value, and every call to NSTR using the same seed will produce identical rays. When using NSTR for optimization, it is recommended that a non-zero value be used for random_seed.
If save is omitted or is zero, the arguments savefilename, filter, and zrd_format need not be supplied. If save is not zero, the rays will be saved to a file. The saved data file will have the name specified by the savefilename. The file naming convention and destination folder are the same as described in "Saving ray data to a file". The extension of savefilename should be provided, but no path should be specified. If save is not zero, then the optional filter name is either a string variable with the filter, or the literal filter in double quotes. If no filter is being used, enter an empty pair of double quotes like this: "". For information on filter strings see "The filter string". For ZRD files, the zrd_format can be 0, 1, or 2 for uncompressed full data, compressed basic data, or compressed full data, respectively. For more information on ZRD formats see " Ray database (ZRD) files ".
NSTR always calls UPDATE before tracing rays to make certain all objects are correctly loaded and updated.
Related Functions:
NSTR2
NSDD
Example:
NSTR 1, 0, 0, 0, 0, 1, 0, 1, "saverays.ZRD", "h2”


However, I couldn’t achieve to make it work. It somehow do the ray tracing without filtering. Are you aware of this info from user manual? If yes, do you have any idea why that shouldn’t work?

Thanks you

Reply