コード例 #1
0
ファイル: pyZDDEscenariotest.py プロジェクト: rhambach/PyZDDE
def test_scenario_multipleChannel():
    """Test multiple channels of communication with ZEMAX"""
    # Create multiple client objects
    ln0 = pyz.PyZDDE()
    ln1 = pyz.PyZDDE()
    ln2 = pyz.PyZDDE()

    # Initialize
    ch0_status = ln0.zDDEInit()
    print("\nStatus for link 0:", ch0_status)
    assert ch0_status==0  # Note that this will case the program to terminate without shutting down the server. The program will have to be restarted.
    print("App Name for Link 0:", ln0._appName)
    print("Connection status for Link 0:", ln0._connection)
    time.sleep(0.1) # Not required, but just for observation

    ch1_status = ln1.zDDEInit()
    print("\nStatus for link 1:",ch1_status)
    assert ch1_status == 0 # Note that this will case the program to terminate without shutting down the server. The program will have to be restarted.
    print("App Name for Link 1:", ln1._appName)
    print("Connection status for Link 1:", ln1._connection)
    time.sleep(0.1)   # Not required, but just for observation

    # Create a new lens in the first ZEMAX DDE server
    ln0.zNewLens()
    sysPara = ln0.zGetSystem()
    sysParaNew = ln0.zSetSystem(0,sysPara[2], 0, 0, 20, 1, -1)
    ln0.zInsertSurface(1)

    # Delete one of the objects
    del ln2   # We can delete this object like this since no DDE conversation object was created for it.

    # Load a lens into the second ZEMAX DDE server
    filename = os.path.join(zmxfp,'Cooke_40_degree_field.zmx');
    assert os.path.exists(filename), "file not found: '%s'" % filename
    ret = ln1.zLoadFile(filename)
    assert ret == 0
    print("\nzLoadFile test successful")


    #Get system from both the channels
    recSys0Data = ln0.zGetSystem()
    recSys1Data = ln1.zGetSystem()

    print("\nSystem data from 1st system:", recSys0Data)
    print("\nSystem data from 2nd system:", recSys1Data)


    # Close the channels
    ln0.zDDEClose()
    ln1.zDDEClose()
コード例 #2
0
def main():
    # Get data items (class methods) from PyZDDE
    pyzobj = pyz.PyZDDE()
    method_list = [
        method[0]
        for method in inspect.getmembers(pyzobj, predicate=inspect.ismethod)
    ]
    dataItemSet_pyzdde = []
    ipzFunctions = []  # interactive helper functions
    for item in method_list:
        if item.startswith('z'):
            dataItemSet_pyzdde.append(item.split('z', 1)[1])
        elif item.startswith('ipz'):
            ipzFunctions.append(item)
    dataItemSet_pyzdde = set(dataItemSet_pyzdde)
    #print("\nData items in PyZDDE: \n", dataItemSet_pyzdde)
    itemCount_pyzdde = len(dataItemSet_pyzdde)

    # Get data items from textfile
    dataItemSet_zemax = []
    dataItemFile = open(testdirectory + os.path.sep + "zemaxDataItems.txt",
                        "r")
    for line in dataItemFile:
        if line.rstrip() is not '':
            if not line.rstrip().startswith('#'):
                dataItemSet_zemax.append(line.rstrip())
    dataItemFile.close()
    dataItemSet_zemax = set(dataItemSet_zemax)

    # Obsolete data items
    dataItemSet_obsolete = set(['SetUDOData'])
    dataItemSet_zemax = dataItemSet_zemax - dataItemSet_obsolete
    #print("\nData items in Zemax: \n", dataItemSet_zemax)
    itemCount_zemax = len(dataItemSet_zemax)

    # Print useful information
    print("Total number of data items defined in ZEMAX Manual:",
          itemCount_zemax)
    print("Total number of PyZDDE class methods with prefix z:",
          itemCount_pyzdde)

    if dataItemSet_zemax.issubset(dataItemSet_pyzdde):
        print("\nGREAT! All data items defined in Zemax Manual are in PyZDDE.")
    else:
        dataItemsNotInPyZDDE = dataItemSet_zemax.difference(dataItemSet_pyzdde)
        print("\nOOPS! Looks like there are some still lurking around.")
        print("\nData items in Zemax but not in PyZDDE: \n",
              dataItemsNotInPyZDDE)

    # Other functions not defined in ZEMAX manual
    extraFunctions_set = dataItemSet_pyzdde.difference(dataItemSet_zemax)
    extraFunctions = [''.join(['z', exfun]) for exfun in extraFunctions_set]
    print("\nExtra functions:")
    print(extraFunctions)
    print("Total extra functions: ", len(extraFunctions))
    print("\nipz helper functions:")
    print(ipzFunctions)
    print("Total ipz functions: ", len(ipzFunctions))
コード例 #3
0
        global HIATUS_UPPER_LIMIT
        global NORMALIZATION_EFL
        self.normEFLentry.focus_set()
        NORMALIZATION_EFL = float(self.normEFLentry.get())
        self.maxHiatusEntry.focus_set()
        HIATUS_UPPER_LIMIT = float(self.maxHiatusEntry.get())
        root.quit()
        root.destroy()


TkFileDialog(root).pack()
root.mainloop()
#end of Tikinter GUI code

# Create a DDE channel object
pyZmLnk = pyzdde.PyZDDE()
#Initialize the DDE link
stat = pyZmLnk.zDDEInit()

#Get all the zemax files in the directories recursively
pattern = "*.zmx"
filenames = [
    os.path.join(dirpath, f) for dirpath, subFolders, files in os.walk(zmxfp)
    for f in fnmatch.filter(files, pattern)
]
parentFolder = str(os.path.split(zmxfp)[1])

###To just use one file FOR DEBUGGING PURPOSE -- comment out this section
##oneFile = []
##oneFile.append(filenames[1])
##filenames = oneFile
コード例 #4
0
        global HIATUS_UPPER_LIMIT
        global NORMALIZATION_EFL
        self.normEFLentry.focus_set()
        NORMALIZATION_EFL = float(self.normEFLentry.get())
        self.maxHiatusEntry.focus_set()
        HIATUS_UPPER_LIMIT = float(self.maxHiatusEntry.get())
        root.quit()
        root.destroy()


TkFileDialog(root).pack()
root.mainloop()
#end of Tikinter GUI code

# Create a DDE channel object
ln = pyzdde.PyZDDE()
#Initialize the DDE link
stat = ln.zDDEInit()

#Get all the zemax files in the directories recursively
pattern = "*.zmx"
filenames = [
    os.path.join(dirpath, f) for dirpath, subFolders, files in os.walk(zmxfp)
    for f in fnmatch.filter(files, pattern)
]
parentFolder = str(os.path.split(zmxfp)[1])

###To just use one file FOR DEBUGGING PURPOSE -- comment out this section
##oneFile = []
##oneFile.append(filenames[1])
##filenames = oneFile
コード例 #5
0
        weight: Field weight
    
    Returns:
        None'''

    if num == 0: raise Exception("There is no field angle 0")

    link.zSetField(
        num,  # field number
        angleX,
        angleY,  # Angles x/y
        weight)  # Field weight


if __name__ == '__main__':
    l0 = pyz.PyZDDE()
    status = l0.zDDEInit()
    print status

    l0.zLoadFile("C:\\Users\\npk\\Dropbox\\zemax_runs\\2014_apr_1_mobie_a")

    import numpy as np
    import pylab as pl

    l = []

    VALUE = 10  # Merit function value
    create_genf(l0, 1, 1, dist=13.5)

    XS = np.arange(-0.07, 0.07, 0.1)
    YS = np.arange(-0.06, 0.06, 0.1)