Find and share your best practices for using the ZOS-API here!
- 153 Topics
- 442 Replies
Hello. I am trying to get the vertex position of each optical element in terms of global coordinates. I have found I need this as I am trying to find the full X, Y, Z location for each ray when running a “CreateNormUnpol” raytrace. When I am reading the ray information, I only get values for the X & Y locations and a 0.0 value for the Z location of the ray. Is there a way to enable global position for all axes? In a similar analysis, I want to know if there is a way to run a single ray trace and get all the location and angle information at each surface as is done in the Single Ray Trace window under the Analysis tab?
Dear all, in Wolfram Matheamtica how can one set Nd for material. LoadNETType["ZOSAPI.Editors.SolveType"] layer = theNCE@GetObjectAtsolver = layer@MaterialCell@CreateSolveType[SolveType`MaterialModel]solver@USUMaterialModel@IndexNd = 1.6layer@MaterialCell@SetSolveData[solver] USUMaterialModel derived from "ZOSAPI.Editors.ISolveMaterialModel" _S _MaterialModel seems to be a problem? Thanx for support and BR,Jozef
The results of a Geometric Image Analysis may be accessed using: gia = TheSystem.Analyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.GeometricImageAnalysis) gia_setting = gia.GetSettings() gia.ApplyAndWaitForCompletion() gia_results = gia.GetResults() gia.ApplyAndWaitForCompletion() gia_data = zos.DoubleToNumpy(gia_results.GetDataGrid(0).Values).reshape(-1, gia_setting.NumberOfPixels) where zos.DoubleToNumpy is tucked into the boilerplate PythonStandaloneApplication class. def DoubleToNumpy(self, data): '''Provided by Sandrine Auriol, Zemax''' if 'numpy' not in sys.modules: print('You have not imported numpy into this file') return False else: src_hndl = GCHandle.Alloc(data, GCHandleType.Pinned) try: src_ptr = src_hndl.AddrOfPinnedObject().ToInt64() cbuf = (ctypes.c_double * len(data)).from_address(src_ptr) npData = np.frombuffer(cbuf, dtype=np.float64) finally: if s
Hey,i want to retrieve data from POP with the API (in python). As far as i got i understand that the pop_analysis.GetResult() is delivering a matrix, like the one you get from the text tab in POP. So far so good. But I don’t know how to get the index for peak irradiance or any other certain value. So, can anybody help me to retrieve the peak irradiance value from that matrix? I’d really appreciate any help that would lead me to a solution. There seem to be some options like “IndexOf”, “FindIndex”, but I don’t know how to use them. My code for that section so far:pop_analysis = TheSystem.Analyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.PhysicalOpticsPropagation)pop_analysis.ApplyAndWaitForCompletion()pop_results = pop_analysis.GetResults()matrixData = pop_results.GetDataGrid(0).ValuesThanks,Mo
Dear comunity. What is the syntax to open a shaded model from Wolfram Mathematica? analysis = TheSystem@Analyses@NewUAnalysis["ZOSAPI.Analysis.AnalysisIDM.NSCShadedModel"] returns NET::methodargs: Improper arguments supplied for method named NewUAnalysis. Thanx and BR,Jozef
Hi,I’m trying to extract data of Huygens PSF in Matlab through the API.I want to get the center coordinates and I thought the HeaderData will include it. But looks like the HeaderData is empty. PSF_Results = PSF_Win.GetResults();string(PSF_Results.HeaderData.Lines) ans = 1×0 empty string array The MetaData and the DataGrids seems to work fine and contains the data.Am I missing something? Is there other place that I can pull the coordinates from there? Thanks!
Hello, I saw a coupling topics on this but don’t see a real solution.Using the MATLAB API I can load a file and create a universal 1 D plot and change config settings. When I open the zmx file after I can see that the settings were applied correctly and the plot looks good. But, I cannot figure out how the access the plot data from the MATLAB API. I’m using: UnivPlot = TheSystem.Analyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.UniversalPlot1D);UnivPlot_Settings = UnivPlot.GetSettings();fprintf('Universal Plot has analysis specific settings? %i\n', UnivPlot.HasAnalysisSpecificSettings)% Above is False; Universal Plot Settings must be changed via ModifySettings (changing a config (.cfg) file)cfg = System.String.Concat(TheApplication.ZemaxDataDir, '\Configs\UNI.CFG');UnivPlot_Settings.Save(); % Create new .cfg file, named "UNI.CFG" in \Configs\ folder% Change universal plot settingsUnivPlot_Settings.ModifySettings(cfg, 'UN1_CATEGORY', num2str(0));UnivPlot_Settings.ModifySettings(cfg, 'U
HiI am learning how to build the MFE with ZOS-API and for that I am creating a simple MFE. I know that Target and Weight are accessible through Operand.WeightOperand.Target But calling the Value column using Operand.Value returns 0. Any idea what I am doing wrong? Thanks
Hi,I’ve been building over the years a series of python based-tools that use ZOSAPI framework in order to automatize repetitive jobs. However, the reccurent changes in the API causes regular failures in these scripts. Lately I’ve been trying to use a simple piece of code that gets the sag from the surfaces and find the following failure (where ZemaxLDE is an instance of the TheSystem.LDE, and xi, yj are points where I want my sag to be returned): tmp = ZemaxLDE.GetSag(index, xi, yj) File "C:\Python27\lib\site-packages\win32com\gen_py\EA433010-2BAC-43C4-857C-7AEAC4A8CCE0x0x1x0\ILensDataEditor.py", line 103, in GetSag , X, Y, sag, alternateSag) File "C:\Python27\lib\site-packages\win32com\client\__init__.py", line 467, in _ApplyTypes_ self._oleobj_.InvokeTypes(dispid, 0, wFlags, retType, argTypes, *args),pywintypes.com_error: (-2147352562, 'Nombre de param\xe8tres non valide.', None, None) Could you please tell me what could have changed (I’m still working with Zemax 21.x beca
Hi!I am experiencing a bug when running local optimisations via the ZOS-API in python. I am using interactive extension. Example of the code is:LocalOpt = TheSystem.Tools.OpenLocalOptimization()LocalOpt.Algorithm = ZOSAPI.Tools.Optimization.OptimizationAlgorithm.DampedLeastSquaresLocalOpt.Cycles = ZOSAPI.Tools.Optimization.OptimizationCycles.Fixed_50_CyclesLocalOpt.NumberOfCores = 8LocalOpt.RunAndWaitForCompletion()LocalOpt.Close()Upon running this, it sometimes completes correctly, but sometimes the optics studio window crashes and closes. Then when i open it back up, it asks if i want to restore the file. I have also tried this on multiple machines with different installations of ZEMAX, and the same thing occurs: sometimes it completes the optimisation and sometimes it crashes. Has anyone else experienced this issue, or know a fix? Thanks very much in advance!!
I am trying to view/export the zernike data of my system using Matlab and the API. Currently my code reads: And I don't know what to do from here. The data comes to Matlab in an IAR file type, and I don't know how to extract it. Thanks, Stephen Chapman
I’m using ZOS-API by matlab.I’ve tried to run Geometric Bitmap Image Analysis and succeed Running Analysis by using Interactive Extension.GeoBitIA = TheSystem.Analyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.GeometricBitmapImageAnalysis);I want to control some setting by using matlab. However I do not find right method to modify Settings.Do me a favor to do that things.Thank you.
Hi Zemax community,I am a student who is learning to use the ZOS API in Matlab and I’m having issues with getting results from New_WavefrontMap. How do I correctly pull data from a wavefront map? As the results I plot are always zero.I am running a wavefront analysis and POP analysis in the same program, which uses the ‘Double Gauss 5 degree field.zmx’ file from samples. I apply the analysis then pull the results using the following code to get the data:WF_Map_Data = New_WF_map_results.DataGrids(1).Values.double;matrixData = POP_Results.DataGrids(1).Values.double;and try to plot it in Matlab the matrix will be populated by zeros.Wavefront map populated by 0’sBoth wavefront map and POP are set up in a similar fashion, but when plotting the results of the POP it will not be populated by zeros.POP resultThanks for readingNick
I am running tolerancing analysis (TA) using Matlab. I noticed that one tolerance data viewer window will show up after the TA is finished. I would like to close the viewer window using Matlab script however I was not able to find the right way to do it in ZOS-API manual. Do you know how to close the viewer window using Matlab script? Thank you very much.
Hi. I am using the ZOS-API for Python and try to switch to the new recommended method of using PythonNET instead of the COM interface. To do so, I created a new Python template using 'Programming>Python>Interactive Extension' (same problem occurs with 'Standalone Application'). Running this template fails when trying to add the NetHelper DLL: import clr, os, winreg from itertools import islice # determine the Zemax working directory aKey = winreg.OpenKey(winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER), r'Software\Zemax', 0, winreg.KEY_READ) zemaxData = winreg.QueryValueEx(aKey, 'ZemaxRoot') NetHelper = os.path.join(os.sep, zemaxData, r'ZOS-API\Libraries\ZOSAPI_NetHelper.dll') winreg.CloseKey(aKey) # add the NetHelper DLL for locating the OpticStudio install folder clr.AddReference(NetHelper) import ZOSAPI_NetHelper --------------------------------------------------------------------------- FileNotFoundException Traceback (most recent call
Could anyone help troubleshoot an error when running the NSC RayTrace in Interactive Extension mode from Matlab - ‘Unrecognized field name "ClearDetectors".’?The code always runs the first time through, and then the second time through the below routine, either in the same program execution or after stopping and starting again, it hangs up on NSCRayTrace.ClearDetectors(0); % Ray Trace % Create ray trace NSCRayTrace = TheSystem.Tools.OpenNSCRayTrace(); NSCRayTrace.SplitNSCRays = false; NSCRayTrace.ScatterNSCRays = false; NSCRayTrace.UsePolarization = true; NSCRayTrace.IgnoreErrors = true; NSCRayTrace.SaveRays = false; NSCRayTrace.SavePaths = true; NSCRayTrace.SavePathsFile = 'Simulation_temp.PAF'; NSCRayTrace.ClearDetectors(
In OpticStudio, We can load any BSDF file from our \Zemax\ScatterData Folder .Here is the available code for Matlab and Python. You can use this code in Standalone or Interactive Extension.-Copy the code in your file .-Change the path of testfileMatlab Code: TheNCE = TheSystem.NCE; Object_2 = TheNCE.GetObjectAt(2); % changes scatter profile on face Scatter_Data=Object_2.CoatScatterData.GetFaceData(0);o3_Scatter = Scatter_Data.CreateScatterModelSettings(ZOSAPI.Editors.NCE.ObjectScatteringTypes.BSDF); o3_Scatter.S_BSDF_.ReflectFile = 'BrownVinyl.bsdf'; o3_Scatter.S_BSDF_.TransmitFile = 'BrownVinyl_HighRes.bsdf'; o3_Scatter.S_BSDF_.ScatterFraction = 0.775; o3_Scatter.S_BSDF_.Angle = 30; Object_2.CoatScatterData.GetFaceData(0).ChangeScatterModelSettings(o3_Scatter); Object_2.CoatScatterData.GetFaceData(0).NumberOfRays = 2; Python code :testFile = r"C:\test\Digital_projector_flys_eye_homogenizer.zos"TheSystem.LoadFile(testFile, False)print(TheSystem.SystemFile)TheNCE = TheSystem.
In OpticStudio, We can load any spectrum file from our \Objects\Sources\Spectrum Files Folder .Here is the available code for Matlab and Python. You can use this code in Standalone or Interactive Extension.-Copy the code in your file .-Change the path of testfileMatlab Code: import ZOSAPI.*;TheSystem = TheApplication.PrimarySystem;sampleDir = TheApplication.SamplesDir;testFile = System.String.Concat("C:\test\ZPO\Diode sample.ZMX"); NSCE = TheSystem.NCE;Obj1 = NSCE.GetObjectAt(1); Source_Color=Obj1.SourcesData.SourceColor;Source_Color=ZOSAPI.Editors.NCE.SourceColorMode.SpectrumFile;filesAvailable = Obj1.SourcesData.SourceColorSettings.GetAvailableSpectrumFiles();FileToSelect=filesAvailable(6);Obj1.SourcesData.SourceColorSettings.SpectrumFile=FileToSelect; Matlab Interactive Extension Python Code:testFile = r"C:\test\ZPO\Diode sample.ZMX"TheSystem.LoadFile(testFile, False)print(TheSystem.SystemFile)NSCE = TheSystem.NCEObj1 = NSCE.GetObjectAt(1) Source_Color=Obj1.SourcesData.Sourc
Hello, I am trying to use the ZOS-API through Python. I have found the knowledgebase articles to be very scattered and confusing. I would like to access the dictionary of enumeration constants referenced multiple times in the linked article. However, the article does not show how to find the constants dict within ZOS-API. And, the source script for the code snippets is not linked in the article attachments! Does anyone know how I can access the constants dict through python? Thanks in advance.https://support.zemax.com/hc/en-us/articles/1500005576662-ZOS-API-using-Python
In opticStudio ,we can set User defined surface through Python and Matlab program using standalone and Interactive Extension.-Set the user defined surface -Select the User defined surface from directory-Get the User defined surfaceMatlab Code:You can directly copy the code in Standalone or Interactive Extension: import ZOSAPI.*; % Set up primary optical system TheSystem = TheApplication.PrimarySystem; sampleDir = TheApplication.SamplesDir; testFile = System.String.Concat('C:\test\ABCD\ABCD Simple_lens.zmx'); TheSystem.LoadFile(testFile, false); TheLDE = TheSystem.LDE; surf2 = TheLDE.GetSurfaceAt(2); typeSettings = surf2.GetSurfaceTypeSettings(ZOSAPI.Editors.LDE.SurfaceType.UserDefined); filesAvailable = typeSettings.GetFileNames(); typeSettings.Filename = filesAvailable(5); surf2.ChangeType(typeSettings); d=typeSettings.Filename; disp(d) Interactive Extension Matlab Python Code:You can directly copy the code in Standalone or Interactive Extensi
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.