def testSaving(self): z = Connection() z.NewLens() model = SurfaceSequence(z) # Zemax surface comments must be 32 characters or less, to # survive saving and reloading surf = model.insert_new(1, surface.Standard) id = surf.id comment = "c"*20 tag = "t"*9 surf.comment = comment surf.comment.tag = tag self.assertEqual(len(surf.comment._client_get_value()), libzmx.CommentParameter.max_len) # Surface can be retrieved from unsaved model els = NamedElements(model) self.assertEqual(id, getattr(els, tag).id) # Save model (fd, modelf) = tempfile.mkstemp(".ZMX") z.SaveFile(modelf) n = len(model) z.NewLens() self.assertNotEqual(n, len(model)) # Reload model z.LoadFile(modelf) els2 = NamedElements(model) # Comment and tag are intact s2 = getattr(els2, tag) self.assertEqual(id, s2.id) self.assertEqual(s2.comment.value, comment) os.close(fd) os.remove(modelf)
# $Rev: 351 $ # $Date: 2013-12-17 18:29:25 +0000 (Tue, 17 Dec 2013) $ # Loads one of the Zemax sample files "Cooke Triplet". # Performs an exercise from the Short Course, optimising the lens. from __future__ import print_function from zemaxclient import Connection from libzmx import * import surface # Establish a connection to the running Zemax application z = Connection() # Load a lens file into the Zemax server memory. # It won't yet appear in the zemax window. For that we need to do z.PushLens() z.LoadFile("C:\\Program Files\\ZEMAX\\Samples\\Short course\\sc_cooke1.zmx") # Get a SurfaceSequence instance. This behaves like a list of surfaces # (the same sequence as viewed in the Zemax lens data editor). model = SurfaceSequence(z) # Get a SystemConfig object. This allows us to get/set certain system # parameters (eg. the stop surface, ray aiming, etc.) systemconfig = SystemConfig(z) # Show the number of surfaces in the lens print("Number of surfaces in model : %d " % len(model)) # Display some information about each surface print("Surface number, radius, thickness....") for surf in model: curvature = surf.curvature.value