Skip to main content

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=filesAvailablel1]

print(Obj1.SourcesData.SourceColorSettings.SpectrumFile)

Python Interactive Extension

 

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