It looks like you're new here. If you want to get involved, click one of these buttons!
I'm trying to change Top cell name and write out the new GDS but in my Script there is error that I'm not able to point out, kindly provide your observation on same, and if you have any other suggestions that also good.
Below is my script.
import pya
KLAYOUT = pya.Layout()
gds_files = ["xyz.gds"]
top_cell = KLAYOUT.top_cell()
print(top_cell)
for each_gds in gds_files:
KLAYOUT.read(each_gds)
for top_cell_read in KLAYOUT.top_cells():
if top_cell_read.name != "xyz.gds":
top_cell_name = top_cell_read.name + "_mod"
new_top_cell = KLAYOUT.create_cell(top_cell_name)
new_top_cell.copy_tree(top_cell_read)
KLAYOUT.set_top_cell(top_cell_name)
KLAYOUT.write("xyz_m.gds")
Comments
Hello,
Modified the code a bit, it might be you want?
Vincent
Great! Thank you for help! @Vincent Lin
In above script the name of top-cell is hardcoded (top_cell_read.name != "xyz.gds":), but I want to find top- level cell from GDS via script then change the top-cell name.
import pya
KLAYOUT = pya.Layout()
gds_files = ["xyz.gds"]
for each_gds in gds_files:
KLAYOUT.read(each_gds)
top_cell = None
max_area = 0
for cell in KLAYOUT.each_cell():
bbox = cell.bbox()
area = bbox.width() * bbox.height()
if area > max_area:
top_cell = cell
max_area = area
if top_cell is not None:
top_cell.name = top_cell.name + "_mod"
print(f"Found top-level cell: {top_cell.name}")
KLAYOUT.write("xyz_new.gds")
I found this above script and it is working fine, Is there any other way to find top-cell name?
Hello rounak1068,
Never use script to re-name cell before, I made a trial to rename top-cell "M", it works and a new GDS also be created
Above code can give you this with new GDS file
Vincent
Thanks ... but the last code will write the file potentially multiple times, as "write" is called inside the loop. Or are you intending the create one file containing one particular top cell? In that case, the "write" statement can be called on the top cell instead of the layout object.
BTW: @rounak1068 this forum supports code formatting through Markdown like on GitHub for example: https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks
Matthias
Il semble que vous ayez commis un erreur en essayant de modifier le nom de la cellule supérieure et de créer un nouveau GDS file à l'aide d'un script.