Solved

How to use Matlab or Python to use ZTD tolerance analysis data?

  • 11 November 2021
  • 6 replies
  • 550 views

I know I can manually load the ZTD file using Tolerancing data viewer and copy the data to excel.  I would like to automate the procedure using Matlab or Python since I have more than 50 ZTD files. Thank you very much.

icon

Best answer by David.Nguyen 12 November 2021, 11:14

View original

6 replies

Userlevel 7
Badge +2

Hi Yao,

 

It is tricky cause I don’t think the Tolerance Data Viewer is implemented in the ZOS-API. However, the *.ZTD file can be opened with a text editor like Notepad++.

Although there are some encoding issues, and perhaps binary content, most of the file seems fine. You could try to directly read the *.ZTD file with MATLAB/Python, and see what it gives you.

Let me know if that works for you.

Take care,

 

David

Hi David,

Thanks for the suggestion. I  checked the Monte Carlo section of the ZTD file, unfortunately, this section is encrypted.:joy:

 

Userlevel 5
Badge +1

Hi Yao and David,

I just wanted to step in here and make a quick comment that the Tolerancing Data Viewer is implemented in the ZOS-API :slight_smile: You’ll need to use the IToleranceDataViewer interface:


Properties of ToleranceDataViewer include Monte Carlo data, Sensitivity data, etc.:


So, I ran a tolerance on one of our sample files to get the following Monte Carlo data:

 

With the following code in MATLAB:
TheSystem = TheApplication.PrimarySystem;

tolDataView = TheSystem.Tools.OpenToleranceDataViewer();

tolDataView.FileName = "C:\ … \Yao_CookeTripletTest.ZTD";

tolDataView.RunAndWaitForCompletion();

MCData = tolDataView.MonteCarloData;

MCDataValues = MCData.Values.Data.double;


We can get the values for each column in the Monte Carlo data:

 

The column headers are stored as the Monte Carlo metadata, which you can pull per-column with GetMetadata():

 

Let us know if we can be of any more help -- thanks!

Userlevel 7
Badge +2

Thank you for correcting me @Angel Morales!

Hi all 

 

Does this situation still work? I am tying to do the same thing using C# ZOS-API, but in my case, when I try to do 

 var tolDataView = TheSystem.Tools.OpenToleranceDataViewer();
I get a system null reference exception which means I can't access my MC data. 

Userlevel 7
Badge +2

Hi Alexander,

 

This piece of code works for me in Python:

TolDataViewer = TheSystem.Tools.OpenToleranceDataViewer()
TolDataViewer.RunAndWaitForCompletion()
print(TolDataViewer.SensitivityData.NumberOfResultOperands)
TolDataViewer.Close()

And it returns the correct number of operands. Therefore, I have no reason to suspect this shouldn’t work in C#. Are you able to share more of your code with us?

Take care,

 

David

Reply