Skip to main content

I need to exchange the Data File Name of a Source File Object:

 

 

 

I tried to do that by python code:

import zospy

zos = zospy.ZOS()

oss = zos.connect()

oss.load(‘zmx_file.zmx’)

led = oss.NCE.GetObjectAt(1)

TypeSet_LED = led.GetObjectTypeSettings(zp.constants.Editors.NCE.ObjectType.SourceFile)
TypeSet_LED.FileName1 = 'filename.dat'

I wrote that code according to section #! ie21s03_py] in example 21 of the ZOS-API Python examples

Apparently, the code does not work.

Did anyone ever manage to exchange source files via python?

Can you provide a code snippet that works?

 

Thanks in advance

Hi ​@dsotm,

Thank you for asking this question and nice to see you’re using ZOSPy!
I checked the example code and this works for me:

import zospy as zp

zos = zp.ZOS()
oss = zos.connect("extension")

oss.new()
oss.make_nonsequential()

# Add new catalog MISC
oss.SystemData.MaterialCatalogs.AddCatalog('MISC')
# Set Wave #1 to 0.47 micron
oss.SystemData.Wavelengths.GetWavelength(1).Wavelength = 0.47
# Use lumens as the source unit
oss.SystemData.Units.SourceUnits = zp.constants.SystemData.ZemaxSourceUnits.Lumens # ZOSAPI.SystemData.ZemaxSourceUnits.Lumens
#! >e21s01_py]

#! >e21s02_py]
# Add 4 more objects
oss.NCE.AddObject()
oss.NCE.AddObject()
oss.NCE.AddObject()
oss.NCE.AddObject()
#! >e21s02_py]

#! >e21s03_py]
# Set 1st object as a Source File
Object_1 = oss.NCE.GetObjectAt(1)
Typeset_SourceFile = Object_1.GetObjectTypeSettings(zp.constants.Editors.NCE.ObjectType.SourceFile)
Typeset_SourceFile.FileName1 = 'RAYFILE_LB_T67C_100K_190608_ZEMAX.DAT'
Object_1.ChangeType(Typeset_SourceFile)
Object_1.GetObjectCell(zp.constants.Editors.NCE.ObjectColumn.Par1).IntegerValue = 5
Object_1.GetObjectCell(zp.constants.Editors.NCE.ObjectColumn.Par2).IntegerValue = 1000
Object_1.GetObjectCell(zp.constants.Editors.NCE.ObjectColumn.Par3).DoubleValue = 2.485572
Object_1.GetObjectCell(zp.constants.Editors.NCE.ObjectColumn.Par8).DoubleValue = 0.47
Object_1.GetObjectCell(zp.constants.Editors.NCE.ObjectColumn.Par9).DoubleValue = 0.47
#! >e21s03_py]

Your code seems to be missing this line:

led.ChangeType(Typeset_LED)

And the specified source file must be located in Zemax/Objects/Sources/Source Files.

Does that help?


Reply