Skip to main content

Call a parameter by its name in the ZOS-API

  • December 8, 2021
  • 7 replies
  • 1019 views

Allie
Zemax Staff
Forum|alt.badge.img+2
  • Zemax Staff
  • 337 replies

When dealing with non-Standard surface types, you typically have access to extra parameters that are specific to that surface. For example, the Coordinate Break surface provides inputs for Decenter X, Decenter Y, etc.

 

Coordinate Break surface type with the extra data parameters highlighted

To access these parameters in the API, our sample code offers two options:

  1. Access a parameter based on the parameter number. A typical command for this may look like the following: decenterX = TheSystem.LDE.GetSurfaceAt(1).GetSurfaceCell(ZOSAPI.Editors.LDE.SurfaceColumn.Par1).DoubleValue;
  2. Access a parameter based on its column number. A typical command for this may look like the following: decenterX = TheSystem.LDE.GetSurfaceAt(1).GetCellAt(12).DoubleValue;

In both of these cases, you will need to have prior knowledge of the location in the LDE of the parameters you want to change. Or you will need to query the “Header” of the column you’re working with to confirm the parameter is correct. 

There is a third surface-specific method for calling parameters by their title. This method utilizes the ISurface interface within the LDE namespace. The steps for accessing this are below:

  1. Access a surface with the GetSurfaceAt property
  2. Access the ISurface interface with the SurfaceData command
  3. If needed, cast to the ISurface interface with the interface of the surface type (required for C#, not required for Matlab or PythonNET)
  4. Call a parameter from this interface. This allows you to call with the name “Decenter_X” instead of with a column or parameter number.

The commands for surface-specific parameters are found in the corresponding ISurfaceXXX interface within the LDE Namespace:

 

Screenshot from the ZOS-API Syntax Guide LDE Namespace page directing to the ISurfaceCoordinateBreak section. 

 

Below, I am providing examples in some of our supported languages. 

Python .NET

Show content

surf1 = TheSystem.LDE.GetSurfaceAt(1)
surfData = surf1.SurfaceData
surfData.Decenter_X = 10

 

Matlab

Show content

    surf1 = TheSystem.LDE.GetSurfaceAt(1);
    surfData = surf1.SurfaceData;
    surfData.Decenter_X = 20;

 

C#

Show content

using System;
using ZOSAPI;
using ZOSAPI.Editors;
using ZOSAPI.Editors.LDE;

 

 

            ILensDataEditor TheLDE = TheSystem.LDE;
            ILDERow surf1 = TheLDE.GetSurfaceAt(1);
            ISurface surf1Data = surf1.SurfaceData;


            // We must cast to the specific surface interface from the ISurface interface
            var coordBreakParams = (ISurfaceCoordinateBreak)surf1Data;

 

            coordBreakParams.Decenter_X = 30;
            double decenterXVal = coordBreakParams.Decenter_X;

 

            Console.WriteLine(decenterXVal);
            Console.ReadKey();

 

Did this topic help you find an answer to your question?

7 replies

David.Nguyen
Luminary
Forum|alt.badge.img+2
  • Luminary
  • 1089 replies
  • December 8, 2021

Hi Allie,

 

This is excellent. I already love the third method, it’ll be so much more convenient to work with parameters now.

Thanks for sharing!

Take care,

 

David


David.Nguyen
Luminary
Forum|alt.badge.img+2
  • Luminary
  • 1089 replies
  • January 23, 2023

Hi Allie,

 

I hope you are well.

I was just going to try your third method for the first time, and it seems it might require casting with Python on my end.

This piece of code (Python 3.8.15, Pythonnet 2.5.2):

TheSystem.LDE.GetSurfaceAt(11).GetCellAt(14).DoubleValue

Returns the Tilt About X of a Coordinate Break surface (at least it works for me). However, this other piece of code:

TheSystem.LDE.GetSurfaceAt(11).SurfaceData.TiltAbout_X

Returns an error:

AttributeError: 'ISurface' object has no attribute 'TiltAbout_X'

Am I doing something wrong? If not, does it mean one needs to cast ISurface to ISurfaceCoordinateBreak, and if so, how would you do it?

Thanks for your help and take care,

 

David


Allie
Zemax Staff
Forum|alt.badge.img+2
  • Author
  • Zemax Staff
  • 337 replies
  • April 5, 2023

Hi David,

Apologies for the delayed response. I’m going through my email inbox and saw that I missed the notification for this post.

I tested your code in Python 3.8.10 with Pythonnet 2.5.2 and it worked fine, as shown below:

 

 

Have you re-tested since you first messaged? And can you confirm that surface 11 in your file is a Coordinate Break surface?


David.Nguyen
Luminary
Forum|alt.badge.img+2

Hi Allie,

 

I’ve tried it again today, and it works! I’m fairly sure my Surface 11 was a coordinate break because the GetCellAt(14) method was returning the right value so I don’t know what I did wrong at the time, but thanks a lot for your help and take care,

 

David


Tiberiu
  • Single Emitter
  • 2 replies
  • November 7, 2023

Hi Allie,
I have a similar problem to David, but can’t resolve it. I am trying to set the decenter of an off-axis conic freeform surface. 

First, I run those
 

        OAM = surfaces['Front'].GetSurfaceTypeSettings(self.ZOSAPI.Editors.LDE.SurfaceType.OffAxisConicFreeform)
        surfaces['Front'].ChangeType(OAM)
        surfaces['Front'].Conic = off_axis_conic_object.conic

which works fine.
For the decenter, I tried the simple GetCellAt() method by using: surfaces['Front'].GetCellAt(18).DoubleValue, but it fails giving:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: 'str' value cannot be converted to System.Double

 

I then tried the suggested method, using

surfData=surfaces['Front'].SurfaceData

surfData.Offset=2

 

Unfortunately, this makes no change to the LDE editor. Moreover the parameter does simply not exist

Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: 'ISurface' object has no attribute 'Offset'

 

I am running on Python 3.7 with pythonnet 3.0.1 with a live interactive extension (for debugging). I tried also in standalone and no improvements.
 

Thanks a lot,

Tiberiu.


Tiberiu
  • Single Emitter
  • 2 replies
  • November 8, 2023
Tiberiu wrote:

Hi Allie,
I have a similar problem to David, but can’t resolve it. I am trying to set the decenter of an off-axis conic freeform surface. 

First, I run those
 

        OAM = surfaces['Front'].GetSurfaceTypeSettings(self.ZOSAPI.Editors.LDE.SurfaceType.OffAxisConicFreeform)
        surfaces['Front'].ChangeType(OAM)
        surfaces['Front'].Conic = off_axis_conic_object.conic

which works fine.
For the decenter, I tried the simple GetCellAt() method by using: surfaces['Front'].GetCellAt(18).DoubleValue, but it fails giving:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: 'str' value cannot be converted to System.Double

 

I then tried the suggested method, using

surfData=surfaces['Front'].SurfaceData

surfData.Offset=2

 

Unfortunately, this makes no change to the LDE editor. Moreover the parameter does simply not exist

Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: 'ISurface' object has no attribute 'Offset'

 

I am running on Python 3.7 with pythonnet 3.0.1 with a live interactive extension (for debugging). I tried also in standalone and no improvements.
 

Thanks a lot,

Tiberiu.

I could use surfaces['Front'].GetCellAt() but using a much higher index. The second method still does not work.


David.Nguyen
Luminary
Forum|alt.badge.img+2
  • Luminary
  • 1089 replies
  • November 8, 2023

Hi @Tiberiu,

 

Try this:

surface_data = TheSystem.LDE.GetSurfaceAt(1).SurfaceData.__implementation__
surface_data.OffsetCell.DoubleValue = 0.111

I think its again related to this issue:

Hope this helps. By the way, what was the index for GetCellAt()?

Take care,

 

David


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings