Created
February 23, 2022 10:06
-
-
Save Omnistic/842ac850f90d946255f97f3ea7d250e6 to your computer and use it in GitHub Desktop.
Read all glass catalogs in OpticStudio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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