Skip to main content

Hi all,

I want to save data and images of detectors automatically with ZPL.

 

 

So I made the ZPL code as below. 

For n = 2, 6, 1

    ####### get Detector viewer in img.

    winnum = n+1

    OpenAnalysisWindow "Dvr", cfgpath$

    ExportJPG winnum, imgfile$

    

    ####### get Detector viewer in dat.

    #ModifySettings cfgtxt$, DVW_SHOW, 1 # extraction middle row data from 2d data

    GetTextFile datfile$, "Dvr", cfgtxt$ , 1

    ConvertFileFormat datfile$, 1   #Unicode to ANSI

Next

 

Once I open all detector viewer windows, I tried to save images and data in detector number order. 

However, I couldn’t save each detector data/image because it cannot recognize the number of detector in this code.

 

What should I do? 

Or, are there better method to do it? 

Please help me. 

Thanks in advance.

 

Hello,
I have the same question. I want to use a macro to save the numerical detector values as a text file and would be glad to get support.

Thanks a lot and best regards
Dirk


Hi all,

The general set of steps for something like this should be the following:

  1. If you haven’t already, save the detector settings. This will create a CFG file for use in the code
  2. In the ZPL, write a loop to cycle through all of the detectors
  3. Use MODIFYSETTINGS to change the detector of interest. This is done with DVW_DETECTOR. The number must match the number of the detector in the Non-Sequential Component Editor
  4. Use OPENANALYSISWINDOW to open a Detector Viewer window with the new settings
  5. Save the image of the window with EXPORTJPG. Note: This is equivalent to taking a screenshot of the analysis window, so it will probably be best to ensure the window opens without docking. 
  6. If you want, save the text output as well with GETTEXTFILE
  7. Close the analysis window. This ensures your workspace does not get too crowded. 

I am attaching a ZPL macro which walks through these steps. The macro will save the detector image and text information to the working directory. The filenames are updated with the detector number. 

 

 

Hope this helps!​​​


Hello Allie,

thanks a lot for your answer.

I tested your macro. I wanted to save the image of the detector viewer (incoherent irradiance, cross section row)
and the values. The saving of the cross section values worked. But the saved image does not show the cross section. It shows the inverse grey scale data. Can you tell me what’s wrong here.

What exactly means “saving the detector settings”? What I did before executing the macro was opening the detector viewer, setting the parameters like “Show as:” and “Show Data:” and then clicking “Save”.

Thanks a lot and best regards

Dirk

 


Hi Dirk,

The reason for the discrepancy is discussed in this forum post:

Because of the difference in integer values between the Graph and Text tabs, you will need to use MODIFYSETTINGS twice in one iteration: once before saving the text file, and once before saving the graph file.

 

 

As for saving the detector settings - you did it right. When I say to save, I mean this: open the Detector Viewer settings dialog and click Save. That way, a CFG file is created for you to modify with the code I provided. 


Hi Allie,

Thanks a lot for your answer.

It was really helpful.

In addition, I want to ask something in your code.

 

In your code, I can’t understand these.

1.    type = NPRO(1, obj, 0, 0)     # obj : detector number

2.   type$ = $BUFFER()

 

Even if the the line 1 is annotated, the code is well worked, in my opinion. 

What is the function of the first line?

In the line 2, $BUFFER() is mysterious. 

In the buffer, “NSC_DETE” is contained after execution of the code.

I didn’t do something, but how can I know what string is in it?

 

Thanks. 

Regards.


Hi @Jeeyoung.Lee,

I’m happy to hear the code is working for you!

In my code, those two lines are used to find Detector objects. This allows me to run the code without first storing the object numbers of each of the detectors.

In your message, line #1 reports a property of a Non-Sequential object. With Code = 0, the property I’m reporting is the name of the object (aka the type). For Detector Rectangles, that will return “NSC_DETE.” In this case, we are using a Numeric Function to report the type. The output of a Numeric Function is a number (integer or double). When NPRO returns a string, that string is sent to the buffer. Then, the value may be extracted by line #2 in your post. 

This is discussed a bit in the Help System file “The Programming Tab > About the ZPL > Numeric Functions

 

 

I also talked about this in my ENVISION presentation last year. You can see my slides here: 

 

 


Hello Allie, thanks for your support. Everything works well:-)

Best wishes

Dirk


Is there a way to save the detector file name as the detector comment column?


Is there a way to save the detector file name as the detector comment column?

Hi Michael,

In that case you may modify Allie’s code “type=NPRO(1,obj,0,0)” to “comment=NPRO(1,obj,1,0)”. The third argument “code” is described in the help file of “SETNSCPROPERTY(keywords)”: 0 for object type and 1 for object comment.

 

Regards,

Jiang


Dear all,

When I was running the sample code Zemax returns error message “Unable to capture analysis window – timeout occurred waiting for rendering to complete.” What should I do in this case? @Allie  @David Nguyen 

Regards,

Jiang

 


Dear all,

When I was running the sample code Zemax returns error message “Unable to capture analysis window – timeout occurred waiting for rendering to complete.” What should I do in this case? @Allie  @David Nguyen 

Regards,

Jiang

 

Dear all,

 

I would like to share that I fixed the issue mentioned above. The issue was caused, I think, by not clicking the OK button to close the new analysis window. Thus, I used “UPDATE ALL” the my code shown below. Moreover, when using the “MODIFYSETTINGS” command, I pointed to the “DVR.CFG” configuration file in the default Zemax config folder (where your configuration file is saved after clicking the “Save” button of Detector Viewer window), instead of the configuration file with the same ZMX file name (“cfgFilename$” below). In my code below, “6” was used because I have only one detector (object 6) in my lens editor. Also, when you use “DVW_SHOW” the dropdown menu entries begin with 0.

path$ = $PATHNAME() + "\"
lensFilename$ = $FILENAME()   
lengthFilename = SLEN(lensFilename$)   
shortenFilename$ = $LEFTSTRING(lensFilename$, lengthFilename-3)  
cfgFilename$ = path$ + shortenFilename$ + "CFG"

data$ = $DATAPATH()
cfgfile$ = data$ + "\Configs\DVR.CFG"

FORMAT 1 INT
A$ = path$ + "DetImage_" + $STR(6) + ".JPG"
B$ = path$ + "DetData_" + $STR(6) + ".TXT"
type = NPRO(1, 6, 0, 0)
type$ = $BUFFER()
! Check if the object type is a detector. If yes, continue
IF (type$ $== "NSC_DETE")
    ! Update the settings with the detector number
    MODIFYSETTINGS cfgfile$, DVW_DETECTOR, 6
    MODIFYSETTINGS cfgfile$, DVW_SHOW, 5
    ! With the new settings, open a window and take an image of what is there
    OPENANALYSISWINDOW DVR, cfgfile$
    UPDATE ALL
    winVal = WINN()
    EXPORTJPG winVal, A$
    CLOSEWINDOW winVal
    ! Additionally, save the detector data as a text file
    MODIFYSETTINGS cfgfile$, DVW_SHOW, 2
    MODIFYSETTINGS cfgfile$, DVW_DATA, 4
    !UPDATE ALL
    GETTEXTFILE B$, DVR, cfgfile$
ENDIF

 

Regards,

Jiang


Reply