MATLABZOSConnection failed

  • 23 October 2020
  • 9 replies
  • 169 views

Hi,


i am new to Zemax and i tried to connect my lense system with Matlab through the ZOS-API interactive extension. As i run the template script the 'TheApplication' Object with all its properties should appear, but thats not the case. It is just showing in which folder it is found and nothing else.

Furthermore i do not know how to load the lense system into this matlab file. Is there anything i missed out?


If somebody could help a beginner that would be really nice.


Best wishes,


Julia.


9 replies

Userlevel 5
Badge +2

Hi Julia,


Thanks for your post here!


You are right, after running the template script TheApplication variable, i.e the output of the function should appear.

There might be different reasons why you did not see it.


Did you get an error message instead, similar to the one below?

 


You usually get this message if you haven’t enabled the Interactive Extension in the OpticStudio GUI:



Another possibility, did you run the the Matlab code from the Command line with an extra ; at the end of the line? If so, in this case Matlab will not list the output of the function in the Command Window, however you still should be able to see it in the Workspace. Probably it is called ans if you have not defined any name for the output.


Regarding your other question about how to load a lens file, for this purpose, you will need to use the LoadLens member function of the ZOSAPI.Tools.General.ILensCatalogLens Interface Reference. You may find further info about how to use it, and also you can check the correct syntax in the sample code called Open File and Optimize #3:



For further references, these articles are on the Interactive Extension with Python and Matlab:


https://my.zemax.com/en-US/Knowledge-Base/kb-article/?ka=KA-01774


https://my.zemax.com/en-US/Knowledge-Base/kb-article/?ka=KA-01606


https://my.zemax.com/en-US/Knowledge-Base/kb-article/?ka=KA-01828


Also, we have an API Learning Path that I would recommend checking out:


https://my.zemax.com/en-US/learning-paths/getting-started-with-zos-api/


 


If you have further questions, please let us know and we will be happy to help!


Best,


Csilla

Hello Csilla,


thank you for your response. I already changed my project from the interactive extension to the standalone application and i have a farther questions here. In my project there are many surfaces ( coordinate breaks, lenses, mirrors,etc.) and two beams. These beams are having the same path (after a certian point). The only difference between these beams is the wavelength. How can i access the coordinates from the beams on the image surface depending on the wavelength/the beam (ideally also depending on the tilting of a certian earlier surface).  


Thank you in advance!


Best,


Julia.

Badge +1

Hi Julia,


You could use the REAX/Y operands to report back the x- and y-coordinates at any surface:



For example:


TheSystem = TheApplication.PrimarySystem;

TheLDE = TheSystem.LDE;


surf = TheLDE.NumberOfSurfaces-1; Hx = 0; Hy = 1; Px = 0; Py = 0;


for wave=1:TheSystem.SystemData.Wavelengths.NumberOfWavelengths

x(wave) = TheSystem.MFE.GetOperandValue(ZOSAPI.Editors.MFE.MeritOperandType.REAX,surf,wave,Hx,Hy,Px,Py,0,0);

y(wave) = TheSystem.MFE.GetOperandValue(ZOSAPI.Editors.MFE.MeritOperandType.REAY,surf,wave,Hx,Hy,Px,Py,0,0);

end


Best,


Ali

Userlevel 5
Badge +1

Hi Julia!


I think obtaining the 'beam coordinates' will depend on what specifically you are after. Is it the chief ray position on the image plane? Some other arbitrary ray? The centroid of the beam?


For a specific ray, you could use one of our REAX/Y/Z Merit Function operands (the following is from our Help File page at 'The Optimize Tab (sequential ui mode) > Automatic Optimization Group > Merit Function Editor (automatic optimization group) > Optimization Operands (Alphabetically)'):






 


The reason I bring up these operands is because you can call them from within the ZOS-API using the GetOperandValue() function. This can call the value from any operand, and it does not need to be defined in your merit function to be utilized. The REAX/Y/Z operands take in the normalized field and pupil coordinates to define which ray you want to evaluate, and it also require you to specify a wavelength, meaning you can get the different landing coordinate data values for each wavelength. The operands are effectively just tracing a single ray through your system, so it will take into account and tilting/decentering you apply to the optical system.


For an example of the usage for GetOperandValue(), you can take a look at Examples 7 and 23 in our sample code directory:

 




 


If you had another idea in mind for the data you'd like to pull, please let us know, and we can continue the discussion further!


~ Angel

Userlevel 5
Badge +1

Oops, looks like Ali got an answer in just before me! At least we're being consistent :)


~ Angel

Hello again,


thank you all very much! I can access now the coordninates. I am still confused thought by the tilting. I want to change the tilting of the coordinate break before the lense but i don't want to use the property BeforeSurfaceTiltX/Y. I would rather use the property TiltAbout_X. But when i try 'tiltx_main = TheSystem.LDE.GetSurfaceAt(14).TiltAbout_X;'  i always get errors like 'No appropriate method, property, or field 'TiltAbout_X' for class

'ZemaxUI.ZOSAPI.Editors.ZOSAPI_LDERow'.' but i do not know which class i need to use instead.

 


I am confused by the amout of different tilting properties in general.


If you could explain what the differences are and help me out with my situation that would be great.


Thank you!


Best,


Julia.

tilting.png
Badge +1

Hi Julia,


You may use the GetSurfaceCell method of the ILDERow Interface:


 



An example piece of code is below:


surf1 = TheLDE.GetSurfaceAt(1);

surf1.GetSurfaceCell(ZOSAPI.Editors.LDE.SurfaceColumn.Par3).DoubleValue = 3


Note: Par3 will change the tilt in x and Par4 will change the tilt in y.


 


Regarding the tilting properties, the ones built into the surface properties are normally used if you don't want to optimize on any of the values of the CB, e.g. the tilt in x. They are much neater than using a lot of CBs. For example, you could use them to make a prism instead of using CBs. Also, if you wanted to tilt a complete element, you would need to use CBs. Use the Tilt/Decenter Elements tool and see what OS does:


T


One of my colleagues, Angel, did a presentation on CBs that you may find useful:


https://my.zemax.com/en-US/forum/threads/e229137e-e007-eb11-a813-000d3a329613


 


Best,


Ali

Hello Ali,


i tried to use the GetSurfaceCell() operation with the DoubleValue as in your example code but it shows the error that this line expects a double but got a string. I can't find any 'StringValue' property in this class therefore i can not look up what's on that column. But i don't understand why its a string the tilting musst be a double because it shows the degree or did i not understood it correctly?


Best,


Julia.

matlabfehler.jpg
Userlevel 6
Badge +2

Hello Julia,


I have checked and this actually works for me. If you want to use the property DoubleValue, I would recommend checking DataType before. Otherwise, I would tend to use the property Value as it is more general.


Here is my code:


>> TheApplication=ans;

>> TheSystem=TheApplication.PrimarySystem;

>> Surf3=TheSystem.LDE.GetSurfaceAt(3);

>> Surf3_Par4 = Surf3.GetSurfaceCell(ZOSAPI.Editors.LDE.SurfaceColumn.Par4);

>> Surf3_Par4.DataType

ans = 

Double

>> Surf3_Par4.DoubleValue

ans =

     0

>> 

Let me know if you have any questions.


Sandrine


 

Reply