Skip to main content

Hello!

 

I am new to ZPL Programming. I currently have the task to extract clear aperture values from Zemax (not according to surface number but the surface names ) using a ZPL macro. I am currently struggling to find the right command. 

 

It would be great if someone could help.

 

Kind Regards,

Santhoshi

Hi Santhoshi,

 

As far as I know, you can only retrieve a surface by its number. Therefore, I suggest creating a FOR-loop that goes through every surface and checks the surface name (I’m assuming what you call “name” is the Comment column) before returning the clear aperture. This example should get you started:

# Target Comment
tar_com$ = "Target"

# Number of surfaces in the system
num = NSUR()

# Loop over the surfaces
FOR ii, 0, num, 1
# Current surface Comment
cur_com$ = $COMMENT(ii)

# Compare current surface Comment
# with target Comment
IF ( cur_com$ $== tar_com$ )
# Print current surface Clear Semi-Diameter
PRINT SDIA(ii)
ENDIF
NEXT

If you have a Surface with its Comment value is “Target” (case sensitive), then this macro returns its Clear Semi-Diameter. Note that if two surfaces have the Comment “Target”, they’ll both have their Clear Semi-Diameter printed.

Let me know if it makes sense.

Take care,

 

David


Thank you very much. This helps alot. 

 

However there is one small addition to the task. How do I set the clear aperture value (SDIA) to a different one ? 

Any inputs from you is valuable

Kind Regards,

Santhoshi


Hi Santhoshi,

 

TL;DR the keyword you are looking for is SURFACEPROPERTY or SURP

In my previous reply, notice that after SDIA you have parentheses and a parameter (the surface number) in between the parentheses. This is characteristic of what we call a function in most programming langages, and in OpticStudio, functions generally have a return value. In this case, the return value is a number, the clear semi-diameter. Therefore, we call it a numeric function. If you type F1 (Help File) and search “numeric functions”, the first topic returned will give you a list of all the functions that return a number in OpticStudio.

What you are asking now is a command that is not returning anything and instead modifies something in your system. These commands are refered to as “keywords” in OpticStudio. If you press F1 again, and search “keywords”, the first result is a list of all the keywords available. The one you’re interested in is SURFACEPROPERTY or SURP. The syntax of this keyword is as follows:

SURP surface, code, value1, value2

Notice it doesn’t have parentheses, because it isn’t a function. Its a keyword. This keyword modifies a surface property indicated by the code number. In the Help File, you’ll find all the available codes, but the one you want is:

6 or SDIA

Clear semi-diameter or Semi-diameter. If the value is zero or positive, the clear semi-diameter or semi-diameter solve is set to "Fixed". If the value is negative, the clear semi-diameter or semi-diameter solve is set to "Automatic" and the clear semi-diameter or semi-diameter will be computed with the next UPDATE keyword.

For SURP, the value2 parameter is ignored, and value1 is the new clear semi-diameter value.

I hope this helps and take care,

 

David


Thank you very much for your reply!


Reply