I always like to check that my file is loaded properly before attempting any calculation on the file. So, a future debugging technique, I would always use code like below:
TheSystem.LoadFile(ZemaxDesignFilePath)
if TheSystem.Mode == ZOSAPI.SystemType.Sequential:
assert TheSystem.SystemData.Aperture.ApertureValue > 0 or TheSystem.LDE.NumberOfSurfaces != 3, "Sequential system could not load"
else:
assert TheSystem.NCE.NumberOfObjects > 1 or TheSystem.NCE.GetObjectAt(1).Type != ZOSAPI.Editors.NCE.ObjectType.NullObject, "Non-sequential system could not load"
This checks to make sure a sequential system either has more than the default 3 surfaces or has an aperture value greater than 0 (so that rays can trace); if the system is non-sequential, it makes sure the system is not the default single object Null Object. This works even if your Default Startup in the GUI has a different file than the LENS.ZMX. This code snippet has saved me countless hours of debugging when my filepath is invalid.