Skip to main content
Question

Glass name given the glass number in a given catalog"

  • November 18, 2025
  • 2 replies
  • 35 views

Mike.Jones
En-Lightened
Forum|alt.badge.img+3

I need the opposite of ZPL numerical function GNUM(a$), where a$ is a glass name in a given catalog and GNUM(a$) returns the glass number in the catalog.  I need the string name of the glass given the glass number in the catalog.  $GLASS(i) gives the glass on surface “i” of a loaded system rather than in a catalog.  Any tips?

Mike

2 replies

MichaelH
Ansys Staff
Forum|alt.badge.img+2
  • Ansys Staff
  • November 18, 2025

Hey Mike,

The code is a little bit verbose with a ZPL, but the concept is as follows:

  • Determine all the loaded Glass Catalogs in the correct order that are for the current system
  • Loop through all the new materials (NM) defined for the specific catalog
  • Once the iterator hits the desired glass number, return the glass name and exit the loop
desired_glass_number = 27

! get all the loaded catalogs
dummy = SYPR(23)
catalogs$ = $BUFFER()
glasscat_dir$ = $DATAPATH() + "\Glasscat\"

! determine the number of loaded catalogs by counting the white spaces
! NOTE: there is always a space after a catalog, even if there is only 1 loaded
num_catalogs = 0
FOR i = 1, SLEN(catalogs$), 1
tmp$ = $LEFTSTRING(catalogs$, i)
tmp$ = $RIGHTSTRING(tmp$, 1)
IF tmp$ $== " " THEN num_catalogs = num_catalogs + 1
NEXT

! loop through the catalogs in order and look for valid glass names
glass_num = 0
FOR i = 1, num_catalogs, 1
catalog$ = $GETSTRING(catalogs$, i)
catalog_file$ = glasscat_dir$ + catalog$ + ".AGF"

! check to make sure the file exits
filter$ = catalog_file$
FINDFILE tmp$, filter$
IF (SLEN(tmp$))
OPEN catalog_file$
LABEL BOF
READSTRING line$
IF (EOFF()) THEN GOTO EOF

! check if the line is a new material
! ideally we would trim the string to remove whitespaces
marker$ = $LEFTSTRING(line$, 2)

! ideally we would convert all letters to uppercase but we'll assume NM is uppercase
IF (marker$ $== "NM")
glass_num = glass_num + 1
glass_name$ = $GETSTRING(line$, 2)

! check the glass_num
IF glass_num == desired_glass_number
PRINT "Glass Number ", $STR(glass_num), " is for ", glass_name$, " material"

! let's verify this is the true
PRINT "VERIFY ", GNUM(glass_name$)

GOTO EOF
ENDIF


ENDIF
GOTO BOF
LABEL EOF
CLOSE
ENDIF
NEXT

 


Mike.Jones
En-Lightened
Forum|alt.badge.img+3
  • Author
  • En-Lightened
  • November 18, 2025

Thanks Michael, I’ll give this a try.

Of course, a ZPL string function $NUMGLASS(i) where “i” is the glass number in a catalog would do this in one line, if it existed.  But we all know that Zemax is 100% nonresponsive to any customer requests, so that will never happen.  I/we all wish that Zemax could be as responsive as you have been.  Thanks, Mike