Example #1
0
"""
Make Schematic
==============

Creates an empty schematic at the specified location.

"""

from eaglepy import default_layers, eagle

schematic_path = "schematic.sch"

schematic = eagle.Schematic(sheets=[eagle.Sheet()])

drawing = eagle.Drawing(grid=eagle.Grid(), layers=default_layers.get_layers(), document=schematic)

e = eagle.Eagle(drawing)

e.save(schematic_path)
from eaglepy import constants, default_layers, eagle, primitives

schematic_path = 'schem_mult_sheets.sch'
num_sheets = 4
width = constants.UNIT.to_default(11, constants.UNIT.INCH)
height = constants.UNIT.to_default(8.5, constants.UNIT.INCH)
font_size = constants.UNIT.to_default(0.7, constants.UNIT.INCH)

schematic = eagle.Schematic()

for i in range(num_sheets):
    frame = primitives.Frame(0, 0, width, height, constants.LAYERS.NETS)
    
    label = primitives.Text("This is page {0}!".format(i+1), 
                            width/2.0, 
                            height/2.0, 
                            constants.LAYERS.INFO, 
                            font_size, 
                            constants.ALIGN.CENTER)
    
    sheet = eagle.Sheet(plain = [frame, label])
    
    schematic.sheets.append(sheet)

drawing = eagle.Drawing(grid = eagle.Grid(),
                        layers = default_layers.get_layers(),
                        document = schematic)
    
e = eagle.Eagle(drawing)

e.save(schematic_path)
Example #3
0
def lib_tool(args):
    """
    Run the tool with the specified argument to remove unused items, extract items to a
    library, or both. 
    
    :param args: A ``Lib_Tool_Arg`` instance.
    
    :returns: A ``Lib_Tool_Stats`` instance.
    """

    # Create a new EAGLE library
    if args.library_name != None:
        lib = eagle.Library(name = args.library_name)

    # Open the file
    e_sch = eagle.Eagle.load(args.input_sch_file)
    
    # Get the drawing
    sch = e_sch.drawing.document
    
    # Get the board
    if args.input_brd_file != None:
        e_brd = eagle.Eagle.load(args.input_brd_file)
        brd = e_brd.drawing.document
    
    if args.keep_unused == False:
        # Create sets of used libraries, used device sets, and used devices
        used_libraries = set([])
        used_device_sets = set([])
        used_devices = set([])
        
        for p in sch.parts:
            if not p.library in used_libraries:
                used_libraries.add(p.library)
                
            if not p.device_set in used_device_sets:
                used_device_sets.add(p.device_set)
                
            if not p.device in used_devices:
                used_devices.add(p.device)
        
        # Statistics 
        stats = Lib_Tool_Stats()
        
        # Iterate over all of the libraries referenced in the schematic. 
        
        for l in sch.libraries:
    
            # If the library is not referenced, remove it and continue.
            if not l in used_libraries:
                sch.libraries.remove(l)
                stats.libs_removed += 1
                continue 
    
            used_packages = set([])
            used_symbols = set([])
    
            # Iterate over the device sets in the library. 
            for ds in l.device_sets:
            
                if not ds in used_device_sets:
                    l.device_sets.remove(ds)
                    stats.device_sets_removed += 1
                    continue
                else:
                    for g in ds.gates:
                        if not g.symbol in used_symbols:
                            used_symbols.add(g.symbol)
                
                # Iterate over the devices in the device set.
                for d in ds.devices:
                
                    if not d in used_devices:
                        ds.devices.remove(d)
                        stats.devices_removed += 1
                    else:
                        if not d.package in used_packages:
                            used_packages.add(d.package)
                            
            # Iterate over all of the symbols in the library and remove unused.
            for s in l.symbols:
                if not s in used_symbols:
                    l.symbols.remove(s)
                    stats.symbols_removed += 1
                            
            # Now, iterate over all of the packages in the library and remove unused.
            for p in l.packages:
                if not p in used_packages:
                    l.packages.remove(p)
                    stats.packages_removed += 1
        
    if args.library_name != None:
        # All device sets, symbols, and packages will be combined into a single library. 
        # A library cannot contain duplicate names, however, so we must determine if duplicate
        # names exist and if so, make the names unique.
        
        # Get a dictionary whose key is a package name and whose value is a list of the corresponding
        # libraries and packages in the library with that name.
        packages = get_lib_and_package_for_package_name_dict(sch.libraries)
        # Update any duplicate package names and add each package to the library
        get_name_dict_and_append_item(packages, lib.packages)
        
        # Get a dictionary whose key is a symbol name and whose value is a list of the corresponding
        # libraries and symbols in the library with that name.
        symbols = get_lib_and_symbol_for_symbol_name_dict(sch.libraries)
        # Update any duplicate symbol names and add each symbol to the library
        get_name_dict_and_append_item(symbols, lib.symbols)
        
        # Get a dictionary whose key is a device set name and whose value is a list of corresponding
        # libraries and symbols in the library with that name.
        device_sets = get_lib_and_dev_set_for_dev_set_name_dict(sch.libraries)
        # Update any duplicate device set names and add each device set to the library
        get_name_dict_and_append_item(device_sets, lib.device_sets)
             
        # Replace all existing libraries with the new library
        sch.libraries = [lib]
        
        if args.input_brd_file != None:
            brd.libraries = [lib]
        
        # Update all the parts to reference the new library
        for p in sch.parts:
            p.library = lib

        # Update all the elements to reference the new library
        if args.input_brd_file != None:
            for e in brd.elements:
                e.library = lib

    # Save the files         
    e_sch.save(args.output_sch_file)
    
    if args.input_brd_file != None:
        e_brd.save(args.output_brd_file)
    
    # Save the library
    if args.output_lbr_file != None:
        # Create the drawing
        grid = eagle.Grid()
        layers = default_layers.get_layers()
        e_drawing = eagle.Drawing(settings = {}, grid = grid, layers = layers, document = lib)
        
        # Create the Eagle object
        e_lbr = eagle.Eagle(e_drawing)
        
        # Save the library file
        e_lbr.save(args.output_lbr_file)
        
    return stats