# DRC Reference: Global Functions

Some functions are available on global level and can be used without any object. Most of them are convenience functions that basically act on some default object or provide function-like alternatives for the methods.

## "box" - Creates a box object

Usage:

- box(...)

This function creates a box object. The arguments are the same than for the DBox constructors.

## "cell" - Selects a cell for input on the default source

Usage:

- cell(args)

See Source#cell for a description of that function. In addition to the functionality described there, the global function will also send the output to the specified cell.

The following code will select cell "MACRO" from the input layout:

    cell("MACRO")
    # shapes now will be taken from cell "MACRO"
    l1 = input(1, 0)

## "clip" - Specifies clipped input on the default source

Usage:

- clip(args)

See Source#clip for a description of that function.

The following code will select shapes within a 500x600 micron rectangle (lower left corner at 0,0) from the input layout. The shapes will be clipped to that rectangle:

    clip(0.mm, 0.mm, 0.5.mm, 0.6.mm)
    # shapes now will be taken from the given rectangle and clipped to it
    l1 = input(1, 0)

## "dbu" - Gets or sets the database unit to use

Usage:

- dbu(dbu)
- dbu

Without any argument, this method gets the database unit used inside the DRC engine.

With an argument, sets the database unit used internally in the DRC engine. Without using that method, the database unit is automatically taken as the database unit of the last input. A specific database unit can be set in order to optimize for two layouts (i.e. take the largest common denominator). When the database unit is set, it must be set at the beginning of the script and before any operation that uses it.

## "edge" - Creates an edge object

Usage:

- edge(...)

This function creates an edge object. The arguments are the same than for the DEdge constructors.

## "edge_layer" - Creates an empty edge layer

Usage:

- edge_layer

The intention of that method is to create an empty layer which can be filled with edge objects using Layer#insert.

## "error" - Prints an error

Usage:

- error(message)

Similar to log, but the message is printed formatted as an error

## "extent" - Creates a new layer with the bounding box of the default source

Usage:

- extent

See Source#extent for a description of that function.

## "flat" - Disables tiling mode

Usage:

- flat

Disables tiling mode. Tiling mode can be enabled again with tiles later.

## "info" - Outputs as message to the logger window

Usage:

- info(message)

Prints the message to the log window in verbose mode. In non-verbose more, nothing is printed. log is a function that always prints a message.

## "input" - Fetches the shapes from the specified input from the default source

Usage:

- input(args)

See Source#input for a description of that function.

## "is_tiled?" - Returns true, if in tiled mode

Usage:

- is_tiled?

## "labels" - Gets the labels (text) from an original layer

Usage:

- labels

See Source#labels for a description of that function.

## "layers" - Gets the layers contained in the default source

Usage:

- layers

See Source#layers for a description of that function.

## "layout" - Specifies an additional layout for the input source.

Usage:

- layout
- layout(what)

This function can be used to specify a new layout for input. It returns an Source object representing that layout. The "input" method of that object can be used to get input layers for that layout.

"what" specifies what input to use. "what" be either

- A string "@n" specifying input from a cellview in the current view
- A layout filename plus an optional cell name
- A Layout object
- A Cell object

Without any arguments the default layout is returned.

If a file name is given, a cell name can be specified as the second argument. If not, the top cell is taken which must be unique in that case.

Having specified a layout for input enables to use the input method for getting input:

    # XOR between layers 1 or the default input and "second_layout.gds":
    l2 = layout("second_layout.gds")
    (input(1, 0) ^ l2.input(1, 0)).output(100, 0)

For further methods on the source object see Source.

## "log" - Outputs as message to the logger window

Usage:

- log(message)

Prints the message to the log window. info is a function that prints a message only if verbose mode is enabled.

## "log_file" - Specify the log file where to send to log to

Usage:

- log_file(filename)

After using that method, the log output is sent to the given file instead of the logger window or the terminal.

## "no_borders" - Reset the tile borders

Usage:

- no_borders

Resets the tile borders - see tile_borders for a description of tile borders.

## "output" - Outputs a layer to the report database or output layout

Usage:

- output(layer, args)

This function is equivalent to "layer.output(args)". See Layer#output for details about this function.

## "output_cell" - Specifies a target cell, but does not change the target layout

Usage:

- output_cell(cellname)

This method switches output to the specified cell, but does not change the target layout nor does it switch the output channel to layout if is report database.

## "p" - Creates a point object

Usage:

- p(x, y)

A point is not a valid object by itself, but it is useful for creating paths for polygons:

    x = polygon_layer
    x.insert(polygon([ p(0, 0), p(16.0, 0), p(8.0, 8.0) ]))

## "path" - Creates a path object

Usage:

- path(...)

This function creates a path object. The arguments are the same than for the DPath constructors.

## "polygon" - Creates a polygon object

Usage:

- polygon(...)

This function creates a polygon object. The arguments are the same than for the DPolygon constructors.

## "polygon_layer" - Creates an empty polygon layer

Usage:

- polygon_layer

The intention of that method is to create an empty layer which can be filled with polygon-like objects using Layer#insert.

## "report" - Specifies a report database for output

Usage:

- report(description [, filename [, cellname ] ])

After specifying a report database for output, output method calls are redirected to the report database. The format of the output calls changes and a category name plus description can be specified rather than a layer/datatype number of layer name. See the description of the output method for details.

If a filename is given, the report database will be written to the specified file name. Otherwise it will be shown but not written.

If external input is specified with source, "report" must be called after "source".

The cellname specifies the top cell used for the report file. By default this is the cell name of the default source. If there is no source layout you'll need to give the cell name in the third parameter.

## "select" - Specifies cell filters on the default source

Usage:

- select(args)

See Source#select for a description of that function.

## "silent" - Resets verbose mode

Usage:

- silent

This function is equivalent to "verbose(false)" (see verbose)

## "source" - Specifies a source layout

Usage:

- source
- source(what)

This function replaces the default source layout by the specified file. If this function is not used, the currently active layout is used as input.

layout is a similar method which specifies a additional input layout.

"what" specifies what input to use. "what" be either

- A string "@n" specifying input from a layout in the current panel
- A layout filename plus an optional cell name
- A Layout object plus an optional cell name
- A Cell object

Without any arguments the default layout is returned. If a filename is given, a cell name can be specified as the second argument. If none is specified, the top cell is taken which must be unique in that case.

    # XOR between layers 1 of "first_layout.gds" and "second_layout.gds" and sends the results to "xor_layout.gds":
    target("xor_layout.gds")
    source("first_layout.gds")
    l2 = layout("second_layout.gds")
    (input(1, 0) ^ l2.input(1, 0)).output(100, 0)

For further methods on the source object see Source.

## "target" - Specify the target layout

Usage:

- target(what [, cellname])

This function can be used to specify a target layout for output. Subsequent calls of "output" will send their results to that target layout. Using "target" will disable output to a report database. If any target was specified before, that target will be closed and a new target will be set up.

"what" specifies what input to use. "what" be either

- A string "@n" specifying output to a layout in the current panel
- A layout filename
- A Layout object
- A Cell object

Except if the argument is a Cell object, a cellname can be specified stating the cell name under which the results are saved. If no cellname is specified, either the current cell or "TOP" is used.

## "threads" - Specifies the number of CPU cores to use in tiling mode

Usage:

- threads(n)

If using threads, tiles are distributed on multiple CPU cores for parallelization. Still, all tiles must be processed before the operation proceeds with the next statement.

## "tile_borders" - Specifies a minimum tile border

Usage:

- tile_border(b)
- tile_border(bx, by)

The tile border specifies the distance to which shapes are collected into the tile. In order words, when processing a tile, shapes within the border distance participate in the operations.

For some operations such as booleans (and, or, ...), size and the DRC functions (width, space, ...) a tile border is automatically established. For other operations such as with_area or edges, the exact distance is unknown, because such operations may have a long range. In that cases, no border is used. The tile_borders function may be used to specify a minimum border which is used in that case. That allows taking into account at least shapes within the given range, although not necessarily all.

To reset the tile borders, use no_borders or "tile_borders(nil)".

## "tiles" - Specifies tiling

Usage:

- tiles(t)
- tiles(w, h)

Specifies tiling mode. In tiling mode, the DRC operations are evaluated in tiles with width w and height h. With one argument, square tiles with width and height t are used.

Special care must be taken when using tiling mode, since some operations may not behave as expected at the borders of the tile. Tiles can be made overlapping by specifying a tile border dimension with tile_borders. Some operations like sizing, the DRC functions specify a tile border implicitly. Other operations without a defined range won't do so and the consequences of tiling mode can be difficult to predict.

In tiling mode, the memory requirements are usually smaller (depending on the choice of the tile size) and multi-CPU support is enabled (see threads). To disable tiling mode use flat.

## "verbose" - Sets or resets verbose mode

Usage:

- verbose
- verbose(m)

In verbose mode, more output is generated in the log file

## "verbose?" - Returns true, if verbose mode is enabled

Usage:

- verbose?

In verbose mode, more output is generated in the log file