heitzmann / gdspy

Python module for creating GDSII stream files, usually CAD layouts.
Boost Software License 1.0
352 stars 128 forks source link

referencing cells imported from a GDS file #243

Open dczaplewski opened 3 months ago

dczaplewski commented 3 months ago

I have a GDS file (Marks.gds). Inside this file are cells named: Cell1, Cell2, Cell3 I would like to import all the cells in this file into a new library. I would then like to reference them in the new library and instance them in other cells.

import gdspy
#Clears the current library so that you don't get the error message when you compile that the cell already exists
gdspy.current_library = gdspy.GdsLibrary()

lib = gdspy.GdsLibrary(infile='Marks.gds')
lib2 = gdspy.GdsLibrary()

for i in range(1,4,1)
     temp="Cell"+str(i)
     lib2.add(lib.cells[temp])

lib2.write_gds('test.gds')

When I run this code, it imports all three cells into the second library and they are included in the 'test.gds' file. However, I would like to reference them and move them around. When I try to do this, the code won't compile because I did not explicitly define the name of the cells: Cell1, Cell2, and Cell3.

import gdspy
#Clears the current library so that you don't get the error message when you compile that the cell already exists
gdspy.current_library = gdspy.GdsLibrary()

lib = gdspy.GdsLibrary(infile='Marks.gds')
lib2 = gdspy.GdsLibrary()

for i in range(1,4,1)
     temp="Cell"+str(i)
     lib2.add(lib.cells[temp])

x1=-2000;
y1=2000;
ref = gdspy.CellReference(Cell1, (x1,y1))

# define cell named CellA
CellA = lib.new_cell('Some_cool_name_in_the_GDS_file')
cellA.add(ref)

lib2.write_gds('test.gds')

I get this error message: UserWarning: [GDSPY] Cell ['Cell1'] not found; operations on this CellReference may not work.

So, how do I import cells from a GDS file into a library and then later reference them to move them around or create arrays of them?

Thanks,

heitzmann commented 3 months ago

You can reference the cell object directly when you create a referece:

ref = gdspy.CellReference(lib2.cells["Cell1"], (x1,y1))