It looks like you're new here. If you want to get involved, click one of these buttons!
Hi, Matthias,
I am a new user for KLayout. I try to generate a cell array and refered to the previous discussion "Creating an array with rotation". However, I meet a problem of "undefined method 'cell_index' for nil:NilClass". Could you help me to check where is my problem?
Belowing is my code:
module MyMacro
include RBA
#view = Application::instance.main_window.current_view
view = RBA::LayoutView::current
ly = RBA::CellView::active.layout
cell = RBA::CellView::active.cell
## cell array
cell_to_place = "TOP"
radius = 100 # radius in µm
num = 32 # number of cells
center = RBA::DVector::new(0, 0) # circle center in µm
# view = RBA::LayoutView::current
#begin
# Undo/redo support
# view.transaction("Create ring of cells")
# ly = RBA::CellView::active.layout
# cell = RBA::CellView::active.cell
# cp = ly.cell(cell_to_place)
cp = ly.cell("TOP")
puts cell.class
# cp || raise("Not a valid cell name: " + cell_to_place)
# cp_index = cp.cell_index
# cp_index = ly.cell("TOP").cell_index
num.times do |i|
a = i.to_f * Math::PI * 2 / num.to_f
a_degree = i.to_f * 360.0 / num.to_f
pos = RBA::DVector::new(radius * Math::sin(a), radius * Math::cos(a)) + center
trans = RBA::DCplxTrans::new(1.0, -a_degree, false, pos)
inst = RBA::DCellInstArray::new(ly.cell("TOP").cell_index, trans)
cell.insert(inst)
end
#ensure
# view.commit
#end
outFile = "C:/Users/Desktop/api_layout.gds"
layout.write(outFile)
end
Thanks a lot!
Candy
Comments
Hi,
Looks like "TOP" isn't a valid cell name.
In this case
ly.cell("TOP")
will return nil. Hence the error.Matthias
Dear Matthias,
Thanks a lot for the comments. The problem is solved.
I found that, to define a cell, there should not be space on both sides of "=". For example:
rather than
Thanks,
Candy
No, that can't make a difference. There is no such magic built into Ruby.
It's the presence of a cell called TOP, believe me.
Matthias