Tagged: bounding box, hashme, reuse cells
- This topic has 4 replies, 2 voices, and was last updated 4 years, 12 months ago by Ronald.
-
AuthorPosts
-
5 June 2019 at 13:49 #5550DaneelMember
I’m doing a design where many rectangles with different sizes will be created as cells. The cells will be names according to their length and width:
def rectangles(length=80, width=80): with nd.Cell('rectangle_' + str(length) + 'x' + str(width)) as rectangle: rect = geom.box(length=length, width=width) nd.Polygon(points=rect).put(0, 0) return rectangle
In a second cell many of these rectangle cells will be created and used with different sizes.
I do not want to create a cell with the same dimensions twice, instead I want to use the cell which already exists.
Is there a way to determine if a rectangle cell with specific dimensions does already exist (maybe by checking if the name already exist)?
Thank you very much for your help.
5 June 2019 at 13:58 #5552RonaldKeymasterDear Daneel,
Using the @hashme decorator should work for you as discussed in this topic
import nazca as nd @nd.bb_util.hashme('rectangle', 'length', 'width') # gives default cell name 'rectangle_80_80' def rectangles(length=80, width=80): with nd.Cell(hashme=True) as rectangle: rect = geom.box(length=length, width=width) nd.Polygon(points=rect).put(0, 0) return rectangle
In case you still want to know which cells have been defined you can try the following code to print all cell names:
import nazca as nd for name in nd.cfg.cellnames.keys(): print(name)
Ronald
5 June 2019 at 15:08 #5553DaneelMemberThank you so much for the help.
17 December 2019 at 10:32 #5920DaneelMemberHello Ronald,
I have another follow-up question on that topic.
I have a function which defines a cell which itself consists of several subcells. Is it possible to use the hasme = True statement with the last cell, which is returned by the function? If I do it like that I receive an exceptio: Exception: Detected a call nd.Cell(hashme=True) without first calling the @hashme(‘cellname’) decorator with a non-empty ‘cellname’.
Does that mean the hashme only works with one cell per function, does the cell which is hashed has to be follow the function definition directly or do i have to hash each cell in the function?
import nazca as nd import nazca.geometries as geom @nd.bb_util.hashme('rectangle', 'length', 'width') # gives default cell name 'rectangle_80_80' def rectangles(length=80, width=80): with nd.Cell('Text') as text: nd.text(text = 'Rectangle' + str(length) +' ,' + str(width), height = 30, layer = 'Label', align='cc').put(0,0) with nd.Cell(hashme=True) as rectangle: rect = geom.box(length=length, width=width) nd.Polygon(points=rect).put(0, 0) text.put(100,0) return rectangle
rectangles().put()
rectangles().put()nd.export_gds()
18 December 2019 at 00:59 #5922RonaldKeymasterDear Daneel,
The first cell you create after evoking the @hashme will get the name created by hashme.
You can simply nest your ‘text’ cell inside the ‘rectangle’ cell to get what you need:
import nazca as nd import nazca.geometries as geom @nd.bb_util.hashme('rectangle', 'length', 'width') def rectangles(length=80, width=80): with nd.Cell() as rectangle: with nd.Cell() as text: nd.text('text', height=30, layer='Label', align='cc').put(0) rect=geom.box(length=length, width=width) nd.Polygon(points=rect).put(0, 0) text.put(100, 0) return rectangle rectangles().put(0) rectangles().put(0) nd.export_gds()
If all you ultimately want to do here is to get access the cell name to print it you have other options too. You can use the Cell attribute cell_name and get rid of the second explicit cell altogether:
@nd.bb_util.hashme('rectangle', 'length', 'width') def rectangles(length=80, width=80): with nd.Cell() as rectangle: text = nd.text(text=rectangle.cell_name[:-6], height=30, layer='Label', align='cc') rect=geom.box(length=length, width=width) nd.Polygon(points=rect).put(0, 0) text.put(100, 0) return rectangle
A last alternative is to use a bounding box:
@nd.bb_util.hashme('rectangle', 'length', 'width') def rectangles(length=80, width=80): with nd.Cell() as rectangle: rectangle.autobbox = True rect=geom.box(length=length, width=width) nd.Polygon(points=rect).put(0, 0) return rectangle
Ronald
-
AuthorPosts
- You must be logged in to reply to this topic.