I need to exchange the Data File Name of a Source File Object:
I tried to do that by python code:
1 import zospy
2
3 zos = zospy.ZOS()
4
5 oss = zos.connect()
6
7 oss.load(‘zmx_file.zmx’)
8
9 led = oss.NCE.GetObjectAt(1 )
10
11 TypeSet_LED = led.GetObjectTypeSettings(zp.constants.Editors.NCE.ObjectType.SourceFile)
12 TypeSet_LED.FileName1 = 'filename.dat'
I wrote that code according to section #! [e21s03_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
Best answer by chaasjes
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:
1 import zospy as zp
2
3 zos = zp.ZOS()
4 oss = zos.connect("extension" )
5
6 oss.new()
7 oss.make_nonsequential()
8
9
10 oss.SystemData.MaterialCatalogs.AddCatalog('MISC' )
11
12 oss.SystemData.Wavelengths.GetWavelength(1 ).Wavelength = 0.47
13
14 oss.SystemData.Units.SourceUnits = zp.constants.SystemData.ZemaxSourceUnits.Lumens
15
16
17
18
19 oss.NCE.AddObject()
20 oss.NCE.AddObject()
21 oss.NCE.AddObject()
22 oss.NCE.AddObject()
23
24
25
26
27 Object_1 = oss.NCE.GetObjectAt(1 )
28 Typeset_SourceFile = Object_1.GetObjectTypeSettings(zp.constants.Editors.NCE.ObjectType.SourceFile)
29 Typeset_SourceFile.FileName1 = 'RAYFILE_LB_T67C_100K_190608_ZEMAX.DAT'
30 Object_1.ChangeType(Typeset_SourceFile)
31 Object_1.GetObjectCell(zp.constants.Editors.NCE.ObjectColumn.Par1).IntegerValue = 5
32 Object_1.GetObjectCell(zp.constants.Editors.NCE.ObjectColumn.Par2).IntegerValue = 1000
33 Object_1.GetObjectCell(zp.constants.Editors.NCE.ObjectColumn.Par3).DoubleValue = 2.485572
34 Object_1.GetObjectCell(zp.constants.Editors.NCE.ObjectColumn.Par8).DoubleValue = 0.47
35 Object_1.GetObjectCell(zp.constants.Editors.NCE.ObjectColumn.Par9).DoubleValue = 0.47
36
Your code seems to be missing this line:
1 led.ChangeType(Typeset_LED)
And the specified source file must be located in Zemax/Objects/Sources/Source Files.
Does that help?
View original