I would like to know how to search for and then copy a specified cell within an open GDS file to a different blank layout using Ruby. I hope this question is not too vague.
there is no one-line copy method for KLayout yet. One user found, that you can use the clip method for that purpose, if you specify a clip box larger than the cell's bounding box. A single-line copy method is on my TODO list yet.
In general case, copying layout from one layout to another involves layer and property mapping.
new_top = ly.add_cell("ROTATED") # "new_top" is newly created cell's name or its "cell index"
ly.cell(new_top).insert(RBA::CellInstArray::new(cell_index,RBA::CplxTrans::new(1,0,false,RBA::DPoint::new(0,0))))
# 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(new_top, 0)
layout_view.add_missing_layers
layout_view.zoom_fit
end
Inside the script you basically create two layouts: one per "new" and another with "mw.create_layout". The second is empty and "new_top" is only valid in the context of the first one. I guess that is why the program crashes (it shouldn't I admit - but I did no handle every case of invalid values).
This code should be more like what you want to:
mw = RBA::Application::instance.main_window
# This already creates a layout!
ly = mw.create_layout(0).layout
layout_view = mw.current_view
ly.read("LABELS.gds")
# NOTE: this should check if the cell is really there ...
cell_index = ly.cell_by_name("LABEL_A")
new_top = ly.add_cell("ROTATED")
ly.cell(new_top).insert(RBA::CellInstArray::new(cell_index,RBA::CplxTrans::new(1,0,false,RBA::DPoint::new(0,0))))
ly.flatten(new_top, -1, true)
# 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(new_top, 0)
layout_view.add_missing_layers
layout_view.zoom_fit
(lacking "LABELS.gds" I have not tested it myself)
This should be a very simple question. How do I get the index number for a string?
For example, if a = "ABC" what function can I perform on the variable a in order to determine the number of individual string characters which in this case is three.
Comments
Hi Jared,
there is no one-line copy method for KLayout yet. One user found, that you can use the clip method for that purpose, if you specify a clip box larger than the cell's bounding box. A single-line copy method is on my TODO list yet.
In general case, copying layout from one layout to another involves layer and property mapping.
There has been a discussion about that topic some time ago: http://klayout.de/forum/comments.php?DiscussionID=103
Maybe that is helpful.
Regards,
Matthias
Can you tell me why this script keeps crashing KLayout?
module MyMacro
include RBA
mw = RBA::Application::instance.main_window
ly = RBA::Layout::new
ly.read("LABELS.gds")
cell_index = ly.cell_by_name("LABEL_A")
new_top = ly.add_cell("ROTATED") # "new_top" is newly created cell's name or its "cell index"
ly.cell(new_top).insert(RBA::CellInstArray::new(cell_index,RBA::CplxTrans::new(1,0,false,RBA::DPoint::new(0,0))))
ly.flatten(new_top, -1, true)
layout = mw.create_layout(0).layout
layout_view = mw.current_view
cell = layout.cell(new_top)
# 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(new_top, 0)
layout_view.add_missing_layers
layout_view.zoom_fit
end
Hi Jared,
Inside the script you basically create two layouts: one per "new" and another with "mw.create_layout". The second is empty and "new_top" is only valid in the context of the first one. I guess that is why the program crashes (it shouldn't I admit - but I did no handle every case of invalid values).
This code should be more like what you want to:
(lacking "LABELS.gds" I have not tested it myself)
Regards,
Matthias
For example, if a = "ABC" what function can I perform on the variable a in order to determine the number of individual string characters which in this case is three.
Hi Jared,
Do you mean the length of the string?
That is
Or do you mean the number of distinct characters?
That is
Matthias