示例#1
0
文件: tests.py 项目: xfcl/libzmx
    def runTest(self) :
        z = Connection()

        response = z.NewLens()
        self.assertFalse(response, "Can't create new lens")

        # find number of surfaces
        response = z.GetSystem()
        numsurfs1 = response[0]

        response = z.InsertSurface(2)
        self.assertFalse(response, "Can't insert a surface")

        # check number of surfaces increased
        response = z.GetSystem()
        numsurfs2 = response[0]
        self.assertEqual(numsurfs2, numsurfs1+1, "Number of surfaces didn't increase")

        # copy lens to editor
        response = z.PushLens()
        self.assertFalse(response, "Can't push lens to editor window")

        response = z.NewLens()
        self.assertFalse(response, "Can't create new lens")
        
        response = z.GetSystem()
        self.assertNotEqual(response[0], numsurfs2,
                            "New lens has same number of surfaces as old (modified) one")

        # copy modified lens back into server memory        
        response = z.GetRefresh()

        # check it's our modified lens
        response = z.GetSystem()
        self.assertEqual(response[0], numsurfs2, "Didn't get our lens back")
示例#2
0
z.SetSolve(
    6,  # surface number
    0,  # solve code for curvature
    11,  # solve type code for f/#
    3.5  # desired f/#
)

# Let's add an extra constraint. We'll make the curvatures on the
# faces of the central element equal.  We can insert a pickup solve
# like this:
central_front_face = model[3]
central_rear_face = model[4]
central_rear_face.curvature = -central_front_face.curvature.linked()

# Load a merit function from another zemax file
z.LoadMerit("C:\\Program Files\\ZEMAX\\Samples\\Short course\\sc_cooke2.zmx")

# Insert a flat, glass window in front of the lens
model.insert_new(1, surface.Standard, "Window", thickness=1.0, glass="BK7")
model.insert_new(2, surface.Standard, thickness=10.0)

print("Optimising ....")
print("Initial merit func = %g" % z.Optimize(-1))
print("Final merit func = %g" % z.Optimize())

# Push the lens from the Zemax server into the display.
# The option "allow extensions to push lenses" should be enabled in
# Zemax preferences.
z.GetUpdate()
z.PushLens()