Skip to content

Instantly share code, notes, and snippets.

@Omnistic
Created February 23, 2022 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Omnistic/842ac850f90d946255f97f3ea7d250e6 to your computer and use it in GitHub Desktop.
Save Omnistic/842ac850f90d946255f97f3ea7d250e6 to your computer and use it in GitHub Desktop.
Read all glass catalogs in OpticStudio
import os
# Path to {Documents}\Zemax\Glasscat
path = r'C:\Users\David Nguyen\Documents\Zemax\Glasscat'
# Initialize return array, which will contain the glass names and vendors
allglass = []
# Loop over the files in the GLASSCAT folder
for glasscat in os.listdir(path):
# Select files with the *.AGF extension
if glasscat.lower().endswith('.agf'):
# Save vendor name
vendor = glasscat[:-4]
# Read the file
with open(os.path.join(path, glasscat)) as glasstxt:
# Search for the lines starting with NM (contains the glass name)
for line in glasstxt:
if line.lower().startswith('nm'):
# Save the glass name
glassname = line[3:]
glassname = glassname[:glassname.find(' ')]
allglass.append((vendor, glassname))
# Display results
for glass in allglass:
print('Vendor: ' + glass[0] + ' | Glass: ' + glass[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment