Hi Armand,
Can you check which version of PythonNET you are using? If you’re using a version greater than 3.0, then you need to explicitly cast the GetSettings() interface:
POP_set = POP.GetSettings().__implementation__
PythonNET 3.x is "Fixed" | Zemax Community
Hi Michael,
I am using version 3.0.1 for pythonnet. I have a try with adding the __implementation__ line you mentioned and it seemed like it was able to run (assuming that you meant to explicitly type that in vs something else, sorry I am not the greatest when it comes to programming). And it was able to run the section of code until the Irr = _ line where it yells at me with a line saying “IAR_DataGridi] object is not callable” is this still related to the same issue with pythonnet? Is it better to downgrade to the lower 2.5.x version of pythonnet? Thanks for your help! FYI, see code below.
# initialize analysis tools
TheAnalyses = TheSystem.Analyses
POP = TheAnalyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.PhysicalOpticsPropagation)
POP_set = POP.GetSettings().__implementation__
POP_set.DataType = ZOSAPI.Analysis.PhysicalOptics.POPDataTypes.Irradiance
POP_set.Field.SetFieldNumber(1)
POP_set.EndSurface.SetSurfaceNumber(2)
POP.ApplyAndWaitForCompletion()
POP_result = POP.GetResults()
Irr = float(POP_result.DataGrids(1).Values)
Cheers,
Armand
Hi Michael,
Thanks for your help and I was finally able to solve the issue! Thought I would reply with the solution that worked for me in case anyone else gets stuck on this. (Still have the issue with “IAR_DataGridi] object is not callable”, but one step at a time:) )
# initialize analysis tools
TheAnalyses = TheSystem.Analyses
POP = TheAnalyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.PhysicalOpticsPropagation)
ws1 = POP.GetSettings()
POP_set = ZOSAPI.Analysis.PhysicalOptics.IAS_PhysicalOpticsPropagation(ws1)
POP_set.Field.SetFieldNumber(1)
POP_set.EndSurface.SetSurfaceNumber(2)
Cheers,
Armand
Hi Armand,
Please see the proper way for running the POP analysis and getting the results (data1 and data2 return the same values, just different ways of accessing the data):
import zosapi, os
# connect to the ZOSAPI
zos = zosapi.App()
TheSystem = zos.TheSystem
ZOSAPI = zos.ZOSAPI
# load a system
TheSystem.LoadFile(os.path.join(os.path.sep, TheSystem.TheApplication.SamplesDir, r'Sequential\Objectives\Double Gauss 28 degree field.zmx'), False)
# open the POP analysis window
pop = TheSystem.Analyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.PhysicalOpticsPropagation)
# for PythonNet 3.x or greater
settings = pop.GetSettings().__implementation__
# for PythonNet 2.x
# settings = POP.GetSettings()
settings.Field.SetFieldNumber(1)
settings.EndSurface.SetSurfaceNumber(2)
# run the analysis
pop.ApplyAndWaitForCompletion()
# get the results from the analysis
results = pop.GetResults()
# this is a callable method accessed with parenthesis (0-indexed)
data1 = results.GetDataGrid(0).Values
# this is an array of data grids accessed with square brackets (0-indexed)
data2 = results.DataGrids[0].Values
# need to convert to list, not float, to change from .NET double[,] to python values
pyData1 = list(data1)
pyData2 = list(data2)
Hi Armand,
Please see the proper way for running the POP analysis and getting the results (data1 and data2 return the same values, just different ways of accessing the data):
import zosapi, os
# connect to the ZOSAPI
zos = zosapi.App()
TheSystem = zos.TheSystem
ZOSAPI = zos.ZOSAPI
# load a system
TheSystem.LoadFile(os.path.join(os.path.sep, TheSystem.TheApplication.SamplesDir, r'Sequential\Objectives\Double Gauss 28 degree field.zmx'), False)
# open the POP analysis window
pop = TheSystem.Analyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.PhysicalOpticsPropagation)
# for PythonNet 3.x or greater
settings = pop.GetSettings().__implementation__
# for PythonNet 2.x
# settings = POP.GetSettings()
settings.Field.SetFieldNumber(1)
settings.EndSurface.SetSurfaceNumber(2)
# run the analysis
pop.ApplyAndWaitForCompletion()
# get the results from the analysis
results = pop.GetResults()
# this is a callable method accessed with parenthesis (0-indexed)
data1 = results.GetDataGrid(0).Values
# this is an array of data grids accessed with square brackets (0-indexed)
data2 = results.DataGrids[0].Values
# need to convert to list, not float, to change from .NET double[,] to python values
pyData1 = list(data1)
pyData2 = list(data2)
Hi Michael,
I tried using this code. however, when I open the POP analysis window using the same line, it automatically starts running the analysis. Is there a way to avoid that?
-Alex
Hey Alex,
Simply replace New_Analysis with New_Analysis_SettingsFirst
.