Macro rendering in main window

edited October 2015 in General
I'm a beginner of KLayout and would like to start some post-processing some GDS files.

Would it be possible to render in the mainwindow all cells, layers and polygons creation using a macro?

Using this code I can create a layer, a cell, but the layer and the box are not showing up, though they get created when opening the saved gds file.

module MyMacro

include RBA

mw = RBA::Application::instance.main_window
ly = mw.create_layout(0).layout
layout_view=mw.current_view

dbu = 1.0/ly.dbu
puts "Database Unit:" + dbu.to_s

tc = ly.create_cell("TOP")

#modify layer index
li = ly.insert_layer(RBA::LayerInfo::new(1,0))

#adding a box
tc.shapes(li).insert(RBA::Box::new(0, 0, 1000, 1000))

layout_view.zoom_fit
ly.write("c:/Users/mb_000/Klayout/1.gds")
end


Why don't the layer and the polygon show on the main window output?

M.

Comments

  • edited November -1

    Add this near the end:

    layout_view.add_missing_layers
    

    This is equivalent to right-clicking on the layer list and choosing "Add other layer entries" (try it, with your current script).

    Why do you need to do this? The layers list does not (indeed, cannot as far as I know) update when you add or remove or modify layers programmatically. See Matthias's explanation here, scroll to the last post.

    But there is a second problem: "TOP" is not showing as the top cell. For a short-term workaround, run your script and then center-click on the "TOP" cell in the cell list on the left of the main window. Or, equivalently, right click and "Show as new top". Now you can see your cell also.

    I searched but couldn't find a way to do that "show as new top" function programmatically. Probably Matthias has a way..

    David

  • edited October 2015

    Also check out E4K, which, funnily enough, has an example to draw a box on a new layer.

    Feel free to contribute your own example scripts to E4K as you learn scripting -- E4K is a bit sparse right now... I just haven't had the time to add a huge number of examples to it.

  • edited November -1

    Hi David,

    thanks at lot again for your support!

    Best regards,

    Matthias

Sign In or Register to comment.