Insert the text on batch mode

edited February 2013 in General
Hi, Matthias,

The function of text dump to file is a convenient tool
If it is possible to insert the text on batch mode with klayout?

For example, user prepares text file of the texts and corresponding coordinates as following,
#contents,x,y
A,0.00,0.00
A,5.00,10.00
A,4603,4135
A,4603,4137
A,4603,4139
A,4603,4142

Then use the batch command insert these texts into the layout file

Regards,
Canny

Comments

  • edited November -1

    Hi Canny,

    that is basically easy. Here's the script core:

    # The layer where to put the texts to
    layer = RBA::LayerInfo::new(1, 0)
    
    # The file where to take the texts from
    input_file = "texts.txt"
    
    lv = RBA::Application.instance.main_window.current_view
    lv || raise("No view open")
    ly = lv.active_cellview.layout
    cell = lv.active_cellview.cell
    
    layer_index = ly.layer_indices.find { |li| ly.get_info(li).is_equivalent?(layer) }
    layer_index || raise("Layer not found: #{layer.to_s}")
    
    File.open("texts.txt") do |file|
      file.each_line do |line|
        if line.sub(/#.*$/, "") =~ /^\s*(.*)\s*,\s*(.*)\s*,\s*(.*)\s*$/
          string = $1
          # assume the coordinates are micron units
          x = ($2.to_f / ly.dbu + 0.5).floor
          y = ($3.to_f / ly.dbu + 0.5).floor
          cell.shapes(layer_index).insert(RBA::Text::new(string, RBA::Trans::new(x, y)))
        end
      end
    end
    

    It's lacking user interface and you have to edit file name and target layer, but you can simply put it into a macro in the macro IDE and run it inside the editor.

    Best regards,

    Matthias

  • edited November -1
    Hi, Matthias,

    It works very well and save lots of effort to give texts on gds file.
    Thank you.

    Regards,
    Canny
Sign In or Register to comment.