Tolerance Analysis and Matlab

  • 25 January 2021
  • 2 replies
  • 432 views

Badge

I'm running tolerance analysis using ZOS-API-Matlab. How do I pull the tolerance data such as histogram, yield, etc? And how can I run my own tolerance script using Matlab?


2 replies

Userlevel 5
Badge +2

Hi Michael,


Thanks for your post here!


First, let me suggest to take a look at the Tolerancing example in the ZOS-API Syntax Help. It will show you the code for setting up the tolerancing and running it:



Regarding how to pull the tolerance histogram and yield data, before pulling these data, you need to use the Tolerance Wizard to set tolerances, then run Tolerancing, and save the results as a ZTD file. Once, the ZTD files are ready you can retrieve the data with the yield and histogram analyses. I have written some python code for these operations, please allow me to refer to these code snippets. Please find below the corresponding lines and find my .py files for python standalone applications attached. The files will also show you how to change the settings for the Yield and Histogram analyses:



#Get Tolerance Histogram
newTolHistogram = TheSystem.Analyses.New_TolerancingHistogram()
newTolHistogramSettings = newTolHistogram.GetSettings()
newTolHistogramSettings.UseSystemTolerances()
#change settings here if needed
#run Tolerance Histogram
newTolHistogram.ApplyAndWaitForCompletion()
# get Tolerance Histogram results
TolHistogramResults = newTolHistogram.GetResults()
numDS = TolHistogramResults.NumberOfDataSeries
for i in range(numDS):
series = TolHistogramResults.DataSeries[i]
numCurves = series.NumSeries
xData = series.XData.Data
yData = series.YData.Data
numPoints = xData.Length
for j in range(numPoints):
print(f'{xData[j]}: {[yData[j, k] for k in range(numCurves)]}')

For the Tolerance Yield, it works very similarly, but you will see it from the attached file.


Finally, to run your own tolerance script, you need to select it as the criterion for tolerancing (in the UI shown below):



I hope this helps, but if you have any further questions, please let us know and we will be happy to help!


Best,


Csilla

Hi all

I am trying to do very much the same thing as Michael did. I downloaded your code Csilla and changed the file to the zmx I was considering (I also tried to do this in C# and that failed as well). However, there seems to have been a change to the back-end code that makes it that this code no longer works with Zemax 2022 (or I am using it incorrectly), I  get the following error:

error

Even though I have done nothing to the code except for changing the filepath of the considered zmx file. Do you have any advice for this error?

 

Alex

Reply