Skip to content

Commit

Permalink
create_cell2 function
Browse files Browse the repository at this point in the history
Wrapper for KLayout's Layout.create_cell(name, library), with error handling, and debugging information if unsuccessful
  • Loading branch information
lukasc-ubc committed Jul 3, 2024
1 parent 8148767 commit b1de6cf
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion klayout_dot_config/python/SiEPIC/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
'''
List of functions:
create_cell2
advance_iterator
get_library_names
get_technology_by_name
Expand Down Expand Up @@ -63,6 +63,29 @@
import pya
'''

def create_cell2(ly, cell_name, library_name):
'''
Wrapper for KLayout Layout.create_cell(name, library),
with error handling, and debugging information if unsuccessful.
ly: pya.Layout
cell_name: string name for pya.Cell
library_name: string name for a pya.Library
'''
pcell = ly.create_cell(cell_name, library_name)
if not pcell:
if library_name not in pya.Library().library_names():
raise Exception('Error: library (%s) not available. Libraries for technology (%s) are: %s.' % (library_name, ly.technology().name, pya.Library().library_names()))
ly_library = pya.Library().library_by_name(library_name,ly.technology().name).layout()
library_cells = [ly_library.cell(a).name for a in ly_library.each_top_cell()]
if cell_name not in library_cells:
raise Exception('Error: cell (%s) not available in library (%s) for technology (%s). Cells are: %s.' % (cell_name, library_name, ly.technology().name, library_cells))

raise Exception('Error: loading cell (%s) from library (%s)' % (cell_name, library_name))

return pcell



# Python 2 vs 3 issues: http://python3porting.com/differences.html
# Python 2: iterator.next()
# Python 3: next(iterator)
Expand Down

0 comments on commit b1de6cf

Please sign in to comment.