Text sizing, rotating and aligning with Ruby


I want to adjust all text size, rotation and alignment with a Ruby script.

The documentation indicates that size= , halign= , valign= should set the size and alignment of a text, so my script is :

include RBA

app = RBA::Application.instance
mw = app.main_window
view = mw.current_view
cv = view.cellview(view.active_cellview_index)
ly = view.active_cellview.layout
cl = view.active_cellview.cell
dbu = ly.dbu

layer_info = LayerInfo.new(127,0)
layer_index = ly.layer(layer_info)

cl.each_shape(layer_index) do |shape|
    if shape.is_text?
        text = shape.text
        text.size= 100*dbu
        text.halign= 1
        text.valign= 1
        text.trans= RBA::Trans::R90
        print( text.string,",")


But it does not set the size, alignment nor the rotation of the texts of the cell, although they are properly listed with the print command.

Please, can you tell me where is my mistake ?

Thank you, Best regards,



  • I wonder whether this has to do with the Default font not
    being scalable, while the ones in the list are. Can you change
    the font property to (say) "Stick" and see if that helps?

    I note that the font is not an accessible Property, has to be
    set in File>Setup>Display>Texts and this affects all texts
    regardless of when they were placed.

  • Thanks .. this was my question too :)

    Font is actually not used so far - it's just a property that needs to be preserved because some tools want it. So if you read and write GDS, the font is transferred to the output, but not further used by KLayout.

    IMHO there is no global definition what font ID maps to which kind of font. GDS seems to have the option to include a font table, but I have no sample for such a case. So I did not try to map it. And frankly, no one has asked so far for font representation. And once you use OASIS or other formats, fonts play no or a different role anyway.

    Best regards,


  • I finally used search and replace. It works like a charm for the size :

        with texts from instances of nd288.. where shape.text_string ~ "D<*>" do shape.text_size =  1 um

    But is does not work for the rotation :

        with texts from instances of nd288.. where shape.text_string ~ "D<*>" do shape.text_rot = Trans.R90


  • I still have the problem to automatically rotate text shapes (the pins at the top or bottom of mycells).
    Any tricks to rotate many text shape ?


  • Hi Laurent,

    sorry for getting back so late.

    "Trans.R90" does not work for some reason (that would actually be intuitive). But this works:

    with texts from cells * where shape.text_string ~ "D<*>" do shape.text_rot = 1

    Here, 1 is 90°. The values are: 0 = 0°, 1 = 90°, 2 = 180°, 3 = 270°, 4 = M0, 5 = M45, 6 = M90, 7 = M135.

    Please note that I also change from "instances of ..." to "*" which means "every cell" (= in "all cells" on the "Replace" page). By saying "instances", the search & replace visits every cell as many times as it's instantiated and this does not make a difference in this case. Only that a cell is potentially visited multiple times.

    Best regards,


Sign In or Register to comment.