Creating a shape then make array of it

edited December 2013 in Ruby Scripting
Hi
i am trying to combine these 2 topics.
Is it possible to place many instances of a cell to a text list of x,y coordinates?
http://klayout.de/forum/comments.php?DiscussionID=370
and
Array selected objects
http://klayout.de/forum/comments.php?DiscussionID=321&page=1#Item_0

The codes I found here is

A.
# create a new view (mode 1) with an empty layout
main_window = RBA::Application::instance.main_window
layout = main_window.create_layout(1).layout
layout_view = main_window.current_view

# set the database unit (shown as an example, the default is 0.001)
layout.dbu = 0.001

# add a cell (in this case "TOP")
cell_index = layout.add_cell("TOP")
cell = layout.cell(cell_index)

# create a layer (in this sample layer 10, datatype 0)
layer_index = layout.insert_layer(RBA::LayerInfo::new(10, 0))

# add shapes now
# TODO: read the text file and create one shape on each location read
# (in this sample a single box with lower left corner being a 0,0 and
# width of 1um and height of 2um is created)
cell.shapes(layer_index).insert(RBA::Box::new(0, 0, 1000, 2000))

# select the top cell in the view, set up the view's layer list and
# fit the viewport to the extensions of our layout
layout_view.select_cell(cell_index, 0)
layout_view.add_missing_layers
layout_view.zoom_fit

B.
ly = ... # the layout
unitcell_index = ... # cell index of the unitcell

arraycell_index = ly.add_cell("ARRAY")
arraycell = ly.cell(arraycell_index)

nx = ... # number of columns
dx = ... # column pitch
ny = ... # number of rows
dy = ... # row pitch
arraycell.insert(RBA::CellInstArray::new(unitcell_index, RBA::Trans::new,
RBA::Point::new(dx, 0), RBA::Point::new(0, dy), nx, ny)



I am having trouble to combine these 2 codes and hoping to find some solution here.
The goal is to create shape then make array of it, then create another shape then array that one again...so on.



thanks

Comments

  • edited November -1

    Hello,

    Could you please be more specific? What's your input and what is the expected output?

    Both pieces of code refer to a specific problem, and I don't think they easily combine to solve yours.

    If you need more information about writing scripts and the database API in general, please try http://www.klayout.de/doc/programming/index.html. You should also be familiar with Ruby. There are numerous tutorials out there, so it should be easy to find one that suits you.

    Thanks,

    Matthias

  • edited November -1
    Hi Matthias
    Thanks for the reply.
    My goal is to use script to draw a 1um by 1um box then make it a array of 100 row and column with pitch of 2um, then continue to draw a 3um by 2um box then make it a array of 50 row and column with pitch of 5um
    That's why I started to search from forum to see if there is any code I can combine to make it happen.
    Code A from above, can help me to draw 1um by 1um box and 3um by 2um box, but somehow I can't use Code B from above, to "make array" the 2 boxes that I created previously with different pitch and numbers of column/rows.


    thanks.
  • edited December 2013

    Hi,

    the code above illustrates how to create a shape and how to instantiate a cell so it becomes a cell array. This is one way to create an array. The two codes above combine like this:

    # create a new view (mode 1) with an empty layout
    main_window = RBA::Application::instance.main_window
    layout = main_window.create_layout(1).layout
    layout_view = main_window.current_view
    
    # set the database unit (shown as an example, the default is 0.001)
    layout.dbu = 0.001
    
    # create a layer (in this sample layer 10, datatype 0)
    layer_index = layout.insert_layer(RBA::LayerInfo::new(10, 0))
    
    # add a cell (in this case "TOP")
    cell_index = layout.add_cell("TOP")
    cell = layout.cell(cell_index)
    
    # add a unit cell (in this case "UNIT")
    unit_cell_index = layout.add_cell("UNIT")
    unit_cell = layout.cell(unit_cell_index)
    
    # add shapes now into the *unit* cell
    # (this sample produces a 1x1 micron box at a database unit of 1nm)
    unit_cell.shapes(layer_index).insert(RBA::Box::new(0, 0, 1000, 1000))
    
    # create an array instance of the unit cell
    nx = 100  # number of columns
    dx = 2000 # column pitch (= 2 micron at 1nm database unit)
    ny = 100  # number of rows
    dy = 2000 # row pitch (= 2 micron at 1nm database unit)
    ox = 0    # x origin of the array
    oy = 0    # y origin of the array
    trans = RBA::Trans::new(RBA::Point::new(ox, oy))
    ax = RBA::Point::new(dx, 0)
    ay = RBA::Point::new(0, dy)
    cell.insert(RBA::CellInstArray::new(unit_cell_index, trans, ax, ay, nx, ny))
    
    # select the top cell in the view, set up the view's layer list and
    # fit the viewport to the extensions of our layout
    layout_view.select_cell(cell_index, 0)
    layout_view.add_missing_layers
    layout_view.zoom_fit
    

    You'll need to add the code to repeat the steps from creating the unit cell to creating the array instance. Don't forget to adjust the origin on each step.

    Another way to create an array is by iterating the coordinates inside your script and producing 100x100 rectangles directly, This will produce somewhat bigger files and is somewhat slower but is also a valid approach.

    Matthias

Sign In or Register to comment.