I wish to print text/numbers to a mask for pattern identification and can't seem to figure out how to create text polygon objects in KLayout. Could you please point me in the right direction?
I'm not sure if this is what you want, but to create text/numbers using V0.22, I would create text/numbers using Text from the toolbar. Then, I select the text element and use the Edit > Selection > Convert to Pcell > Basic.TEXT to change it to polygon objects.
I'd like to create on-wafer text from a ruby script, but I'm having trouble figuring out the syntax.
Anyone have an example of calling the built-in text PCELL from ruby?
Here's what I've got so far (not quite working):
The intent is to step a cell across a wafer and then label instances with x-y numbers (different for each cell)
new_top = ly.add_cell("wafer")
#ref_layer = RBA::LayerInfo::new(1,0).layer
# use "guiding shape layer" for now since I can't get layer 0 to work
ref_layer = ly.guiding_shape_layer
#ref_layer = 0 w = 0.0
# add first instance of MAIN
firstmain = ly.cell(new_top).insert(RBA::CellInstArray::new(cell_index,RBA::CplxTrans::new(1,0,false,RBA::DPoint::new(0,0))))
maincellx = ly.cell(new_top).bbox.width/dbu
maincelly = ly.cell(new_top).bbox.height/dbu
ly.cell(new_top).erase(firstmain)
nc = ((d*1000.0) / maincellx).round
nr = ((d*1000.0) / maincelly).round
# draw circles
pts = []
n = 64
da = Math::PI * 2 / n
n.times do |i|
pts.push(Point.from_dpoint(DPoint.new(r*dbu * Math::cos(i * da), r*dbu * Math::sin(i * da))))
end
ly.cell(new_top).shapes(ref_layer).insert(Polygon.new(pts))
pts = []
n.times do |i|
pts.push(Point.from_dpoint(DPoint.new(re*dbu * Math::cos(i * da), re*dbu * Math::sin(i * da))))
end
ly.cell(new_top).shapes(ref_layer).insert(Polygon.new(pts))
# for text label
# find the built-in "Basic" library with the text PCELL
blib = Library.library_by_name("Basic")
# next line says 0 cells in library
# numcells = bliblay.cells
#tpc =
# create instances of MAIN
(nr+1).times do |j|
(nc+1).times do |i|
if Math::sqrt(((i-nc/2-0.5)*maincellx)**2 + ((j-nr/2-0.5)*maincelly)**2 ) <= r then
ly.cell(new_top).insert(RBA::CellInstArray::new(cell_index,Trans.new(0,(i-nc/2-0.5)*maincellx*dbu,(j-nr/2-0.5)*maincelly*dbu)))
# generate x-y numbers to write in each instance
x = 50 + (i-nc/2-0.5).round
y = 50 + (j-nr/2-0.5).round
labxytext = "#{y.to_s}#{x.to_s}"
# this does something, but not the text I want.
# note: can't find "TEXT" pcell, but it seems to be number 10 in the library.
# can't figure out the syntax to call it correctly
#labxy = ly.add_pcell_variant(blib,10,[labxytext,1,1,50,FALSE,0,0,0])
end
end
end
# fit the viewport to the extensions of our layout
layout_view.select_cell(new_top, 0)
layout_view.add_missing_layers
layout_view.zoom_fit
end
I shall explain a little regarding the concepts and the question you raised in your code:
"biblay.cells" returns 0 because the library contains PCells only (which are something different than static cells)
Please don't use constants for PCell ID's (like 10) - they are likely to change. Use "lib.layout.pcell_declaration(name)" to obtain the ID for a name.
For the same reasons, you should not pass a specific array for the parameters. In new releases, new parameters may be added for example. You can use the PCell declaration object to obtain the parameters and look up the parameters by name. Please have a look at the sample code in the link above.
Once you have created a PCell variant, you have a real cell that you can create an instance from.
The API for creating and changing PCell parameters will be enhanced in the next release, so it will be possible for example to modify PCell parameters by name.
Thanks for your help--I've got it working now.
Can you comment on how to change the "font" used for the layout text created by the TEXT pcell?
Specifically, I'd like to use a "font" which doesn't have any enclosed spaces (like the center of 0, 8, 6, 9, etc.)
Comments
I'm not sure if this is what you want, but to create text/numbers using V0.22, I would create text/numbers using Text from the toolbar. Then, I select the text element and use the Edit > Selection > Convert to Pcell > Basic.TEXT to change it to polygon objects.
-Ken
Anyone have an example of calling the built-in text PCELL from ruby?
Here's what I've got so far (not quite working):
The intent is to step a cell across a wafer and then label instances with x-y numbers (different for each cell)
module MyMacro
include RBA
# parameters
d = 150.0
e = 5.0
r = d/2
re = r - e
# convert to microns
r *= 1000.0
re *= 1000.0
mw = RBA::Application::instance.main_window
ly = mw.create_layout(0).layout
dbu = 1.0/ly.dbu
layout_view=mw.current_view
ly.read("file.gds")
cell_index = ly.cell_by_name("MAIN")
new_top = ly.add_cell("wafer")
#ref_layer = RBA::LayerInfo::new(1,0).layer
# use "guiding shape layer" for now since I can't get layer 0 to work
ref_layer = ly.guiding_shape_layer
#ref_layer = 0 w = 0.0
# add first instance of MAIN
firstmain = ly.cell(new_top).insert(RBA::CellInstArray::new(cell_index,RBA::CplxTrans::new(1,0,false,RBA::DPoint::new(0,0))))
maincellx = ly.cell(new_top).bbox.width/dbu
maincelly = ly.cell(new_top).bbox.height/dbu
ly.cell(new_top).erase(firstmain)
nc = ((d*1000.0) / maincellx).round
nr = ((d*1000.0) / maincelly).round
# draw circles
pts = []
n = 64
da = Math::PI * 2 / n
n.times do |i|
pts.push(Point.from_dpoint(DPoint.new(r*dbu * Math::cos(i * da), r*dbu * Math::sin(i * da))))
end
ly.cell(new_top).shapes(ref_layer).insert(Polygon.new(pts))
pts = []
n.times do |i|
pts.push(Point.from_dpoint(DPoint.new(re*dbu * Math::cos(i * da), re*dbu * Math::sin(i * da))))
end
ly.cell(new_top).shapes(ref_layer).insert(Polygon.new(pts))
# for text label
# find the built-in "Basic" library with the text PCELL
blib = Library.library_by_name("Basic")
# next line says 0 cells in library
# numcells = bliblay.cells
#tpc =
# create instances of MAIN
(nr+1).times do |j|
(nc+1).times do |i|
if Math::sqrt(((i-nc/2-0.5)*maincellx)**2 + ((j-nr/2-0.5)*maincelly)**2 ) <= r then
ly.cell(new_top).insert(RBA::CellInstArray::new(cell_index,Trans.new(0,(i-nc/2-0.5)*maincellx*dbu,(j-nr/2-0.5)*maincelly*dbu)))
# generate x-y numbers to write in each instance
x = 50 + (i-nc/2-0.5).round
y = 50 + (j-nr/2-0.5).round
labxytext = "#{y.to_s}#{x.to_s}"
# this does something, but not the text I want.
# note: can't find "TEXT" pcell, but it seems to be number 10 in the library.
# can't figure out the syntax to call it correctly
#labxy = ly.add_pcell_variant(blib,10,[labxytext,1,1,50,FALSE,0,0,0])
end
end
end
# fit the viewport to the extensions of our layout
layout_view.select_cell(new_top, 0)
layout_view.add_missing_layers
layout_view.zoom_fit
end
Hi
there was another forum entry about the same question: http://klayout.de/forum/comments.php?DiscussionID=230&page=1#Item_4.
I shall explain a little regarding the concepts and the question you raised in your code:
The API for creating and changing PCell parameters will be enhanced in the next release, so it will be possible for example to modify PCell parameters by name.
Regards,
Matthias
Can you comment on how to change the "font" used for the layout text created by the TEXT pcell?
Specifically, I'd like to use a "font" which doesn't have any enclosed spaces (like the center of 0, 8, 6, 9, etc.)
Hi,
there is a brief description here: http://www.klayout.de/doc/about/basic_lib.html#h2-44.
Regards,
Matthias