Useful Ruby Modules

This is a collection of hopefully useful ruby modules. These scripts may also serve as a starting point for custom developments. All scripts are installed by one of the following ways:

For .rbm scripts:

  • By copying the file to the installation path of KLayout. The installatio path is the folder where the klayout.exe or klayout binary is located. This usually is "C:/Program Files/KLayout" on Windows or some path like "/usr/bin/klayout" on Linux. This is the way to globally install a macro.
  • Or: by copying the file to an arbitrary folder and setting $KLAYOUT_PATH to it's path.
  • Or: call KLayout with the "-rm" option and directly pass the path of the script to that option:
    klayout -rm script.rbm ...

For .lym macros:

  • By copying the files into the local macro installation folder. For the location of the folder open the macro development environment (Tools/Macro Development) and point with the mouse over the "Local" folder.

    The "Import" function from the macro tree's context menu will do exactly that if you select the "Local" branch and choose "Import" from the context menu (right mouse click).

    On Linux, the local macro installation folder is "~/.klayout/macros", on Windows it often is "%HOME%\KLayout\macros". This is the preferred way to install macros for the current user only.
  • Or: By copying the file to the "macros" folder in installation path of KLayout. If this folder does not exist yet, create it. The installatio path is the folder where the klayout.exe or klayout binary is located. This usually is "C:/Program Files/KLayout" on Windows or some path like "/usr/bin/klayout" on Linux. This is the way to globally install a macro.
  • Or: by copying the file to an arbitrary folder and setting $KLAYOUT_PATH to it's path.

These scripts are made available here:

Please also see XSection@KLayout on SourceForge for the cross section generator script. There in the code section you find the cross section script "xsection.rbm" in the "src" folder and a sample technology file called "cmos.xs" in the "samples" folder.

Anisotropic scaling

Download link: scale_anisotropic.lym

This script installs a new menu entry in the "Edit" menu in the "Selection" submenu called "Anisotropic Scaling" before the "Scale" entry. It asks for two scaling factors for x and y (separated by comma) and applies a different scaling in both directions on the selected shapes. This is a simple implementation which does not check for rounding issues (gaps) and does not support scaling of instances. Paths are converted to polygons because in the general case a constant width cannot be maintained.

Compute the total area of all selected shapes

Download link: calc_area.rbm

This script installs a new menu entry in the "Tools" menu called "Compute total area of selected shapes". It sums up the area of all shapes selected. Caution: this is a simple sum of areas. Areas where the shapes overlap are counted twice.

Compute the total area of all selected layers (hierarchical)

Download link: calc_area_hier.rbm

This script installs a new menu entry in the "Tools" menu called "Compute layer area". It computes the total area of all layers selected. Caution: this is a simple sum of shape areas, weighted with the cell's instant counts. Areas where the shapes overlap are counted twice.

A layer processing framework

Download link: layer_proc.rbm

This script installs a new menu entry in the "Tools" menu called "Processing Scripts". This menu entry asks for a processing script and executes it. Such a layer processing script contains commands to process layers such as sizing, boolean operations and similar. The exact syntax of the scripts is described in the header of the ruby module script.

The module also maintains a list of recently used processing scripts and presents them in the "Tools" menu under "Processing Scripts".

Import a Cadence techfile

Download link: import_tf.rbm

This script requires at least version 0.21.13.

This script installs a new menu entry in the "File" menu called "Import Cadence Techfile". It asks for the path of a Cadence techfile. It also requires a display resource file which it looks for in the folder where the techfile is located. If it finds multiple files with "drf" extension, it asks for a specific one. Also, if no stream layers are specified in the techfile, the script will try to find and load a layer mapping file ("layermap" extension).

The script will import the techfile and set the layer properties accordingly. These properties can then be saved using "Save Layer Properties" from the "File" menu.

Note: the script is able to parse simple forms of techfiles but will not execute embedded Skill code correctly. The best way is to dump a Cadence ASCII techfile and import that file.

Import a LEF file

Download link: LEF.rbm

This script installs a new menu entry in the "File" menu called "Open LEF". It asks for the path of a LEF file and imports it into a new layout.

Note: starting with version 0.22, KLayout features LEF/DEF import functionality and the script is obsolete. It is still provided however as an example.

A simple technology manager

Download link: tech_manager.rbm

This script installs a new menu "Technology". It allows to summarize some configuration settings and associate them with a technology. If a technology is selected, it will switch the following configuration settings:

  • Grids (Current grid plus default grids)
  • Default layer properties (From the "Layer Properties" page in the setup dialog. This will not the currently loaded ones, but rather switch the ones applied on the next load of a layout)
  • Database unit (For new layouts)
  • Net tracer setup (Layer stack)

To set up a new technology, select the respective settings in the setup dialog, close this dialog and choose "Save" from the "Technologies" menu. To remove a setup, choose "Remove". To apply a setup, choose the respective entry. Please note, that the effect of a setting, specifically the default layer properties will be on the next load of a layout, not on the currently loaded one.

Hint: the settings are stored in the file "$HOME/.klayout_tech_info.txt".

Note: starting with version 0.22, KLayout features build-in technology management functionality and the script is obsolete. It is still provided however as an example.

Search for odd-width paths

Download link: search_odd_width_paths.rbm

This script installs a menu entry in the "Tools" menu called "Find Paths With Odd Width". It will find all paths with an odd width in database units in the current layout and report them. Such paths cannot be saved to OASIS, hence it's important to remove them before a layout can be written to OASIS.

Replace cells with others from another file

Download link: replace_cells.rbm

The script installs a new menu entry at the end of the cell list context menu: "Replace Cells With Others". This function asks for a file containing a couple of other (top) cells, even with their own hierarchy. It will copy these cells into the existing layout and replace the corresponding cells in the current layout with the ones from the replacement library.

Hint: the script requires the database unit of the replacement and original file to be identical.

Write all child cells of the current cell to new files

Download link: write_childcells.rbm

The script installs a new menu entry at the end of the cell list context menu: "Write Child Cells". This function asks for the hierarchy level and writes all cells at this level (below the current cell) to files called "{cellname}.gds".

Dump all shapes of the current cell recursively to a XML file

Download link: dump_flat_shapes.rbm

This script installs a menu entry in the "Tools" menu called "Dump Flat Shapes". It asks for a file name and writes a flat dump of the current cell to this file. This dump contains all shapes of the cell and their chip cells projected into the top cell.

The format of the dump file is XML with that layout:

<shape_dump cell="{cell name}" dbu="{database unit}">
  <layer source="{layer}">
    .. shapes on that layer using these XML elements: ..
    <box>{box description}</box>
    <path>{path description}</path>
    <polygon>{polygon description}</polygon>
    <text>{text description}</text>
    .. more shapes ..
  </layer>
  .. more layers ..
</shape_dump>

List all layers under a ruler

Download link: list_layers.rbm

This script will install a new entry in the "Tools" menu called "List Layers". Before this function can be used, a single ruler must be drawn. The script looks for shapes that are crossed by this ruler and reports the layers of those shapes. The script can operate on multiple layouts as well.

Rename all cells

Download link: rename_cells.rbm

This script will install a new entry in the "Tools" menu called "Rename Cells". It will ask for a rename expression and rename all cells of the current layout. In the expression, "*" is a placeholder for the current cell name and "#" a placeholder for the cell index. Hence it is possible for example to add an "A" prefix by using an expression of "A*". Also it's possible to remove all traces of macro names by using "CELL#" as the expression.

Compute the bounding box of a cell

Download link: cell_bbox.rbm

This script will install a new entry in the "Tools" menu called "Cell Bounding Box". It will compute and output the bounding box over all layers of the current cell (the one that is shown in the layout view and which is in the active cell tree). The ouput will include the corner coordinates as well as width and height.

Take a screenshot with options

Download link: screenshot.lym

This macro will provide a screenshot function with a dialog to enter the pixel dimensions. This script will install a new entry in the "File" menu called "Screenshot With Options".