Executing a Text File

edited April 2013 in Ruby Scripting
Hello Matthias,

My question is what is the proper way to configure the "read" function in KLayout so that I can read in a text file and translate it into a form that KLayout can understand and execute.

For example:

include RBA

def self.rectangle_builder(leftx,bottomy,rightx,topy,cell,layer)



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

main_cell_index = layout.add_cell("Cell")
main_cell = layout.cell(main_cell_index)

layer = layout.insert_layer(RBA::LayerInfo::new(151,35))


layout_view.select_cell(main_cell_index, 0)

How do I read in a text file through KLayout that has all of the code from the "layout.dbu = 0.001" line down and execute this translated text file with a "read("call_method.txt")" type function?

Thank you for your time.


  • edited November -1

    Hi Jared,

    do you mean "load"?

    Ruby can execute a file in a specific place simply by writing


    A more "Ruby" way is to create an object as the context for a script and use instance_eval on that object to execute the code in the context of that object.

    I guess your question is about something that's called a "domain specific language". Building DSL's is a particular strength of Ruby. There are some nice articles about that topic, i.e http://jroller.com/rolsen/entry/building_a_dsl_in_ruby. This particular article is quite generic and I adopted that idea for the layer processing framework. If you plan something in that direction, considering these thoughts might be a good idea.



Sign In or Register to comment.