Solved

Missing ZOSAPI methods for POP Analysis


Hello,

 

I’m trying to control POP analysis through Python, and when trying to change the settings of the POP analysis window, I appear to missing the necessary ZOSAPI methods. Looking at this article, I see the below command to

 

my_analysis = TheSystem.Analyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.ANALYSIS_ENUMERATOR_HERE);

 

When I try to do this myself, it doesn’t appear as though I can see the Analysis class for ZOSAPI. The only thing I see is the ZOSAPI_Connection class. I see that in the help it should have the Analysis namespace, but I’m unable to call it in Python.

 

Thanks,

Cedar

 

Update: It seems I’m able to call the Analysis class even though it doesn’t appear in the IDE with the above command. Once I do, it shows up normally. I just have to remember what all the different methods/classes are named.

 

My next problem is that according to the ZOSAPI help, the PhysicalOpticsPropagation should have the StartSurface property that I need to be able to set before running analysis, but I get following error:

AttributeError: 'IAS_' object has no attribute 'StartSurface'

When trying to use the following code:

settings = pop_analysis.GetSettings()
settings.StartSurface = 1

Please advise.

 

Thanks,

Cedar

icon

Best answer by Csilla Timar-Fulep 24 May 2022, 15:55

View original

5 replies

Userlevel 7
Badge +2

Hi Cedar,

 

If you look at the ZOS-API Syntax Help File, you’ll find that the StartSurface property is GET only.

 

 

What this means is that you can only get the StartSurface, and not set it directly. You will also notice that the return type is IAS_Surface, and not an integer indicating the surface number.

If you click on the return type, this is what it shows in the Syntax Help:

 

 

As you can see, an IAS_Surface type has different functions to get the surface number (GetSurfaceNumber()) as an integer, and set the surface number: SetSurfaceNumber(int N). The latter has an integer parameter indicating the surface number.

Thus, in your example, you need to write:

start_surf = settings.StartSurface

start_surf.SetSurfaceNumber(1)

or simply

settings.StartSurface.SetSurfaceNumber(1)

Let me know if that makes sense.

Take care,

 

David

 

Hi David,

 

Thanks for your response. That makes sense, and I appreciate your correction, but I’m afraid that’s not my main problem. The command to open the POP analysis seems to work. After entering

pop_analysis = TheSystem.Analyses.New_Analysis_SettingsFirst(ZOSAPI.Analysis.AnalysisIDM.PhysicalOpticsPropagation)

I see a blank POP window come up, so that works, but when trying to use your suggestion and entering:

settings = pop_analysis.GetSettings()
start_surf = settings.StartSurface

I get the error I mentioned above:

AttributeError: 'IAS_' object has no attribute 'StartSurface'

When I check

pop_analysis.HasAnalysisSpecificSettings

it returns “True”, so I’m just confused at what exactly is happening. Everything else seems to work, I just can’t access the POP settings.

 

Thanks,

Cedar

Userlevel 7
Badge +2

Hi Cedar,

 

That is strange. The following snippet works on my machine with Python:

 

MyPOP = TheSystem.Analyses.New_Analysis_SettingsFirst(ZOSAPI.Analysis.AnalysisIDM.PhysicalOpticsPropagation)
MyPOPSet = MyPOP.GetSettings()
MyPOPSet.StartSurface.SetSurfaceNumber(7)
MyPOP.ApplyAndWaitForCompletion()

 

Obviously, your system needs to have at least seven surfaces, otherwise, I think it defaults to 1 or whatever saved configuration you might have.

Additionally, if I run your lines of code (copy/paste), it also works for me (at least with Python). settings is quite a generic name, is it possible that you have multiple variables called this way?

Could you share more details about how you are setting the ZOS-API? Are you using an interactive extension or standalone app? What programming langage do you use?

Sometimes, I find that restarting my machine helps when some strange errors like this happen.

Take care,

 

David

Userlevel 5
Badge +2

Hello,

@Cedar.Andre in order to be able to see the different classes used in your native Python IDE you will need to use the Interactive Extension connection type. This processed is discussed in more details in this knowledgebase article:
Connect to OpticStudio from Python with the ZOS-API Interactive Extension – Knowledgebase (zemax.com)

Then regarding the error message you got when trying to set the Start Surface parameter, are you using the COM or the .NET communication from Python? If you are using the COM communication, then this might be why you have the error. In this case you would need to cast the settings. Please take a look at this Community Forum thread where the differences between the COM and .NET communication forms are explained:
What is the difference between Python COM and Python .NET? | Zemax Community

Further details about the COM and .NET based communications can be found in these articles:
ZOS-API using Python – Knowledgebase (zemax.com)

ZOS-API using Python.NET – Knowledgebase (zemax.com)

I hope this helps, but if you have any further questions, please do not hesitate to ask.

Best,
Csilla

Hi David and Csilla,

 

I was using Python, but I found the issue. I was using an experimental build for pythonnet. When reverting to the latest version, 2.5.2, I was able to use it normally. Thanks for all your help! I was sure I was doing everything else correctly, so it was really hard to see exactly what was wrong.

 

Thanks!

Cedar

Reply