Skip to main content

How to load Spectrum File in Color/Spectrum of object properties in ZOS API Matlab and Python

  • February 23, 2022
  • 1 reply
  • 332 views

Sahil
Forum|alt.badge.img+1

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 testfile

Matlab 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.NCE

Obj1 = NSCE.GetObjectAt(1) 

Source_Color=Obj1.SourcesData.SourceColor

Source_Color=ZOSAPI.Editors.NCE.SourceColorMode.SpectrumFile

filesAvailable = Obj1.SourcesData.SourceColorSettings.GetAvailableSpectrumFiles()

Obj1.SourcesData.SourceColorSettings.SpectrumFile=filesAvailable[1]

print(Obj1.SourcesData.SourceColorSettings.SpectrumFile)

Python Interactive Extension

 

Did this topic help you find an answer to your question?

1 reply

  • Infrared
  • 7 replies
  • February 26, 2024

This method appears to be deprecated. I could only do it by accessing private variables.

NSE = TheSystem.NCE

obj_1 = NSE.GetObjectAt(1)
available_source_files = obj_1.SourcesData.SourceColorSettings._S_SpectrumFile.GetAvailableSpectrumFiles()

obj_1.SourcesData.SourceColorSettings._S_SpectrumFile.set_SpectrumFile(available_source_files)
print(f"Spectrum set: {obj_1.SourcesData.SourceColorSettings._S_SpectrumFile.get_SpectrumFile()}")

Is there a cleaner way?

 

Thanks,

Thomas


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings