Skip to main content

Hi,



I'm running into a problem with the NSC detector viewer combined with the ZOSAPI and CAD-object as detector. I can succesfully built and trace my Zemax models using the ZOSAPI in non-sequential mode. However, I would like to have the output of the detector viewer text tab (Irradiance + x,y,z)



This is where my problem arises. I can open the Detector viewer through the API, but since I do not have a standard detector, I can only get output in the text-tab. When I call DetectorView.Results.GetTextFile() after running the DetectorViewer, the resulting text file shows 'incoherent data' (I assume since I call it while the viewer is on the graph tab).



Now when I connect as extension and click the `text` tab myself within OpticStudio, and then call DetectorView.Results.GetTextFile(), the file is correct. 



As I would like to run many of these analyses, I would like to automate obtaining the detector viewer results. Is there a way to change tabs through the ZOS-API? Or a workaround like making the Text tab the default tab? 



 



Thank you in advance!

Hi Luc,



This has been covered on the forum, and here is a link to that posting. 



https://my.zemax.com/en-US/forum/threads/034aafd1-3d96-ea11-a811-000d3a329613



I will keep an eye out for further information that may help, but this should give you the standard information you need.



Kevin


Hi Luc,



I found some additional information on extracting x,y,z positions from an object as detector that might be relevant for you. 



It can be pulled for Detector Objects under the FaceData interface:





You can use this interface to pull data on the vertices that make up the faces which will provide you with the intersection points for each pixel. Here’s an example of the code from that interface in use:



 



obj7 = TheNCE.GetObjectAt(7);



numFaces = obj7.GetFacetedObjectData().NumberOfFaces; % There are 12 faces



% Face 0 data



obj7.GetFacetedObjectData().CurrentFace = 0;



obj7_Face0 = obj7.GetFacetedObjectData();



% Number of vertices = 3



[x01, y01, z01] = obj7.GetFacetedObjectData().GetVertex(1);



[x02, y02, z02] = obj7.GetFacetedObjectData().GetVertex(2);



[x03, y03, z03] = obj7.GetFacetedObjectData().GetVertex(3);



 


Hi Kevin,



 



Thank you very much for all the replies, this provides exactly what I need! For the python users that find this post, the following should work (and can be extended for obtaining Flux):



fd = DetectorObject.GetFacetedObjectData()


centroids = []


irradiance = []


absorbed_irradiance = []


for facenum in range(fd.NumberOfFaces):


    fd.CurrentFace = facenum


    verts = np.array([list(fd.GetVertex(vertnum, 0,0,0)[1:]) for vertnum in range(fd.NumberOfVertices)])


    centroids.append(verts.mean(axis=0))


    irradiance.append(fd.Irradiance)


    absorbed_irradiance.append(fd.AbsorbedIrradiance)


                      


centroids = np.array(centroids)


irradiance = np.array(irradiance)


absorbed_irradiance = np.array(absorbed_irradiance)


 



With `DetectorObject` being a  NCE Detector Object and `np`  the common abbreviation for the imported numpy package (import numpy as np)



Best,



 



Luc



 


Reply