Undefined method "cell_index" in doing Cell Array

edited June 2020 in KLayout Support

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


  # 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)  


#  view.commit

outFile = "C:/Users/Desktop/api_layout.gds"



Thanks a lot!



  • Hi,

    Looks like "TOP" isn't a valid cell name.

    In this case ly.cell("TOP") will return nil. Hence the error.


  • 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:

    puts cp.class
    ## The out put is "RBA::Cell"

    rather than

    cp = ly.cell("TOP")
    puts cp.class
    ## The out put is "RBA::Nil"


  • edited June 2020

    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.


Sign In or Register to comment.